From: Michal Marek <mmarek@suse.cz>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] apply: handle filenames with double slashes better
Date: Thu, 21 May 2009 21:12:04 +0200 [thread overview]
Message-ID: <20090521191204.GA29362@sepie.suse.cz> (raw)
In-Reply-To: <7vd4a2bj3p.fsf@alter.siamese.dyndns.org>
On Thu, May 21, 2009 at 07:56:10AM -0700, Junio C Hamano wrote:
> Michal Marek <mmarek@suse.cz> writes:
>
> > Collapse double slashes to make patches like this work with --index or
> > --cached:
> >
> > git apply --index <<-EOF
> > --- a/perl//Git.pm
> > +++ b/perl//Git.pm
> > @@ -1358,3 +1358,4 @@
> >
> >
> > 1; # Famous last words
> > +# test
> > EOF
> >
> > Signed-off-by: Michal Marek <mmarek@suse.cz>
>
> Hmm, I do not know if this is a good change.
>
> For duplicate slashes in paths, I do not think there is any other sensible
> way to handle them other than squashing them together, but naming the
> function to do so "canon_name()" would tempt people to add other
> not-so-clearly-sensible "canonicalization" such as turning "./a" to "a"
> (which we shouldn't --- we should treat "./" as one level so that we keep
> behaving in a similar way as "patch -p1" does) or "a/../b" to "b".
OK, renamed to squash_slash().
> Also calling this in find_name() loses information too early in the
> processing; how bad would it look if you move the callsite of this
> duplicate slash squashing down the callchain where the names are actually
> used?
I tried this, but I'm not sure it's better now (and there might be some
inconsistencies left). IMHO removing the double slashes is an operation
similar to the unquoting done in find_name(), i.e. converting the text
in the patch to something that can be passed to lstat() or
cache_name_lookup(). Anyway, new patch attached.
Michal
diff --git a/builtin-apply.c b/builtin-apply.c
index 8a3771e..5a35d9f 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -320,6 +320,22 @@ static int name_terminate(const char *name, int namelen, int c, int terminate)
return 1;
}
+/* remove double slashes to make --index work with such filenames */
+static char *squash_slash(char *name)
+{
+ int i = 0, j = 0;
+
+ if (!name)
+ return name;
+ while (name[i]) {
+ if ((name[j++] = name[i++]) == '/')
+ while (name[i] == '/')
+ i++;
+ }
+ name[j] = '\0';
+ return name;
+}
+
static char *find_name(const char *line, char *def, int p_value, int terminate)
{
int len;
@@ -423,6 +439,7 @@ static int guess_p_value(const char *nameline)
name = find_name(nameline, NULL, 0, TERM_SPACE | TERM_TAB);
if (!name)
return -1;
+ name = squash_slash(name);
cp = strchr(name, '/');
if (!cp)
val = 0;
@@ -2416,7 +2433,7 @@ static int verify_index_match(struct cache_entry *ce, struct stat *st)
static int check_preimage(struct patch *patch, struct cache_entry **ce, struct stat *st)
{
- const char *old_name = patch->old_name;
+ const char *old_name = squash_slash(patch->old_name);
struct patch *tpatch = NULL;
int stat_ret = 0;
unsigned st_mode = 0;
@@ -2503,8 +2520,8 @@ static int check_preimage(struct patch *patch, struct cache_entry **ce, struct s
static int check_patch(struct patch *patch)
{
struct stat st;
- const char *old_name = patch->old_name;
- const char *new_name = patch->new_name;
+ const char *old_name = squash_slash(patch->old_name);
+ const char *new_name = squash_slash(patch->new_name);
const char *name = old_name ? old_name : new_name;
struct cache_entry *ce = NULL;
struct patch *tpatch;
--
1.6.3
next prev parent reply other threads:[~2009-05-21 19:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-21 12:25 [PATCH] apply: handle filenames with double slashes better Michal Marek
2009-05-21 14:56 ` Junio C Hamano
2009-05-21 19:12 ` Michal Marek [this message]
2009-05-21 19:22 ` Junio C Hamano
2009-05-25 9:11 ` Michal Marek
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=20090521191204.GA29362@sepie.suse.cz \
--to=mmarek@suse.cz \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).