Merge branch 'ak/apply-non-git-epoch' into maint
* ak/apply-non-git-epoch: apply: handle patches with funny filename and colon in timezone apply: Recognize epoch timestamps with : in the timezone
This commit is contained in:
commit
ded4dfd519
@ -449,7 +449,7 @@ static char *find_name_gnu(const char *line, char *def, int p_value)
|
||||
return squash_slash(strbuf_detach(&name, NULL));
|
||||
}
|
||||
|
||||
static size_t tz_len(const char *line, size_t len)
|
||||
static size_t sane_tz_len(const char *line, size_t len)
|
||||
{
|
||||
const char *tz, *p;
|
||||
|
||||
@ -467,6 +467,24 @@ static size_t tz_len(const char *line, size_t len)
|
||||
return line + len - tz;
|
||||
}
|
||||
|
||||
static size_t tz_with_colon_len(const char *line, size_t len)
|
||||
{
|
||||
const char *tz, *p;
|
||||
|
||||
if (len < strlen(" +08:00") || line[len - strlen(":00")] != ':')
|
||||
return 0;
|
||||
tz = line + len - strlen(" +08:00");
|
||||
|
||||
if (tz[0] != ' ' || (tz[1] != '+' && tz[1] != '-'))
|
||||
return 0;
|
||||
p = tz + 2;
|
||||
if (!isdigit(*p++) || !isdigit(*p++) || *p++ != ':' ||
|
||||
!isdigit(*p++) || !isdigit(*p++))
|
||||
return 0;
|
||||
|
||||
return line + len - tz;
|
||||
}
|
||||
|
||||
static size_t date_len(const char *line, size_t len)
|
||||
{
|
||||
const char *date, *p;
|
||||
@ -561,7 +579,9 @@ static size_t diff_timestamp_len(const char *line, size_t len)
|
||||
if (!isdigit(end[-1]))
|
||||
return 0;
|
||||
|
||||
n = tz_len(line, end - line);
|
||||
n = sane_tz_len(line, end - line);
|
||||
if (!n)
|
||||
n = tz_with_colon_len(line, end - line);
|
||||
end -= n;
|
||||
|
||||
n = short_time_len(line, end - line);
|
||||
@ -733,8 +753,8 @@ static int has_epoch_timestamp(const char *nameline)
|
||||
" "
|
||||
"[0-2][0-9]:[0-5][0-9]:00(\\.0+)?"
|
||||
" "
|
||||
"([-+][0-2][0-9][0-5][0-9])\n";
|
||||
const char *timestamp = NULL, *cp;
|
||||
"([-+][0-2][0-9]:?[0-5][0-9])\n";
|
||||
const char *timestamp = NULL, *cp, *colon;
|
||||
static regex_t *stamp;
|
||||
regmatch_t m[10];
|
||||
int zoneoffset;
|
||||
@ -764,8 +784,11 @@ static int has_epoch_timestamp(const char *nameline)
|
||||
return 0;
|
||||
}
|
||||
|
||||
zoneoffset = strtol(timestamp + m[3].rm_so + 1, NULL, 10);
|
||||
zoneoffset = (zoneoffset / 100) * 60 + (zoneoffset % 100);
|
||||
zoneoffset = strtol(timestamp + m[3].rm_so + 1, (char **) &colon, 10);
|
||||
if (*colon == ':')
|
||||
zoneoffset = zoneoffset * 60 + strtol(colon + 1, NULL, 10);
|
||||
else
|
||||
zoneoffset = (zoneoffset / 100) * 60 + (zoneoffset % 100);
|
||||
if (timestamp[m[3].rm_so] == '-')
|
||||
zoneoffset = -zoneoffset;
|
||||
|
||||
|
@ -30,6 +30,7 @@ test_expect_success setup '
|
||||
epocWest="1969-12-31 16:00:00.000000000 -0800" &&
|
||||
epocGMT="1970-01-01 00:00:00.000000000 +0000" &&
|
||||
epocEast="1970-01-01 09:00:00.000000000 +0900" &&
|
||||
epocWest2="1969-12-31 16:00:00 -08:00" &&
|
||||
|
||||
sed -e "s/TS0/$epocWest/" -e "s/TS1/$timeWest/" <c >createWest.patch &&
|
||||
sed -e "s/TS0/$epocEast/" -e "s/TS1/$timeEast/" <c >createEast.patch &&
|
||||
@ -46,6 +47,7 @@ test_expect_success setup '
|
||||
sed -e "s/TS0/$timeWest/" -e "s/TS1/$epocWest/" <d >removeWest.patch &&
|
||||
sed -e "s/TS0/$timeEast/" -e "s/TS1/$epocEast/" <d >removeEast.patch &&
|
||||
sed -e "s/TS0/$timeGMT/" -e "s/TS1/$epocGMT/" <d >removeGMT.patch &&
|
||||
sed -e "s/TS0/$timeWest/" -e "s/TS1/$epocWest2/" <d >removeWest2.patch &&
|
||||
|
||||
echo something >something &&
|
||||
>empty
|
||||
|
@ -72,4 +72,20 @@ test_expect_success 'whitespace-damaged traditional patch' '
|
||||
test_cmp expected postimage.txt
|
||||
'
|
||||
|
||||
test_expect_success 'traditional patch with colon in timezone' '
|
||||
echo postimage >expected &&
|
||||
reset_preimage &&
|
||||
rm -f "post image.txt" &&
|
||||
git apply "$vector/funny-tz.diff" &&
|
||||
test_cmp expected "post image.txt"
|
||||
'
|
||||
|
||||
test_expect_success 'traditional, whitespace-damaged, colon in timezone' '
|
||||
echo postimage >expected &&
|
||||
reset_preimage &&
|
||||
rm -f "post image.txt" &&
|
||||
git apply "$vector/damaged-tz.diff" &&
|
||||
test_cmp expected "post image.txt"
|
||||
'
|
||||
|
||||
test_done
|
||||
|
5
t/t4135/damaged-tz.diff
Normal file
5
t/t4135/damaged-tz.diff
Normal file
@ -0,0 +1,5 @@
|
||||
diff -urN -X /usr/people/jes/exclude-linux linux-2.6.12-rc2-mm3-vanilla/post image.txt linux-2.6.12-rc2-mm3/post image.txt
|
||||
--- linux-2.6.12-rc2-mm3-vanilla/post image.txt 1969-12-31 16:00:00 -08:00
|
||||
+++ linux-2.6.12-rc2-mm3/post image.txt 2005-04-12 02:14:06 -07:00
|
||||
@@ -0,0 +1 @@
|
||||
+postimage
|
5
t/t4135/funny-tz.diff
Normal file
5
t/t4135/funny-tz.diff
Normal file
@ -0,0 +1,5 @@
|
||||
diff -urN -X /usr/people/jes/exclude-linux linux-2.6.12-rc2-mm3-vanilla/post image.txt linux-2.6.12-rc2-mm3/post image.txt
|
||||
--- linux-2.6.12-rc2-mm3-vanilla/post image.txt 1969-12-31 16:00:00 -08:00
|
||||
+++ linux-2.6.12-rc2-mm3/post image.txt 2005-04-12 02:14:06 -07:00
|
||||
@@ -0,0 +1 @@
|
||||
+postimage
|
Loading…
Reference in New Issue
Block a user