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 21, 2010, 22:12 UTC
Message-ID
<1287699122-26702-1-git-send-email-fedux@lugmen.org.ar>

Fix the case when the patch is a rename or mode-change only and -p is used with a value greater than one. The git_header_name function did not remove more than one path component.

Signed-off-by: Federico Cuello <fedux@lugmen.org.ar>
---
 builtin/apply.c |   14 +++++---------
 1 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/builtin/apply.c b/builtin/apply.c
index 23c18c5..14996f8 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -1132,15 +1132,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, (name - line) + len);
+			if (!second)
+				return NULL;
+			second++;
+			if (second[len] == '\n' && !strncmp(name, second, len)) {
 				return xmemdupz(name, len);
 			}
 		}
-- 
1.7.3.1
Next: Junio C Hamano
Message 1 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.