{"thread":{"id":"11137","subject":"[BUG] \"git clean\" does not pay attention to its parameters","startedAt":"2007-12-05T06:54:06Z","lastAt":"2007-12-06T03:28:06Z","messageCount":9,"participants":["Nanako Shiraishi","Junio C Hamano","Johannes Schindelin","Sam Ravnborg","Shawn Bohrer","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"61970","messageId":"200712050654.lB56scKk000311@mi0.bluebottle.com","threadId":"11137","inReplyTo":null,"subject":"[BUG] \"git clean\" does not pay attention to its parameters","fromName":"Nanako Shiraishi","fromEmail":"nanako3@bluebottle.com","sentAt":"2007-12-05T06:54:06Z","receivedAt":"2007-12-05T06:54:06Z","isPatch":false,"sender":{"key":"nanako3@lavabit.com","avatar":"https://gravatar.com/avatar/3777b9e201c5883a62b1a6fdf7c53f2d712d1d80989146063ea861e33aad72a8?d=mp&s=160"},"body":"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):\n\n  % git clean -n '*.aux'\n\nThis 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.\n\n----------------------------------------------------------------------\nGet a free email account with anti spam protection.\nhttp://www.bluebottle.com/tag/2\n"},{"id":"61980","messageId":"7veje1zibm.fsf@gitster.siamese.dyndns.org","threadId":"11137","inReplyTo":"200712050654.lB56scKk000311@mi0.bluebottle.com","subject":"Re:* [BUG] \"git clean\" does not pay attention to its parameters","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-05T07:55:41Z","receivedAt":"2007-12-05T07:55:41Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nanako Shiraishi <nanako3@bluebottle.com> writes:\n\n> 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):\n>\n>   % git clean -n '*.aux'\n>\n> 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.\n\nYuck.  People actually use git-clean?\n\nBut thanks for reporting.\n\nComparing the corresponding part from builtin-ls-files.c and what\nbuiltin-clean.c does, it does look broken.\n\nDoes this patch help?  I am not sure why the directory side of the code\nis written that way, but I have a suspicion that \"was a directory\nexplicitly given as one of the pathspec\" check is also bogus, although I\ndid not touch that part.\n\n-- >8 --\n[PATCH] git-clean: Honor pathspec.\n\ngit-clean \"*.rej\" should attempt to look at only paths that match\npattern \"*.rej\", but rewrite to C broke it.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin-clean.c |   31 ++++++++++++++++++++-----------\n 1 files changed, 20 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin-clean.c b/builtin-clean.c\nindex 56ae4eb..7dd901e 100644\n--- a/builtin-clean.c\n+++ b/builtin-clean.c\n@@ -27,13 +27,14 @@ static int git_clean_config(const char *var, const char *value)\n \n int cmd_clean(int argc, const char **argv, const char *prefix)\n {\n-\tint j;\n+\tint i;\n \tint show_only = 0, remove_directories = 0, quiet = 0, ignored = 0;\n \tint ignored_only = 0, baselen = 0, config_set = 0;\n \tstruct strbuf directory;\n \tstruct dir_struct dir;\n \tconst char *path, *base;\n \tstatic const char **pathspec;\n+\tchar *seen = NULL;\n \tstruct option options[] = {\n \t\tOPT__QUIET(&quiet),\n \t\tOPT__DRY_RUN(&show_only),\n@@ -85,12 +86,17 @@ int cmd_clean(int argc, const char **argv, const char *prefix)\n \tread_directory(&dir, path, base, baselen, pathspec);\n \tstrbuf_init(&directory, 0);\n \n-\tfor (j = 0; j < dir.nr; ++j) {\n-\t\tstruct dir_entry *ent = dir.entries[j];\n-\t\tint len, pos, specs;\n+\tif (pathspec) {\n+\t\tfor (i = 0; pathspec[i]; i++)\n+\t\t\t; /* nothing */\n+\t\tseen = xmalloc();\n+\t}\n+\n+\tfor (i = 0; i < dir.nr; i++) {\n+\t\tstruct dir_entry *ent = dir.entries[i];\n+\t\tint len, pos;\n \t\tstruct cache_entry *ce;\n \t\tstruct stat st;\n-\t\tchar *seen;\n \n \t\t/*\n \t\t * Remove the '/' at the end that directory\n@@ -114,15 +120,13 @@ int cmd_clean(int argc, const char **argv, const char *prefix)\n \t\t\tint matched_path = 0;\n \t\t\tstrbuf_addstr(&directory, ent->name);\n \t\t\tif (pathspec) {\n-\t\t\t\tfor (specs =0; pathspec[specs]; ++specs)\n-\t\t\t\t\t/* nothing */;\n-\t\t\t\tseen = xcalloc(specs, 1);\n-\t\t\t\t/* Check if directory was explictly passed as\n-\t\t\t\t * pathspec.  If so we want to remove it */\n+\t\t\t\t/*\n+\t\t\t\t * Check if directory was explictly passed as\n+\t\t\t\t * pathspec. If so we want to remove it.\n+\t\t\t\t */\n \t\t\t\tif (match_pathspec(pathspec, ent->name, ent->len,\n \t\t\t\t\t\t   baselen, seen))\n \t\t\t\t\tmatched_path = 1;\n-\t\t\t\tfree(seen);\n \t\t\t}\n \t\t\tif (show_only && (remove_directories || matched_path)) {\n \t\t\t\tprintf(\"Would remove %s\\n\", directory.buf);\n@@ -138,6 +142,10 @@ int cmd_clean(int argc, const char **argv, const char *prefix)\n \t\t\t}\n \t\t\tstrbuf_reset(&directory);\n \t\t} else {\n+\t\t\tif (pathspec &&\n+\t\t\t    !match_pathspec(pathspec, ent->name, ent->len,\n+\t\t\t\t\t    baselen, seen))\n+\t\t\t\tcontinue; /* excluded */\n \t\t\tif (show_only) {\n \t\t\t\tprintf(\"Would remove %s\\n\", ent->name);\n \t\t\t\tcontinue;\n@@ -147,6 +155,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)\n \t\t\tunlink(ent->name);\n \t\t}\n \t}\n+\tfree(seen);\n \n \tstrbuf_release(&directory);\n \treturn 0;\n-- \n1.5.3.7-2115-geb804\n"},{"id":"61990","messageId":"Pine.LNX.4.64.0712050947370.27959@racer.site","threadId":"11137","inReplyTo":"7veje1zibm.fsf@gitster.siamese.dyndns.org","subject":"Re:* [BUG] \"git clean\" does not pay attention to its parameters","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-12-05T09:49:38Z","receivedAt":"2007-12-05T09:49:38Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 4 Dec 2007, Junio C Hamano wrote:\n\n> @@ -85,12 +86,17 @@ int cmd_clean(int argc, const char **argv, const char *prefix)\n>  \tread_directory(&dir, path, base, baselen, pathspec);\n>  \tstrbuf_init(&directory, 0);\n>  \n> -\tfor (j = 0; j < dir.nr; ++j) {\n> -\t\tstruct dir_entry *ent = dir.entries[j];\n> -\t\tint len, pos, specs;\n> +\tif (pathspec) {\n> +\t\tfor (i = 0; pathspec[i]; i++)\n> +\t\t\t; /* nothing */\n> +\t\tseen = xmalloc();\n\nDid you mean xmalloc(i)?\n\nCiao,\nDscho\n"},{"id":"61991","messageId":"7vve7dwix3.fsf@gitster.siamese.dyndns.org","threadId":"11137","inReplyTo":"Pine.LNX.4.64.0712050947370.27959@racer.site","subject":"Re: * [BUG] \"git clean\" does not pay attention to its parameters","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-05T10:11:04Z","receivedAt":"2007-12-05T10:11:04Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> Hi,\n>\n> On Tue, 4 Dec 2007, Junio C Hamano wrote:\n>\n>> @@ -85,12 +86,17 @@ int cmd_clean(int argc, const char **argv, const char *prefix)\n>>  \tread_directory(&dir, path, base, baselen, pathspec);\n>>  \tstrbuf_init(&directory, 0);\n>>  \n>> -\tfor (j = 0; j < dir.nr; ++j) {\n>> -\t\tstruct dir_entry *ent = dir.entries[j];\n>> -\t\tint len, pos, specs;\n>> +\tif (pathspec) {\n>> +\t\tfor (i = 0; pathspec[i]; i++)\n>> +\t\t\t; /* nothing */\n>> +\t\tseen = xmalloc();\n>\n> Did you mean xmalloc(i)?\n\nYes.\n"},{"id":"61997","messageId":"20071205105005.GA6961@uranus.ravnborg.org","threadId":"11137","inReplyTo":"7veje1zibm.fsf@gitster.siamese.dyndns.org","subject":"Re: * [BUG] \"git clean\" does not pay attention to its parameters","fromName":"Sam Ravnborg","fromEmail":"sam@ravnborg.org","sentAt":"2007-12-05T10:50:05Z","receivedAt":"2007-12-05T10:50:05Z","isPatch":false,"sender":{"key":"sam@ravnborg.org","avatar":"https://gravatar.com/avatar/168a912606ed0742d840bb365e3cc21db390c36531a58341dc7a069cc1f15f62?d=mp&s=160"},"body":"On Tue, Dec 04, 2007 at 11:55:41PM -0800, Junio C Hamano wrote:\n> Nanako Shiraishi <nanako3@bluebottle.com> writes:\n> \n> > 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):\n> >\n> >   % git clean -n '*.aux'\n> >\n> > 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.\n> \n> Yuck.  People actually use git-clean?\n\ngit clean -d -x is my friend.\nIt it a great way to delete all my temporary files named 'kurt', 'fisk', 'viggo', 'x*' etc.\n\n\tSam\n"},{"id":"62019","messageId":"20071205152816.GA21347@mediacenter.austin.rr.com","threadId":"11137","inReplyTo":"7veje1zibm.fsf@gitster.siamese.dyndns.org","subject":"Re: * [BUG] \"git clean\" does not pay attention to its parameters","fromName":"Shawn Bohrer","fromEmail":"shawn.bohrer@gmail.com","sentAt":"2007-12-05T15:28:16Z","receivedAt":"2007-12-05T15:28:16Z","isPatch":false,"sender":{"key":"shawn.bohrer@gmail.com","avatar":"https://gravatar.com/avatar/6eb093ef7d276306d18366254e0c95ff6a5db58231ac7e82fe78c2800aaae1b6?d=mp&s=160"},"body":"On Tue, Dec 04, 2007 at 11:55:41PM -0800, Junio C Hamano wrote:\n> Does this patch help?  I am not sure why the directory side of the code\n> is written that way, but I have a suspicion that \"was a directory\n> explicitly given as one of the pathspec\" check is also bogus, although I\n> did not touch that part.\n\nBefore the rewrite in C git clean would refuse to remove a directory if\nyou said:\n\n   git clean dir\n\nwithout using the -d parameter.  Per your suggestion this check causes\ngit clean to remove the directory anyway since you explicitly asked it\nto.\n"},{"id":"62032","messageId":"20071205180356.GA5181@coredump.intra.peff.net","threadId":"11137","inReplyTo":"7veje1zibm.fsf@gitster.siamese.dyndns.org","subject":"Re: * [BUG] \"git clean\" does not pay attention to its parameters","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-12-05T18:03:56Z","receivedAt":"2007-12-05T18:03:56Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Dec 04, 2007 at 11:55:41PM -0800, Junio C Hamano wrote:\n\n> Yuck.  People actually use git-clean?\n\nI use it all the time (though never with arguments, or I probably would\nhave noticed this bug). I think it is coupled with the \"use git status\nto see what is going on\" workflow that, IIRC, you don't use.\n\nAlso, nit: don't you mean \"git clean\"? :)\n\n-Peff\n"},{"id":"62081","messageId":"7vbq94in6m.fsf@gitster.siamese.dyndns.org","threadId":"11137","inReplyTo":"20071205152816.GA21347@mediacenter.austin.rr.com","subject":"Re: * [BUG] \"git clean\" does not pay attention to its parameters","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-06T02:14:57Z","receivedAt":"2007-12-06T02:14:57Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Shawn Bohrer <shawn.bohrer@gmail.com> writes:\n\n> Before the rewrite in C git clean would refuse to remove a directory if\n> you said:\n>\n>    git clean dir\n>\n> without using the -d parameter.  Per your suggestion this check causes\n> git clean to remove the directory anyway since you explicitly asked it\n> to.\n\nThanks for reminding me of that issue.\n"},{"id":"62087","messageId":"20071206032806.GB5499@coredump.intra.peff.net","threadId":"11137","inReplyTo":"7veje1zibm.fsf@gitster.siamese.dyndns.org","subject":"Re: * [BUG] \"git clean\" does not pay attention to its parameters","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-12-06T03:28:06Z","receivedAt":"2007-12-06T03:28:06Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Dec 04, 2007 at 11:55:41PM -0800, Junio C Hamano wrote:\n\n> [PATCH] git-clean: Honor pathspec.\n> \n> git-clean \"*.rej\" should attempt to look at only paths that match\n> pattern \"*.rej\", but rewrite to C broke it.\n\nAnd here is a test that fails without your patch (probably the commit\nmessage should say \"fixed in XX\" once the commit id is known, or it\nshould be squashed in with your patch).\n\n-- >8 --\nt7300: add test for clean with wildcard pathspec\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n t/t7300-clean.sh |   14 ++++++++++++++\n 1 files changed, 14 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t7300-clean.sh b/t/t7300-clean.sh\nindex f013c17..dfd1188 100755\n--- a/t/t7300-clean.sh\n+++ b/t/t7300-clean.sh\n@@ -126,6 +126,20 @@ test_expect_success 'git-clean symbolic link' '\n \n '\n \n+test_expect_success 'git-clean with wildcard' '\n+\n+\ttouch a.clean b.clean other.c &&\n+\tgit-clean \"*.clean\" &&\n+\ttest -f Makefile &&\n+\ttest -f README &&\n+\ttest -f src/part1.c &&\n+\ttest -f src/part2.c &&\n+\ttest ! -f a.clean &&\n+\ttest ! -f b.clean &&\n+\ttest -f other.c\n+\n+'\n+\n test_expect_success 'git-clean -n' '\n \n \tmkdir -p build docs &&\n-- \n1.5.3.7.2099.gd6d7-dirty\n"}]}