From: Junio C Hamano <gitster@pobox.com>
To: Shawn Bohrer <shawn.bohrer@gmail.com>
Cc: jobh@broadpark.no, git@vger.kernel.org
Subject: Re: [PATCH] git clean: Don't automatically remove directories when run within subdirectory
Date: Mon, 14 Apr 2008 00:18:13 -0700 [thread overview]
Message-ID: <7v8wzgaoqy.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <1208130578-24748-1-git-send-email-shawn.bohrer@gmail.com> (Shawn Bohrer's message of "Sun, 13 Apr 2008 18:49:37 -0500")
Shawn Bohrer <shawn.bohrer@gmail.com> writes:
> diff --git a/builtin-clean.c b/builtin-clean.c
> index fefec30..5c5ec98 100644
> --- a/builtin-clean.c
> +++ b/builtin-clean.c
> @@ -95,7 +95,8 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
>
> for (i = 0; i < dir.nr; i++) {
> struct dir_entry *ent = dir.entries[i];
> - int len, pos, matches;
> + int len, pos;
> + int matches = 0;
> struct cache_entry *ce;
> struct stat st;
Initialization of "matches" seems to be an independent clean-up. Although
it forces the initialization in the codepath that do not need the value of
matches, that is not a big deal --- right?
> @@ -127,18 +128,16 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
>
> if (pathspec) {
> memset(seen, 0, argc > 0 ? argc : 1);
> - matches = match_pathspec(pathspec, ent->name, ent->len,
> + matches = match_pathspec(pathspec, ent->name, len,
> baselen, seen);
> - } else {
> - matches = 0;
> }
And the essential change (fix) is to send len which could be shorter than
ent->len because we have stripped '/' here, plus the one in match_one()
that now allows name[] that is not NUL terminated.
> if (S_ISDIR(st.st_mode)) {
> strbuf_addstr(&directory, ent->name);
> qname = quote_path_relative(directory.buf, directory.len, &buf, prefix);
> - if (show_only && (remove_directories || matches)) {
> + if (show_only && (remove_directories || (matches >= 2))) {
> printf("Would remove %s\n", qname);
> - } else if (remove_directories || matches) {
> + } else if (remove_directories || (matches >= 2)) {
These magic numbers are bad. Please update it to use symbolic constants.
> if (!quiet)
> printf("Removing %s\n", qname);
> if (remove_dir_recursively(&directory, 0) != 0) {
> diff --git a/dir.c b/dir.c
> index b5bfbca..63715c9 100644
> --- a/dir.c
> +++ b/dir.c
> @@ -80,7 +80,7 @@ static int match_one(const char *match, const char *name, int namelen)
> if (strncmp(match, name, matchlen))
> return !fnmatch(match, name, 0) ? MATCHED_FNMATCH : 0;
>
> - if (!name[matchlen])
> + if (namelen == matchlen)
> return MATCHED_EXACTLY;
> if (match[matchlen-1] == '/' || name[matchlen] == '/')
> return MATCHED_RECURSIVELY;
next prev parent reply other threads:[~2008-04-14 7:19 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-08 18:22 git clean removes directories when not asked to Joachim B Haga
2008-04-08 18:38 ` Joachim B Haga
2008-04-09 17:04 ` [PATCH] " Joachim B Haga
2008-04-13 23:49 ` [PATCH] git clean: Don't automatically remove directories when run within subdirectory Shawn Bohrer
2008-04-13 23:49 ` [PATCH] git clean: Add test to verify directories aren't removed with a prefix Shawn Bohrer
2008-04-14 7:03 ` [PATCH] git clean: Don't automatically remove directories when run within subdirectory Joachim Berdal Haga
2008-04-14 7:18 ` Junio C Hamano [this message]
2008-04-14 17:06 ` Shawn Bohrer
2008-04-14 18:18 ` Joachim Berdal Haga
2008-04-15 3:44 ` Shawn Bohrer
2008-04-15 6:33 ` Joachim Berdal Haga
2008-04-15 14:26 ` Shawn Bohrer
2008-04-15 14:46 ` Joachim Berdal Haga
2008-04-15 3:14 ` Shawn Bohrer
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=7v8wzgaoqy.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=jobh@broadpark.no \
--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).