am: preliminary support for hg patches

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Giuseppe Bilotta committed Aug 29, 2011 at 18:44 UTC 0cfd112032017ab68ed576f6bb5258452084ebf1
1 file changed +34
git-am.sh
+34
@@ -248,6 +248,40 @@ split_patches () {
248 this=
249 msgnum=
250 ;;
251 + hg)
252 + this=0
253 + for hg in "$@"
254 + do
255 + this=$(( $this + 1 ))
256 + msgnum=$(printf "%0${prec}d" $this)
257 + # hg stores changeset metadata in #-commented lines preceding
258 + # the commit message and diff(s). The only metadata we care about
259 + # are the User and Date (Node ID and Parent are hashes which are
260 + # only relevant to the hg repository and thus not useful to us)
261 + # Since we cannot guarantee that the commit message is in
262 + # git-friendly format, we put no Subject: line and just consume
263 + # all of the message as the body
264 + perl -M'POSIX qw(strftime)' -ne 'BEGIN { $subject = 0 }
265 + if ($subject) { print ; }
266 + elsif (/^\# User /) { s/\# User/From:/ ; print ; }
267 + elsif (/^\# Date /) {
268 + my ($hashsign, $str, $time, $tz) = split ;
269 + $tz = sprintf "%+05d", (0-$tz)/36;
270 + print "Date: " .
271 + strftime("%a, %d %b %Y %H:%M:%S ",
272 + localtime($time))
273 + . "$tz\n";
274 + } elsif (/^\# /) { next ; }
275 + else {
276 + print "\n", $_ ;
277 + $subject = 1;
278 + }
279 + ' <"$hg" >"$dotest/$msgnum" || clean_abort
280 + done
281 + echo "$this" >"$dotest/last"
282 + this=
283 + msgnum=
284 + ;;
285 *)
286 echo "Patch format $patch_format is not supported."
287 exit 1