Merge branch 'fc/apply-p2-get-header-name'
* fc/apply-p2-get-header-name: test: git-apply -p2 rename/chmod only Fix git-apply with -p greater than 1maint
commit
f3f973a017
|
@ -942,28 +942,28 @@ static int gitdiff_newfile(const char *line, struct patch *patch)
|
||||||
static int gitdiff_copysrc(const char *line, struct patch *patch)
|
static int gitdiff_copysrc(const char *line, struct patch *patch)
|
||||||
{
|
{
|
||||||
patch->is_copy = 1;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int gitdiff_copydst(const char *line, struct patch *patch)
|
static int gitdiff_copydst(const char *line, struct patch *patch)
|
||||||
{
|
{
|
||||||
patch->is_copy = 1;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int gitdiff_renamesrc(const char *line, struct patch *patch)
|
static int gitdiff_renamesrc(const char *line, struct patch *patch)
|
||||||
{
|
{
|
||||||
patch->is_rename = 1;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int gitdiff_renamedst(const char *line, struct patch *patch)
|
static int gitdiff_renamedst(const char *line, struct patch *patch)
|
||||||
{
|
{
|
||||||
patch->is_rename = 1;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1048,7 +1048,7 @@ static char *git_header_name(char *line, int llen)
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
const char *second = NULL;
|
const char *second = NULL;
|
||||||
size_t len;
|
size_t len, line_len;
|
||||||
|
|
||||||
line += strlen("diff --git ");
|
line += strlen("diff --git ");
|
||||||
llen -= 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
|
* Accept a name only if it shows up twice, exactly the same
|
||||||
* form.
|
* form.
|
||||||
*/
|
*/
|
||||||
|
second = strchr(name, '\n');
|
||||||
|
if (!second)
|
||||||
|
return NULL;
|
||||||
|
line_len = second - name;
|
||||||
for (len = 0 ; ; len++) {
|
for (len = 0 ; ; len++) {
|
||||||
switch (name[len]) {
|
switch (name[len]) {
|
||||||
default:
|
default:
|
||||||
|
@ -1155,15 +1159,11 @@ static char *git_header_name(char *line, int llen)
|
||||||
case '\n':
|
case '\n':
|
||||||
return NULL;
|
return NULL;
|
||||||
case '\t': case ' ':
|
case '\t': case ' ':
|
||||||
second = name+len;
|
second = stop_at_slash(name + len, line_len - len);
|
||||||
for (;;) {
|
if (!second)
|
||||||
char c = *second++;
|
return NULL;
|
||||||
if (c == '\n')
|
second++;
|
||||||
return NULL;
|
if (second[len] == '\n' && !strncmp(name, second, len)) {
|
||||||
if (c == '/')
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (second[len] == '\n' && !memcmp(name, second, len)) {
|
|
||||||
return xmemdupz(name, len);
|
return xmemdupz(name, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,4 +56,30 @@ test_expect_success 'apply with too large -p and fancy filename' '
|
||||||
grep "removing 3 leading" err
|
grep "removing 3 leading" err
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'apply (-p2) diff, mode change only' '
|
||||||
|
cat >patch.chmod <<-\EOF &&
|
||||||
|
diff --git a/sub/file1 b/sub/file1
|
||||||
|
old mode 100644
|
||||||
|
new mode 100755
|
||||||
|
EOF
|
||||||
|
chmod 644 file1 &&
|
||||||
|
git apply -p2 patch.chmod &&
|
||||||
|
test -x file1
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'apply (-p2) diff, rename' '
|
||||||
|
cat >patch.rename <<-\EOF &&
|
||||||
|
diff --git a/sub/file1 b/sub/file2
|
||||||
|
similarity index 100%
|
||||||
|
rename from sub/file1
|
||||||
|
rename to sub/file2
|
||||||
|
EOF
|
||||||
|
echo A >expected &&
|
||||||
|
|
||||||
|
cp file1.saved file1 &&
|
||||||
|
rm -f file2 &&
|
||||||
|
git apply -p2 patch.rename &&
|
||||||
|
test_cmp expected file2
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Loading…
Reference in New Issue