From: Junio C Hamano <gitster@pobox.com>
To: Nanako Shiraishi <nanako3@bluebottle.com>
Cc: Shawn Bohrer <shawn.bohrer@gmail.com>, git@vger.kernel.org
Subject: Re:* [BUG] "git clean" does not pay attention to its parameters
Date: Tue, 04 Dec 2007 23:55:41 -0800 [thread overview]
Message-ID: <7veje1zibm.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <200712050654.lB56scKk000311@mi0.bluebottle.com> (Nanako Shiraishi's message of "Wed, 5 Dec 2007 15:54:06 +0900")
Nanako Shiraishi <nanako3@bluebottle.com> writes:
> In a repository with LaTeX documents, I tried to see what *.aux files are left behind after formatting, by running "git clean -n" with the latest git (1.5.3.7-1005-gdada0c1):
>
> % git clean -n '*.aux'
>
> This however showed more than just '*.aux' files. With the released version 1.5.3.6, the output is correctly limited to the files that match the pattern.
Yuck. People actually use git-clean?
But thanks for reporting.
Comparing the corresponding part from builtin-ls-files.c and what
builtin-clean.c does, it does look broken.
Does this patch help? I am not sure why the directory side of the code
is written that way, but I have a suspicion that "was a directory
explicitly given as one of the pathspec" check is also bogus, although I
did not touch that part.
-- >8 --
[PATCH] git-clean: Honor pathspec.
git-clean "*.rej" should attempt to look at only paths that match
pattern "*.rej", but rewrite to C broke it.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin-clean.c | 31 ++++++++++++++++++++-----------
1 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/builtin-clean.c b/builtin-clean.c
index 56ae4eb..7dd901e 100644
--- a/builtin-clean.c
+++ b/builtin-clean.c
@@ -27,13 +27,14 @@ static int git_clean_config(const char *var, const char *value)
int cmd_clean(int argc, const char **argv, const char *prefix)
{
- int j;
+ int i;
int show_only = 0, remove_directories = 0, quiet = 0, ignored = 0;
int ignored_only = 0, baselen = 0, config_set = 0;
struct strbuf directory;
struct dir_struct dir;
const char *path, *base;
static const char **pathspec;
+ char *seen = NULL;
struct option options[] = {
OPT__QUIET(&quiet),
OPT__DRY_RUN(&show_only),
@@ -85,12 +86,17 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
read_directory(&dir, path, base, baselen, pathspec);
strbuf_init(&directory, 0);
- for (j = 0; j < dir.nr; ++j) {
- struct dir_entry *ent = dir.entries[j];
- int len, pos, specs;
+ if (pathspec) {
+ for (i = 0; pathspec[i]; i++)
+ ; /* nothing */
+ seen = xmalloc();
+ }
+
+ for (i = 0; i < dir.nr; i++) {
+ struct dir_entry *ent = dir.entries[i];
+ int len, pos;
struct cache_entry *ce;
struct stat st;
- char *seen;
/*
* Remove the '/' at the end that directory
@@ -114,15 +120,13 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
int matched_path = 0;
strbuf_addstr(&directory, ent->name);
if (pathspec) {
- for (specs =0; pathspec[specs]; ++specs)
- /* nothing */;
- seen = xcalloc(specs, 1);
- /* Check if directory was explictly passed as
- * pathspec. If so we want to remove it */
+ /*
+ * Check if directory was explictly passed as
+ * pathspec. If so we want to remove it.
+ */
if (match_pathspec(pathspec, ent->name, ent->len,
baselen, seen))
matched_path = 1;
- free(seen);
}
if (show_only && (remove_directories || matched_path)) {
printf("Would remove %s\n", directory.buf);
@@ -138,6 +142,10 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
}
strbuf_reset(&directory);
} else {
+ if (pathspec &&
+ !match_pathspec(pathspec, ent->name, ent->len,
+ baselen, seen))
+ continue; /* excluded */
if (show_only) {
printf("Would remove %s\n", ent->name);
continue;
@@ -147,6 +155,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
unlink(ent->name);
}
}
+ free(seen);
strbuf_release(&directory);
return 0;
--
1.5.3.7-2115-geb804
next prev parent reply other threads:[~2007-12-05 7:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-05 6:54 [BUG] "git clean" does not pay attention to its parameters Nanako Shiraishi
2007-12-05 7:55 ` Junio C Hamano [this message]
2007-12-05 9:49 ` Johannes Schindelin
2007-12-05 10:11 ` * " Junio C Hamano
2007-12-05 10:50 ` Sam Ravnborg
2007-12-05 15:28 ` Shawn Bohrer
2007-12-06 2:14 ` Junio C Hamano
2007-12-05 18:03 ` Jeff King
2007-12-06 3:28 ` Jeff King
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=7veje1zibm.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=nanako3@bluebottle.com \
--cc=shawn.bohrer@gmail.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).