Skip to content

Commit

Permalink
apply: handle patches with funny filename and colon in timezone
Browse files Browse the repository at this point in the history
Some patches have a timezone formatted like '-08:00' instead of
'-0800' in their ---/+++ lines (e.g. http://lwn.net/Articles/131729/).
Take this into account when searching for the start of the timezone
(which is the end of the filename).

This does not actually affect the outcome of patching unless (1) a
file being patched has a non-' ' whitespace character (e.g., tab) in
its filename, or (2) the patch is whitespace-damaged, so the tab
between filename and timestamp has been replaced with spaces.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jonathan Nieder authored and Junio C Hamano committed Nov 10, 2010
1 parent a1980c4 commit 2d502e1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
24 changes: 22 additions & 2 deletions builtin/apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions t/t4135-apply-weird-filenames.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 5 additions & 0 deletions t/t4135/damaged-tz.diff
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions t/t4135/funny-tz.diff
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2d502e1

Please sign in to comment.