git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Fix git-apply with -p greater than 1

From
Federico Cuello <fedux@lugmen.org.ar>
Date
Oct 25, 2010, 14:11 UTC
Message-ID
<1288015897-21565-1-git-send-email-fedux@lugmen.org.ar>
In-Reply-To
<7v8w1qm5n2.fsf@alter.siamese.dyndns.org>

Fix for rename/copy patches. Filenames don't include 'a/' or 'b/' prefix, then use p_value minus one.

Also add 'copy' test script.
Signed-off-by: Federico Cuello <fedux@lugmen.org.ar>
---
 builtin/apply.c       |    8 ++++----
 t/t4120-apply-popt.sh |   13 +++++++++++++
 2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/builtin/apply.c b/builtin/apply.c
index 14996f8..3197e38 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -919,28 +919,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;
 }
 
diff --git a/t/t4120-apply-popt.sh b/t/t4120-apply-popt.sh
index 579c9e6..4ed06f0 100755
--- a/t/t4120-apply-popt.sh
+++ b/t/t4120-apply-popt.sh
@@ -82,4 +82,17 @@ test_expect_success 'apply (-p2) diff, rename' '
 	test_cmp expected file2
 '
 
+test_expect_success 'apply (-p2) diff, copy' '
+	cat >patch.copy <<-\EOF &&
+	diff --git a/sub/file1 b/sub/file2
+	similarity index 100%
+	copy from sub/file1
+	copy to sub/file2
+	EOF
+	cp file1.saved file1 &&
+	rm -f file2 &&
+	git apply -p2 patch.copy &&
+	test_cmp file1 file2
+'
+
 test_done
-- 
1.7.3.2
Previous: Federico CuelloNext: Junio C Hamano
Message 8 of 9 in “Fix git-apply with -p greater than 1”
  1. Fix git-apply with -p greater than 1Federico Cuello, Oct 21, 2010
  2. Junio C HamanoOct 22, 2010
  3. Jonathan NiederOct 22, 2010
  4. FedeOct 22, 2010
  5. Jonathan NiederOct 22, 2010
  6. Junio C HamanoOct 22, 2010
  7. Federico CuelloOct 22, 2010
  8. Fix git-apply with -p greater than 1Federico Cuello, Oct 25, 2010
  9. Junio C HamanoOct 22, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.