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 <andersk@mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Anders Kaseorg committed
Sep 29, 2010 at 16:49 UTC
a1980c4efcfea516e2ba442bf7e56a39d9a7933f
2 files changed
+9
-4
builtin/apply.c
+7
-4
@@ -733,8 +733,8 @@ static int has_epoch_timestamp(const char *nameline)
733
" "
734
"[0-2][0-9]:[0-5][0-9]:00(\\.0+)?"
735
" "
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;
738
static regex_t *stamp;
739
regmatch_t m[10];
740
int zoneoffset;
@@ -764,8 +764,11 @@ static int has_epoch_timestamp(const char *nameline)
764
return 0;
765
}
766
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);
772
if (timestamp[m[3].rm_so] == '-')
773
zoneoffset = -zoneoffset;
774
t/t4132-apply-removal.sh
+2
@@ -30,6 +30,7 @@ test_expect_success setup '
30
epocWest="1969-12-31 16:00:00.000000000 -0800" &&
31
epocGMT="1970-01-01 00:00:00.000000000 +0000" &&
32
epocEast="1970-01-01 09:00:00.000000000 +0900" &&
33
+ epocWest2="1969-12-31 16:00:00 -08:00" &&
34
35
sed -e "s/TS0/$epocWest/" -e "s/TS1/$timeWest/" <c >createWest.patch &&
36
sed -e "s/TS0/$epocEast/" -e "s/TS1/$timeEast/" <c >createEast.patch &&
@@ -46,6 +47,7 @@ test_expect_success setup '
47
sed -e "s/TS0/$timeWest/" -e "s/TS1/$epocWest/" <d >removeWest.patch &&
48
sed -e "s/TS0/$timeEast/" -e "s/TS1/$epocEast/" <d >removeEast.patch &&
49
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 &&
51
52
echo something >something &&
53
>empty