diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-12-09 10:36:36 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-12-09 10:36:36 -0800 |
commit | a59c87265b917eb0d1b95c73ed829d47ee2ded6b (patch) | |
tree | bcb2e1e97d65799dbc35fefc769747c52b794cbf /builtin | |
parent | 5605685a71bd65548dab56e457b15d365b4350b4 (diff) | |
parent | aae1f6acf1984f4ae4453ad299a1fa4d261fb188 (diff) | |
download | git-a59c87265b917eb0d1b95c73ed829d47ee2ded6b.tar.gz |
Merge branch 'fc/apply-p2-get-header-name' into maint
* fc/apply-p2-get-header-name:
test: git-apply -p2 rename/chmod only
Fix git-apply with -p greater than 1
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/apply.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/builtin/apply.c b/builtin/apply.c index 4e800b5c8d..b719f41482 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -942,28 +942,28 @@ static int gitdiff_newfile(const char *line, struct patch *patch) static int gitdiff_copysrc(const char *line, struct patch *patch) { patch->is_copy = 1; - patch->old_name = find_name(line, NULL, 0, 0); + patch->old_name = find_name(line, NULL, p_value ? p_value - 1 : 0, 0); return 0; } static int gitdiff_copydst(const char *line, struct patch *patch) { patch->is_copy = 1; - patch->new_name = find_name(line, NULL, 0, 0); + patch->new_name = find_name(line, NULL, p_value ? p_value - 1 : 0, 0); return 0; } static int gitdiff_renamesrc(const char *line, struct patch *patch) { patch->is_rename = 1; - patch->old_name = find_name(line, NULL, 0, 0); + patch->old_name = find_name(line, NULL, p_value ? p_value - 1 : 0, 0); return 0; } static int gitdiff_renamedst(const char *line, struct patch *patch) { patch->is_rename = 1; - patch->new_name = find_name(line, NULL, 0, 0); + patch->new_name = find_name(line, NULL, p_value ? p_value - 1 : 0, 0); return 0; } @@ -1048,7 +1048,7 @@ static char *git_header_name(char *line, int llen) { const char *name; const char *second = NULL; - size_t len; + size_t len, line_len; line += strlen("diff --git "); llen -= strlen("diff --git "); @@ -1148,6 +1148,10 @@ static char *git_header_name(char *line, int llen) * Accept a name only if it shows up twice, exactly the same * form. */ + second = strchr(name, '\n'); + if (!second) + return NULL; + line_len = second - name; for (len = 0 ; ; len++) { switch (name[len]) { default: @@ -1155,15 +1159,11 @@ static char *git_header_name(char *line, int llen) case '\n': return NULL; case '\t': case ' ': - second = name+len; - for (;;) { - char c = *second++; - if (c == '\n') - return NULL; - if (c == '/') - break; - } - if (second[len] == '\n' && !memcmp(name, second, len)) { + second = stop_at_slash(name + len, line_len - len); + if (!second) + return NULL; + second++; + if (second[len] == '\n' && !strncmp(name, second, len)) { return xmemdupz(name, len); } } |