Re: [PATCH] Handle "git show" output correctly.

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] Handle "git show" output correctly.

From: Matthieu Moy <hidden>
Date: 2016-06-15 22:54:43

Peter Jones [off-list ref] writes:
(this version with fixed tabs)
This will end up being the commit message. If you add text here, then
the maintainer will have to manually fix it when applying (or reject
your patch). Please, be nice with him and put your comments below the
--- :
Signed-off-by: Peter Jones <pjones@redhat.com>
---
(ie. here)
 git-am.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

[PATCH] [git-am] Handle "git show" output correctly

From: Peter Jones <pjones@redhat.com>
Date: 2016-06-15 22:54:44

This patch adds the ability for "git am" to accept patches in the format
generated by "git show".  Some people erroneously use "git show" instead
of "git format-patch", and it's nice as a maintainer to be able to
easily take their patch rather than going back and forth with them to
get a "correctly" formatted patch containing exactly the same actual
information.

Signed-off-by: Peter Jones <pjones@redhat.com>
---
 git-am.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
diff --git a/git-am.sh b/git-am.sh
index c682d34..cfd7b09 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -216,6 +216,21 @@ check_patch_format () {
 		read l2
 		read l3
 		case "$l1" in
+		"commit "*)
+			case "$l2" in
+			"Author: "*)
+				case "$l3" in
+				"Date: "*)
+					patch_format=gitshow
+					;;
+				*)
+					;;
+				esac
+				;;
+			*)
+				;;
+			esac
+			;;
 		"From "* | "From: "*)
 			patch_format=mbox
 			;;
@@ -321,6 +336,36 @@ split_patches () {
 		this=
 		msgnum=
 		;;
+	gitshow)
+		this=0
+		for stgit in "$@"
+		do
+			this=`expr "$this" + 1`
+			msgnum=`printf "%0${prec}d" $this`
+			# The first nonemptyline after an empty line is the
+			# subject, and the body starts with the next nonempty
+			# line.
+			perl -ne 'BEGIN { $subject = 0 }
+				if ($subject > 1) { print ; }
+				elsif (/^\s+$/) { next ; }
+				elsif (/^Author:/) { s/Author/From/ ; print ;}
+				elsif (/^(From|Date)/) { print ; }
+				elsif (/^commit/) { next ; }
+				elsif ($subject) {
+					$subject = 2 ;
+					print "\n" ;
+					s/^    // ;
+					print ;
+				} else {
+					print "Subject: ", $_ ;
+					$subject = 1;
+				}
+			' < "$stgit" > "$dotest/$msgnum" || clean_abort
+		done
+		echo "$this" > "$dotest/last"
+		this=
+		msgnum=
+		;;
 	hg)
 		this=0
 		for hg in "$@"
-- 
1.7.11.4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help