summaryrefslogtreecommitdiff
path: root/git-am.sh
diff options
context:
space:
mode:
authorPaul Tan <pyokagan@gmail.com>2015-06-15 11:08:12 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-06-15 19:34:11 (GMT)
commite9dfe253fd489ea171e0478147aeb6eab91dab75 (patch)
tree2cd95b4285c0e1058f1dbe6ed9d8416b0ac41be2 /git-am.sh
parentfcceef4e06f30ea6dc30bd8fe16142472447cb94 (diff)
downloadgit-e9dfe253fd489ea171e0478147aeb6eab91dab75.zip
git-e9dfe253fd489ea171e0478147aeb6eab91dab75.tar.gz
git-e9dfe253fd489ea171e0478147aeb6eab91dab75.tar.bz2
am: use gmtime() to parse mercurial patch date
An example of the line in a mercurial patch that specifies the date of the commit would be: # Date 1433753301 25200 where the first number is the number of seconds since the unix epoch (in UTC), and the second number is the offset of the timezone, in second s west of UTC (negative if the timezone is east of UTC). git-am uses localtime() to break down the first number into its components (year, month, day, hours, minutes, seconds etc.). However, the returned components are relative to the user's time zone. As a result, if the user's time zone does not match the time zone specified in the patch, the resulting commit will have the wrong author date. Fix this by using gmtime() instead, which uses UTC instead of the user's time zone. Signed-off-by: Paul Tan <pyokagan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-am.sh')
-rwxr-xr-xgit-am.sh6
1 files changed, 3 insertions, 3 deletions
diff --git a/git-am.sh b/git-am.sh
index 1f4c09e..5eec11d 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -343,11 +343,11 @@ split_patches () {
elsif (/^\# User /) { s/\# User/From:/ ; print ; }
elsif (/^\# Date /) {
my ($hashsign, $str, $time, $tz) = split ;
- $tz = sprintf "%+05d", (0-$tz)/36;
+ $tz_str = sprintf "%+05d", (0-$tz)/36;
print "Date: " .
strftime("%a, %d %b %Y %H:%M:%S ",
- localtime($time))
- . "$tz\n";
+ gmtime($time-$tz))
+ . "$tz_str\n";
} elsif (/^\# /) { next ; }
else {
print "\n", $_ ;