From: Robie Basak <robie.basak@canonical.com>
To: git@vger.kernel.org
Subject: [PATCH] apply: squash consecutive slashes with p_value > 0
Date: Wed, 16 Nov 2011 12:04:03 +0000 [thread overview]
Message-ID: <20111116120403.GA10342@mal.justgohome.co.uk> (raw)
"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 reply other threads:[~2011-11-16 12:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-16 12:04 Robie Basak [this message]
2011-11-16 17:36 ` [PATCH] apply: squash consecutive slashes with p_value > 0 Junio C Hamano
[not found] ` <20111117150409.GB17472@mal.justgohome.co.uk>
[not found] ` <7vr516myqh.fsf@alter.siamese.dyndns.org>
2011-11-17 17:55 ` Robie Basak
2011-11-17 18:07 ` Junio C Hamano
2011-11-17 18:57 ` Robie Basak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111116120403.GA10342@mal.justgohome.co.uk \
--to=robie.basak@canonical.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).