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

[PATCH] apply: squash consecutive slashes with p_value > 0

From
RBRobie Basak <robie.basak@canonical.com>
Date
Nov 16, 2011, 12:04 UTC
Message-ID
<20111116120403.GA10342@mal.justgohome.co.uk>
"patch" works with -p1 and diffs in the following form:
    --- foo.orig//bar
    +++ foo//bar
    ...

patch(1) says that "A sequence of one or more adjacent slashes is counted as a single slash."

This patch amends git-apply's filename parsing to behave in the same way, eliminating both '/'s with -p1 in this example.

Test case included.
Signed-off-by: Robie Basak <robie.basak@canonical.com>
---
 builtin/apply.c              |    8 ++++++--
 t/t4153-apply-doubleslash.sh |   29 +++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 2 deletions(-)
 create mode 100755 t/t4153-apply-doubleslash.sh
diff --git a/builtin/apply.c b/builtin/apply.c
index 84a8a0b..78e25fa 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -627,9 +627,13 @@ static char *find_name_common(const char *line, char *def, int p_value,
 			if (name_terminate(start, line-start, c, terminate))
 				break;
 		}
-		line++;
-		if (c == '/' && !--p_value)
+		if (c == '/' && !--p_value) {
+			while (*line == '/')
+			    line++;
 			start = line;
+		} else {
+			line++;
+		}
 	}
 	if (!start)
 		return squash_slash(def);
diff --git a/t/t4153-apply-doubleslash.sh b/t/t4153-apply-doubleslash.sh
new file mode 100755
index 0000000..1ea76b5
--- /dev/null
+++ b/t/t4153-apply-doubleslash.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+#
+# Copyright (c) 2011 Canonical Ltd.
+#
+
+test_description='git apply filenames with double slashes
+
+Try to apply a patch with git-apply where the filename specified has a double
+slash after the first (to-be-stripped) component'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+	test_commit 1 f &&
+	cat > good.patch <<EOF
+diff -u a//f b//f
+--- a//f
++++ b//f
+@@ -1 +1 @@
+-1
++2
+EOF
+'
+
+test_expect_success 'apply diff with double slashes in filenames' '
+	git apply good.patch 2>err
+'
+
+test_done
-- 
1.7.5.4
Next: Junio C Hamano
Message 1 of 5 in “apply: squash consecutive slashes with p_value > 0”
  1. apply: squash consecutive slashes with p_value > 0Robie Basak, Nov 16, 2011
  2. Junio C HamanoNov 16, 2011
  3. Robie BasakNov 17, 2011
  4. Junio C HamanoNov 17, 2011
  5. Robie BasakNov 17, 2011

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.