Re: [PATCH/RFC v4 0/2] Add -e/--exclude to git clean.

Subsystems: documentation, the rest

3 messages, 3 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH/RFC v4 0/2] Add -e/--exclude to git clean.

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:49:09

Junio C Hamano [off-list ref] writes:
Aaron Crane [off-list ref] writes:
quoted
Jared Hance [off-list ref] wrote:
quoted
This is the fourth round of patches for git clean -e.
Since this patch seems to be somewhat controversial, I've marked it as
PATCH/RFC. I would like some ideas on what to use for separators
Rather than stuffing multiple exclusions into a single option, how
about requiring one -e option per exclusion?

git clean -e foo -e bar
I find it a lot saner.

Sorry, Jared, I should have thought of it and suggested it during the
first review round.
The fix-up should look something like this, on top of your patch.

Note that I did this on top of applying your patch to 'maint', and you may
need to adjust the parameter order of string-list functions if you want to
forward port it to 'master'.

Untested, of course ;-)


 Documentation/git-clean.txt |   11 ++++++-----
 builtin/clean.c             |   36 +++++++++++++++---------------------
 2 files changed, 21 insertions(+), 26 deletions(-)
diff --git a/Documentation/git-clean.txt b/Documentation/git-clean.txt
index 488e103..60e38e6 100644
--- a/Documentation/git-clean.txt
+++ b/Documentation/git-clean.txt
@@ -8,7 +8,7 @@ git-clean - Remove untracked files from the working tree
 SYNOPSIS
 --------
 [verse]
-'git clean' [-d] [-f] [-n] [-q] [-e] [-x | -X] [--] <path>...
+'git clean' [-d] [-f] [-n] [-q] [-e <pattern>] [-x | -X] [--] <path>...
 
 DESCRIPTION
 -----------
@@ -45,10 +45,11 @@ OPTIONS
 	Be quiet, only report errors, but not the files that are
 	successfully removed.
 
--e <files>::
---exclude=<files>::
-	Specify special exceptions to not be cleaned. Separate with a space.
-	Globs, like that in $GIT_DIR/info/excludes, should be used.
+-e <pattern>::
+--exclude=<pattern>::
+	Specify special exceptions to not be cleaned.  Each <pattern> is
+	the same form as in $GIT_DIR/info/excludes and this option can be
+	given multiple times.
 
 -x::
 	Don't use the ignore rules.  This allows removing all untracked
diff --git a/builtin/clean.c b/builtin/clean.c
index b1da923..58c9c06 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -10,13 +10,13 @@
 #include "cache.h"
 #include "dir.h"
 #include "parse-options.h"
+#include "string-list.h"
 #include "quote.h"
 
 static int force = -1; /* unset */
-static const char *excludes;
 
 static const char *const builtin_clean_usage[] = {
-	"git clean [-d] [-f] [-n] [-q] [-x | -X] [--] <paths>...",
+	"git clean [-d] [-f] [-n] [-q] [-e <pattern>] [-x | -X] [--] <paths>...",
 	NULL
 };
 
@@ -27,6 +27,13 @@ static int git_clean_config(const char *var, const char *value, void *cb)
 	return git_default_config(var, value, cb);
 }
 
+static int exclude_cb(const struct option *opt, const char *arg, int unset)
+{
+	struct string_list *exclude_list = opt->value;
+	string_list_append(arg, exclude_list);
+	return 0;
+}
+
 int cmd_clean(int argc, const char **argv, const char *prefix)
 {
 	int i;
@@ -37,8 +44,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
 	struct dir_struct dir;
 	static const char **pathspec;
 	struct strbuf buf = STRBUF_INIT;
-	struct strbuf excludes_buf = STRBUF_INIT;
-	struct strbuf **excludes_split = NULL;
+	struct string_list exclude_list = { NULL, 0, 0, 0 };
 	const char *qname;
 	char *seen = NULL;
 	struct option options[] = {
@@ -47,7 +53,8 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
 		OPT_BOOLEAN('f', "force", &force, "force"),
 		OPT_BOOLEAN('d', NULL, &remove_directories,
 				"remove whole directories"),
-		OPT_STRING('e', "exclude", &excludes, "EXCLUDES", "specify files not to clean"),
+		{ OPTION_CALLBACK, 'e', "exclude", &exclude_list, "pattern",
+		  "exclude <pattern>", PARSE_OPT_NONEG, exclude_cb },
 		OPT_BOOLEAN('x', NULL, &ignored, "remove ignored files, too"),
 		OPT_BOOLEAN('X', NULL, &ignored_only,
 				"remove only ignored files"),
@@ -85,16 +92,8 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
 	if (!ignored)
 		setup_standard_excludes(&dir);
 
-	if (excludes) {
-		strbuf_addstr(&excludes_buf, excludes);
-		excludes_split = strbuf_split(&excludes_buf, ' ');
-		for (i = 0; excludes_split[i]; i++) {
-			if (excludes_split[i]->buf[excludes_split[i]->len - 1] == ' ') {
-				strbuf_remove(excludes_split[i], excludes_split[i]->len - 1, 1);
-			}
-			add_exclude(excludes_split[i]->buf, "", 0, dir.exclude_list);
-		}
-	}
+	for (i = 0; i < exclude_list.nr; i++)
+		add_exclude(exclude_list.items[i].string, "", 0, dir.exclude_list);
 
 	pathspec = get_pathspec(prefix, argv);
 
@@ -182,11 +181,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
 	free(seen);
 
 	strbuf_release(&directory);
-	if (excludes) {
-		strbuf_release(&excludes_buf);
-		for (i = 0; excludes_split[i]; i++) {
-			strbuf_release(excludes_split[i]);
-		}
-	}
+	string_list_clear(&exclude_list, 0);
 	return (errors != 0);
 }

Re: [PATCH/RFC v4 0/2] Add -e/--exclude to git clean.

From: Jared Hance <hidden>
Date: 2016-06-15 22:49:09

On Tue, Jul 20, 2010 at 11:23:22AM -0700, Junio C Hamano wrote:
The fix-up should look something like this, on top of your patch.

Note that I did this on top of applying your patch to 'maint', and you may
need to adjust the parameter order of string-list functions if you want to
forward port it to 'master'.

Untested, of course ;-)
Okay. Do you want to me to create a rebased version to combine this
and my first patch?

Re: [PATCH/RFC v4 0/2] Add -e/--exclude to git clean.

From: Louis Strous <hidden>
Date: 2016-06-15 22:49:36

The git clean -e option is more useful than just for stuff that you plan to
bring under git control later.  It also allows to retain per-user configurations
of external tools when using git clean to remove all build results and
intermediate files.  This leads to the enhancement request described below.

Most IDEs (integrated development environments) allow the user to configure
various display and debugger options, and store those options in some
configuration file.  Such user option files should not be under git control in a
multi-user environment, because then all users are forced to use the same
options.  Yet these user option files should not be deleted when the rest of the
untracked files are deleted (through git clean), otherwise the user options are
lost.

git clean -x -d -f -e "pattern" removes all untracked files except those
matching the pattern.  However, it is cumbersome to specify these patterns every
time.  It would be more convenient if git clean would read such patterns from a
file similar to .gitignore (maybe .gitignoreclean?).  Then that file itself
could be put under git control and shared with the other developers.

I request implementation of this feature.

Best regards,

Louis Strous
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help