Skip to content

Commit a1980c4

Browse files
anderskgitster
authored andcommitted
apply: Recognize epoch timestamps with : in the timezone
Some patches have a timezone formatted like ‘-08:00’ instead of ‘-0800’ (e.g. http://lwn.net/Articles/131729/), so git apply would fail to recognize the epoch timestamp of deleted files and would create empty files instead. Teach it to support both formats, and add a test case. Signed-off-by: Anders Kaseorg <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 87b5054 commit a1980c4

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

builtin/apply.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -733,8 +733,8 @@ static int has_epoch_timestamp(const char *nameline)
733733
" "
734734
"[0-2][0-9]:[0-5][0-9]:00(\\.0+)?"
735735
" "
736-
"([-+][0-2][0-9][0-5][0-9])\n";
737-
const char *timestamp = NULL, *cp;
736+
"([-+][0-2][0-9]:?[0-5][0-9])\n";
737+
const char *timestamp = NULL, *cp, *colon;
738738
static regex_t *stamp;
739739
regmatch_t m[10];
740740
int zoneoffset;
@@ -764,8 +764,11 @@ static int has_epoch_timestamp(const char *nameline)
764764
return 0;
765765
}
766766

767-
zoneoffset = strtol(timestamp + m[3].rm_so + 1, NULL, 10);
768-
zoneoffset = (zoneoffset / 100) * 60 + (zoneoffset % 100);
767+
zoneoffset = strtol(timestamp + m[3].rm_so + 1, (char **) &colon, 10);
768+
if (*colon == ':')
769+
zoneoffset = zoneoffset * 60 + strtol(colon + 1, NULL, 10);
770+
else
771+
zoneoffset = (zoneoffset / 100) * 60 + (zoneoffset % 100);
769772
if (timestamp[m[3].rm_so] == '-')
770773
zoneoffset = -zoneoffset;
771774

t/t4132-apply-removal.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ test_expect_success setup '
3030
epocWest="1969-12-31 16:00:00.000000000 -0800" &&
3131
epocGMT="1970-01-01 00:00:00.000000000 +0000" &&
3232
epocEast="1970-01-01 09:00:00.000000000 +0900" &&
33+
epocWest2="1969-12-31 16:00:00 -08:00" &&
3334
3435
sed -e "s/TS0/$epocWest/" -e "s/TS1/$timeWest/" <c >createWest.patch &&
3536
sed -e "s/TS0/$epocEast/" -e "s/TS1/$timeEast/" <c >createEast.patch &&
@@ -46,6 +47,7 @@ test_expect_success setup '
4647
sed -e "s/TS0/$timeWest/" -e "s/TS1/$epocWest/" <d >removeWest.patch &&
4748
sed -e "s/TS0/$timeEast/" -e "s/TS1/$epocEast/" <d >removeEast.patch &&
4849
sed -e "s/TS0/$timeGMT/" -e "s/TS1/$epocGMT/" <d >removeGMT.patch &&
50+
sed -e "s/TS0/$timeWest/" -e "s/TS1/$epocWest2/" <d >removeWest2.patch &&
4951
5052
echo something >something &&
5153
>empty

0 commit comments

Comments
 (0)