From: Alex Riesen <raa.lkml@gmail.com>
To: martin f krafft <madduck@madduck.net>
Cc: git discussion list <git@vger.kernel.org>,
439992-quiet@bugs.debian.org, Junio C Hamano <junkio@cox.net>
Subject: [PATCH] Remove duplicate pathspecs from ls-files command line
Date: Wed, 29 Aug 2007 21:44:10 +0200 [thread overview]
Message-ID: <20070829194410.GA11824@steel.home> (raw)
In-Reply-To: <20070829081122.GA604@piper.oerlikon.madduck.net>
The first entry wins, all the subsequent entries will be discarded.
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
martin f krafft, Wed, Aug 29, 2007 10:11:22 +0200:
> when using git-add from a script, the following fails:
>
> $ git commit -m. foo foo
> error: pathspec 'foo' did not match any file(s) known to git.
> Did you forget to 'git add'?
>
> I am bringing this up in the context of
> http://bugs.debian.org/439992, where debcommit.pl would duplicate
> a file argument under certain conditions. It's since been fixed, but
> I wonder whether git-commit could be made more robust in the
> presence of duplicate arguments? Or is this behaviour by choice?
>
Don't think so. Looks like accident. The patch below fixes it,
by introducing a costly argument duplication check. Shouldn't
be a problem for a normal use (git-ls-files expects globs, not
pathnames).
setup.c | 21 +++++++++++++++++----
1 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/setup.c b/setup.c
index 06004f1..b13b628 100644
--- a/setup.c
+++ b/setup.c
@@ -111,10 +111,19 @@ void verify_non_filename(const char *prefix, const char *arg)
die("'%s': %s", arg, strerror(errno));
}
+static const char **has_pathspec(const char **start, const char **end, const char *spec)
+{
+ const char **p;
+ for (p = start; p != end; ++p)
+ if (!strcmp(*p, spec))
+ return p;
+ return NULL;
+}
+
const char **get_pathspec(const char *prefix, const char **pathspec)
{
const char *entry = *pathspec;
- const char **p;
+ const char **in, **out;
int prefixlen;
if (!prefix && !entry)
@@ -128,11 +137,15 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
}
/* Otherwise we have to re-write the entries.. */
- p = pathspec;
+ in = out = pathspec;
prefixlen = prefix ? strlen(prefix) : 0;
do {
- *p = prefix_path(prefix, prefixlen, entry);
- } while ((entry = *++p) != NULL);
+ const char *spec = prefix_path(prefix, prefixlen, entry);
+ if (!has_pathspec(pathspec, out, spec))
+ *out++ = spec;
+ } while ((entry = *++in) != NULL);
+ if (in != out)
+ *out = NULL;
return (const char **) pathspec;
}
--
1.5.3.rc7.24.g0e57
next prev parent reply other threads:[~2007-08-29 19:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-29 8:11 double occurrence of filenames on command lines martin f krafft
2007-08-29 19:44 ` Alex Riesen [this message]
2007-08-29 20:44 ` [PATCH] Remove duplicate pathspecs from ls-files command line Junio C Hamano
2007-08-29 21:04 ` martin f krafft
2007-08-29 21:15 ` Alex Riesen
2007-08-29 21:36 ` David Kastrup
2007-08-30 1:25 ` Junio C Hamano
2007-08-30 5:52 ` David Kastrup
2007-08-29 20:57 ` martin f krafft
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=20070829194410.GA11824@steel.home \
--to=raa.lkml@gmail.com \
--cc=439992-quiet@bugs.debian.org \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
--cc=madduck@madduck.net \
/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