summaryrefslogtreecommitdiff
path: root/builtin-apply.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-11-25 02:56:54 -0800
committerJunio C Hamano <gitster@pobox.com>2009-11-26 19:02:24 -0800
commitec7fc0b1a46c5a352532ea3f29c5663752fd8ac6 (patch)
tree540136a940dde0e0293f047f6f2ed2a26a21b805 /builtin-apply.c
parent4f366275189c06ec26c01ee5ace2f3831b2aa46a (diff)
downloadgit-ec7fc0b1a46c5a352532ea3f29c5663752fd8ac6.tar.gz
builtin-apply.c: pay attention to -p<n> when determining the name
The patch structure has def_name component that is used to validate the sanity of a "diff --git" patch by checking pathnames that appear on the patch header lines for consistency. The git_header_name() function is used to compute this out of "diff --git a/... b/..." line, but the code always stripped one level of prefix (i.e. "a/" and "b/"), without paying attention to -p<n> option. Code in find_name() function that parses other lines in the patch header (e.g. "--- a/..." and "+++ b/..." lines) however did strip the correct number of leading paths prefixes, and the sanity check between these computed values failed. Teach git_header_name() to honor -p<n> option like find_name() function does. Found and reported by Steven J. Murdoch who also wrote tests. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-apply.c')
-rw-r--r--builtin-apply.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/builtin-apply.c b/builtin-apply.c
index f667368d16..36e2f9dda5 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -823,12 +823,13 @@ static int gitdiff_unrecognized(const char *line, struct patch *patch)
static const char *stop_at_slash(const char *line, int llen)
{
+ int nslash = p_value;
int i;
for (i = 0; i < llen; i++) {
int ch = line[i];
- if (ch == '/')
- return line + i;
+ if (ch == '/' && --nslash <= 0)
+ return &line[i];
}
return NULL;
}