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 <pjo...@redhat.com>
---
 git-am.sh | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/git-am.sh b/git-am.sh
index c682d34..210e9fe 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,51 @@ split_patches () {
                this=
                msgnum=
                ;;
+       gitshow)
+               this=0
+               for patch 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 {
+                                       $diff = 0; $subject = 0; $subjtext="";
+                               }
+                               if ($diff == 1 || /^diff/ || /^---$/) {
+                                       $diff = 1 ;
+                                       print ;
+                               } elsif ($subject > 1) {
+                                       s/^    // ;
+                                       print ;
+                               } elsif ($subject == 1 && !/^\s+$/) {
+                                       s/^    // ;
+                                       $subjtext = "$subjtext $_";
+                               } elsif ($subject == 1) {
+                                       $subject = 2 ;
+                                       print "Subject: ", $subjtext ;
+                                       s/^    // ;
+                                       print ;
+                               } elsif ($subject) {
+                                       print "\n" ;
+                                       s/^    // ;
+                                       print ;
+                               } elsif (/^\s+$/) { next ; }
+                               elsif (/^Author:/) { s/Author/From/ ; print ;}
+                               elsif (/^(From|Date)/) { print ; }
+                               elsif (/^commit/) { next ; }
+                               else {
+                                       s/^    // ;
+                                       $subjtext = $_;
+                                       $subject = 1;
+                               }
+                       ' < "$patch" > "$dotest/$msgnum" || clean_abort
+               done
+               echo "$this" > "$dotest/last"
+               this=
+               msgnum=
+               ;;
        hg)
                this=0
                for hg in "$@"
-- 
1.7.11.4

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to