summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: aea1945)
raw | patch | inline | side by side (parent: aea1945)
author | Junio C Hamano <junkio@cox.net> | |
Tue, 20 Feb 2007 01:57:29 +0000 (17:57 -0800) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Tue, 20 Feb 2007 02:44:59 +0000 (18:44 -0800) |
git-apply running inside a subdirectory, with or without --index,
used to always assume that the patch is formatted in such a way
to apply with -p1 from the toplevel, but it is more useful and
consistent with the use of "GNU patch -p1" if it defaulted to
assume that its input is meant to apply at the level it is
invoked in.
This changes the behaviour. It used to be that the patch
generated this way would apply without any trick:
edit Documentation/Makefile
git diff >patch.file
cd Documentation
git apply ../patch.file
You need to give an explicit -p2 to git-apply now. On the other
hand, if you got a patch from somebody else who did not follow
"patch is to apply from the top with -p1" convention, the input
patch would start with:
diff -u Makefile.old Makefile
--- Makefile.old
+++ Makefile
and in such a case, you can apply it with:
git apply -p0 patch.file
Signed-off-by: Junio C Hamano <junkio@cox.net>
used to always assume that the patch is formatted in such a way
to apply with -p1 from the toplevel, but it is more useful and
consistent with the use of "GNU patch -p1" if it defaulted to
assume that its input is meant to apply at the level it is
invoked in.
This changes the behaviour. It used to be that the patch
generated this way would apply without any trick:
edit Documentation/Makefile
git diff >patch.file
cd Documentation
git apply ../patch.file
You need to give an explicit -p2 to git-apply now. On the other
hand, if you got a patch from somebody else who did not follow
"patch is to apply from the top with -p1" convention, the input
patch would start with:
diff -u Makefile.old Makefile
--- Makefile.old
+++ Makefile
and in such a case, you can apply it with:
git apply -p0 patch.file
Signed-off-by: Junio C Hamano <junkio@cox.net>
builtin-apply.c | patch | blob | history | |
t/t4119-apply-config.sh | patch | blob | history |
diff --git a/builtin-apply.c b/builtin-apply.c
index 3f829fb661d28778a3527b01ada4334ea53093db..053511e2ee23cc6a1db524bd0dbe3a25260f25dd 100644 (file)
--- a/builtin-apply.c
+++ b/builtin-apply.c
return 1;
}
-static char * find_name(const char *line, char *def, int p_value, int terminate)
+static char *find_name(const char *line, char *def, int p_value, int terminate)
{
int len;
const char *start = line;
static char *gitdiff_verify_name(const char *line, int isnull, char *orig_name, const char *oldnew)
{
if (!orig_name && !isnull)
- return find_name(line, NULL, 1, TERM_TAB);
+ return find_name(line, NULL, p_value, TERM_TAB);
if (orig_name) {
int len;
len = strlen(name);
if (isnull)
die("git-apply: bad git-diff - expected /dev/null, got %s on line %d", name, linenr);
- another = find_name(line, NULL, 1, TERM_TAB);
+ another = find_name(line, NULL, p_value, TERM_TAB);
if (!another || memcmp(another, name, len))
die("git-apply: bad git-diff - inconsistent %s filename on line %d", oldnew, linenr);
free(another);
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-1, 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-1, 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-1, 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-1, 0);
return 0;
}
return 0;
x = x->next;
}
- if (0 < prefix_length) {
- int pathlen = strlen(pathname);
- if (pathlen <= prefix_length ||
- memcmp(prefix, pathname, prefix_length))
- return 0;
- }
return 1;
}
+static char *prefix_one(char *name)
+{
+ if (!name)
+ return name;
+ return xstrdup(prefix_filename(prefix, prefix_length, name));
+}
+
+static void prefix_patches(struct patch *p)
+{
+ if (!prefix)
+ return;
+ for ( ; p; p = p->next) {
+ p->new_name = prefix_one(p->new_name);
+ p->old_name = prefix_one(p->old_name);
+ }
+}
+
static int apply_patch(int fd, const char *filename, int inaccurate_eof)
{
unsigned long offset, size;
break;
if (apply_in_reverse)
reverse_patches(patch);
+ if (prefix)
+ prefix_patches(patch);
if (use_patch(patch)) {
patch_stats(patch);
*listp = patch;
listp = &patch->next;
- } else {
+ }
+ else {
/* perhaps free it a bit better? */
free(patch);
skipped_patch++;
index 0e8ea7e2b8f24edea491cdf865c77158725f89fa..816b5b8fb2388e59d99532f49a5c46f81dfc8125 100755 (executable)
--- a/t/t4119-apply-config.sh
+++ b/t/t4119-apply-config.sh
. ./test-lib.sh
test_expect_success setup '
- echo A >file1 &&
- cp file1 saved &&
- git add file1 &&
- echo "B " >file1 &&
+ mkdir sub &&
+ echo A >sub/file1 &&
+ cp sub/file1 saved &&
+ git add sub/file1 &&
+ echo "B " >sub/file1 &&
git diff >patch.file
'
test_expect_success 'apply --whitespace=strip' '
- cp saved file1 &&
+ rm -f sub/file1 &&
+ cp saved sub/file1 &&
git update-index --refresh &&
git apply --whitespace=strip patch.file &&
- if grep " " file1
+ if grep " " sub/file1
then
echo "Eh?"
false
test_expect_success 'apply --whitespace=strip from config' '
- cp saved file1 &&
+ rm -f sub/file1 &&
+ cp saved sub/file1 &&
git update-index --refresh &&
git config apply.whitespace strip &&
git apply patch.file &&
- if grep " " file1
+ if grep " " sub/file1
then
echo "Eh?"
false
fi
'
-mkdir sub
D=`pwd`
test_expect_success 'apply --whitespace=strip in subdir' '
cd "$D" &&
git config --unset-all apply.whitespace
- cp saved file1 &&
+ rm -f sub/file1 &&
+ cp saved sub/file1 &&
git update-index --refresh &&
cd sub &&
- git apply --whitespace=strip ../patch.file &&
- if grep " " ../file1
+ git apply --whitespace=strip -p2 ../patch.file &&
+ if grep " " file1
then
echo "Eh?"
false
cd "$D" &&
git config apply.whitespace strip &&
- cp saved file1 &&
+ rm -f sub/file1 &&
+ cp saved sub/file1 &&
git update-index --refresh &&
cd sub &&
- git apply ../patch.file &&
+ git apply -p2 ../patch.file &&
if grep " " file1
then
echo "Eh?"