Skip to content

Commit ded4dfd

Browse files
committed
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
2 parents ae0a37c + 2d502e1 commit ded4dfd

File tree

5 files changed

+57
-6
lines changed

5 files changed

+57
-6
lines changed

builtin/apply.c

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ static char *find_name_gnu(const char *line, char *def, int p_value)
449449
return squash_slash(strbuf_detach(&name, NULL));
450450
}
451451

452-
static size_t tz_len(const char *line, size_t len)
452+
static size_t sane_tz_len(const char *line, size_t len)
453453
{
454454
const char *tz, *p;
455455

@@ -467,6 +467,24 @@ static size_t tz_len(const char *line, size_t len)
467467
return line + len - tz;
468468
}
469469

470+
static size_t tz_with_colon_len(const char *line, size_t len)
471+
{
472+
const char *tz, *p;
473+
474+
if (len < strlen(" +08:00") || line[len - strlen(":00")] != ':')
475+
return 0;
476+
tz = line + len - strlen(" +08:00");
477+
478+
if (tz[0] != ' ' || (tz[1] != '+' && tz[1] != '-'))
479+
return 0;
480+
p = tz + 2;
481+
if (!isdigit(*p++) || !isdigit(*p++) || *p++ != ':' ||
482+
!isdigit(*p++) || !isdigit(*p++))
483+
return 0;
484+
485+
return line + len - tz;
486+
}
487+
470488
static size_t date_len(const char *line, size_t len)
471489
{
472490
const char *date, *p;
@@ -561,7 +579,9 @@ static size_t diff_timestamp_len(const char *line, size_t len)
561579
if (!isdigit(end[-1]))
562580
return 0;
563581

564-
n = tz_len(line, end - line);
582+
n = sane_tz_len(line, end - line);
583+
if (!n)
584+
n = tz_with_colon_len(line, end - line);
565585
end -= n;
566586

567587
n = short_time_len(line, end - line);
@@ -733,8 +753,8 @@ static int has_epoch_timestamp(const char *nameline)
733753
" "
734754
"[0-2][0-9]:[0-5][0-9]:00(\\.0+)?"
735755
" "
736-
"([-+][0-2][0-9][0-5][0-9])\n";
737-
const char *timestamp = NULL, *cp;
756+
"([-+][0-2][0-9]:?[0-5][0-9])\n";
757+
const char *timestamp = NULL, *cp, *colon;
738758
static regex_t *stamp;
739759
regmatch_t m[10];
740760
int zoneoffset;
@@ -764,8 +784,11 @@ static int has_epoch_timestamp(const char *nameline)
764784
return 0;
765785
}
766786

767-
zoneoffset = strtol(timestamp + m[3].rm_so + 1, NULL, 10);
768-
zoneoffset = (zoneoffset / 100) * 60 + (zoneoffset % 100);
787+
zoneoffset = strtol(timestamp + m[3].rm_so + 1, (char **) &colon, 10);
788+
if (*colon == ':')
789+
zoneoffset = zoneoffset * 60 + strtol(colon + 1, NULL, 10);
790+
else
791+
zoneoffset = (zoneoffset / 100) * 60 + (zoneoffset % 100);
769792
if (timestamp[m[3].rm_so] == '-')
770793
zoneoffset = -zoneoffset;
771794

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

t/t4135-apply-weird-filenames.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,20 @@ test_expect_success 'whitespace-damaged traditional patch' '
7272
test_cmp expected postimage.txt
7373
'
7474

75+
test_expect_success 'traditional patch with colon in timezone' '
76+
echo postimage >expected &&
77+
reset_preimage &&
78+
rm -f "post image.txt" &&
79+
git apply "$vector/funny-tz.diff" &&
80+
test_cmp expected "post image.txt"
81+
'
82+
83+
test_expect_success 'traditional, whitespace-damaged, colon in timezone' '
84+
echo postimage >expected &&
85+
reset_preimage &&
86+
rm -f "post image.txt" &&
87+
git apply "$vector/damaged-tz.diff" &&
88+
test_cmp expected "post image.txt"
89+
'
90+
7591
test_done

t/t4135/damaged-tz.diff

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
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
2+
--- linux-2.6.12-rc2-mm3-vanilla/post image.txt 1969-12-31 16:00:00 -08:00
3+
+++ linux-2.6.12-rc2-mm3/post image.txt 2005-04-12 02:14:06 -07:00
4+
@@ -0,0 +1 @@
5+
+postimage

t/t4135/funny-tz.diff

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
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
2+
--- linux-2.6.12-rc2-mm3-vanilla/post image.txt 1969-12-31 16:00:00 -08:00
3+
+++ linux-2.6.12-rc2-mm3/post image.txt 2005-04-12 02:14:06 -07:00
4+
@@ -0,0 +1 @@
5+
+postimage

0 commit comments

Comments
 (0)