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

[PATCH] builtin-apply.c: Skip filenames without enough components

From
AGAndreas Gruenbacher <agruen@suse.de>
Date
Jan 17, 2010, 02:05 UTC
Message-ID
<201001170305.10793.agruen@suse.de>

find_name() wrongly returned the whole filename for filenames without enough leading pathname components (e.g., when applying a patch to a top-level file with -p2).

Include the -p value used in the error message when no filenames can be found.

Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
---
 builtin-apply.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/builtin-apply.c b/builtin-apply.c
index 541493e..b99db0b 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -404,6 +404,9 @@ static char *squash_slash(char *name)
 {
 	int i = 0, j = 0;
 
+	if (!name)
+		return NULL;
+
 	while (name[i]) {
 		if ((name[j++] = name[i++]) == '/')
 			while (name[i] == '/')
@@ -416,7 +419,10 @@ static char *squash_slash(char *name)
 static char *find_name(const char *line, char *def, int p_value, int terminate)
 {
 	int len;
-	const char *start = line;
+	const char *start = NULL;
+
+	if (p_value == 0)
+		start = line;
 
 	if (*line == '"') {
 		struct strbuf name = STRBUF_INIT;
@@ -1199,7 +1205,8 @@ static int find_header(char *line, unsigned long size, int *hdrsize, 
struct patc
 				continue;
 			if (!patch->old_name && !patch->new_name) {
 				if (!patch->def_name)
-					die("git diff header lacks filename information (line %d)", linenr);
+					die("git diff header lacks filename information when removing "
+					    "%d leading pathname components (line %d)" , p_value, linenr);
 				patch->old_name = patch->new_name = patch->def_name;
 			}
 			patch->is_toplevel_relative = 1;
-- 
1.6.6.197.g9c4a28
Next: Junio C Hamano
Message 1 of 5 in “builtin-apply.c: Skip filenames without enough components”
  1. builtin-apply.c: Skip filenames without enough componentsAndreas Gruenbacher, Jan 17, 2010
  2. Junio C HamanoJan 17, 2010
  3. Andreas GruenbacherJan 17, 2010
  4. Nanako ShiraishiJan 18, 2010
  5. Andreas GruenbacherJan 18, 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.