Skip to content

Commit 0cfd112

Browse files
Oblomovgitster
authored andcommitted
am: preliminary support for hg patches
Signed-off-by: Giuseppe Bilotta <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c574e68 commit 0cfd112

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

git-am.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,40 @@ split_patches () {
248248
this=
249249
msgnum=
250250
;;
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+
;;
251285
*)
252286
echo "Patch format $patch_format is not supported."
253287
exit 1

0 commit comments

Comments
 (0)