From: Shawn Bohrer <shawn.bohrer@gmail.com>
To: Junio C Hamano <gitster@pobox.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 12:06:43 -0500 [thread overview]
Message-ID: <20080414170643.GA10548@mediacenter> (raw)
In-Reply-To: <7v8wzgaoqy.fsf@gitster.siamese.dyndns.org>
On Mon, Apr 14, 2008 at 12:18:13AM -0700, Junio C Hamano wrote:
> Shawn Bohrer <shawn.bohrer@gmail.com> writes:
> > - 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?
Yes this is an independent clean-up. I can't see any harm in forcing
the initializtion.
> > - 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.
Yep, I'll add that to the changelog.
> > - 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.
Agreed I'll send an updated patch later tonight. One additional thought
though. 2 is MATCHED_FNMATCH which worries me a little because I think
this would mean 'git clean -f *' will also remove directories (I haven't
tried though). Perhaps this should really be 3 MATCHED_EXACTLY just to
be safe. Does anyone have opinions either way?
--
Shawn
next prev parent reply other threads:[~2008-04-14 17:09 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
2008-04-14 17:06 ` Shawn Bohrer [this message]
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=20080414170643.GA10548@mediacenter \
--to=shawn.bohrer@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jobh@broadpark.no \
/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).