Merge branch 'gb/am-hg-patch'
authorJunio C Hamano <gitster@pobox.com>
Wed, 5 Oct 2011 19:36:17 +0000 (12:36 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 5 Oct 2011 19:36:17 +0000 (12:36 -0700)
* gb/am-hg-patch:
  am: preliminary support for hg patches

1  2 
git-am.sh

diff --cc git-am.sh
index 016b5056eb29fb24d06667c340ad372ed096d4dc,eaa8a11450d1efe6f49db11661b5ab30f1fe988f..9042432e23d7e43edafce28b6822a041028b57b7
+++ b/git-am.sh
@@@ -311,13 -248,43 +311,47 @@@ split_patches () 
                this=
                msgnum=
                ;;
+       hg)
+               this=0
+               for hg in "$@"
+               do
+                       this=$(( $this + 1 ))
+                       msgnum=$(printf "%0${prec}d" $this)
+                       # hg stores changeset metadata in #-commented lines preceding
+                       # the commit message and diff(s). The only metadata we care about
+                       # are the User and Date (Node ID and Parent are hashes which are
+                       # only relevant to the hg repository and thus not useful to us)
+                       # Since we cannot guarantee that the commit message is in
+                       # git-friendly format, we put no Subject: line and just consume
+                       # all of the message as the body
+                       perl -M'POSIX qw(strftime)' -ne 'BEGIN { $subject = 0 }
+                               if ($subject) { print ; }
+                               elsif (/^\# User /) { s/\# User/From:/ ; print ; }
+                               elsif (/^\# Date /) {
+                                       my ($hashsign, $str, $time, $tz) = split ;
+                                       $tz = sprintf "%+05d", (0-$tz)/36;
+                                       print "Date: " .
+                                             strftime("%a, %d %b %Y %H:%M:%S ",
+                                                      localtime($time))
+                                             . "$tz\n";
+                               } elsif (/^\# /) { next ; }
+                               else {
+                                       print "\n", $_ ;
+                                       $subject = 1;
+                               }
+                       ' <"$hg" >"$dotest/$msgnum" || clean_abort
+               done
+               echo "$this" >"$dotest/last"
+               this=
+               msgnum=
+               ;;
        *)
 -              echo "Patch format $patch_format is not supported."
 -              exit 1
 +              if test -n "$patch_format"
 +              then
 +                      clean_abort "$(eval_gettext "Patch format \$patch_format is not supported.")"
 +              else
 +                      clean_abort "$(gettext "Patch format detection failed.")"
 +              fi
                ;;
        esac
  }