git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git clean: Don't automatically remove directories when run within subdirectory

From
Shawn Bohrer <shawn.bohrer@gmail.com>
Date
Apr 14, 2008, 17:06 UTC
Message-ID
<20080414170643.GA10548@mediacenter>
In-Reply-To
<7v8wzgaoqy.fsf@gitster.siamese.dyndns.org>
On Mon, Apr 14, 2008 at 12:18:13AM -0700, Junio C Hamano wrote:
Show 10 quoted lines
> 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.

Show 10 quoted lines
> > -			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.
Show 7 quoted lines
> > -			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

Previous: Junio C HamanoNext: Joachim Berdal Haga
Message 8 of 14 in “git clean removes directories when not asked to”
  1. Joachim B HagaApr 8, 2008
  2. Joachim B HagaApr 8, 2008
  3. Re: git clean removes directories when not asked toJoachim B Haga, Apr 9, 2008
  4. git clean: Don't automatically remove directories when run within subdirectoryShawn Bohrer, Apr 13, 2008
  5. git clean: Add test to verify directories aren't removed with a prefixShawn Bohrer, Apr 13, 2008
  6. Joachim Berdal HagaApr 14, 2008
  7. Junio C HamanoApr 14, 2008
  8. Shawn BohrerApr 14, 2008
  9. Joachim Berdal HagaApr 14, 2008
  10. Shawn BohrerApr 15, 2008
  11. Joachim Berdal HagaApr 15, 2008
  12. Shawn BohrerApr 15, 2008
  13. Joachim Berdal HagaApr 15, 2008
  14. git clean: Don't automatically remove directories when run within subdirectoryShawn Bohrer, Apr 15, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.