git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Add -e/--exclude to git-clean.
@ 2010-07-20 19:35 Jared Hance
  2010-07-20 19:35 ` [PATCH 1/2] " Jared Hance
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Jared Hance @ 2010-07-20 19:35 UTC (permalink / raw)
  To: git; +Cc: gitster

Changes:
    - Use -e multiple times instead of using a separator

I'm starting a new thread since the code change is rather major. I've
incorporated Julio's changes, touched up on them a bit, and updated
the test suite so that it uses multiple instances of -e rather than 
using a separator in them.

Thanks to Julio and all that helped.

Jared Hance (2):
  Add -e/--exclude to git-clean.
  Add test for git clean -e.

 Documentation/git-clean.txt |    8 +++++++-
 builtin/clean.c             |   17 ++++++++++++++++-
 t/t7300-clean.sh            |   16 ++++++++++++++++
 3 files changed, 39 insertions(+), 2 deletions(-)

^ permalink raw reply	[flat|nested] 8+ messages in thread
* [PATCH v3] Add --exclude to git-clean.
@ 2010-07-19 18:39 Jared Hance
  2010-07-20 16:28 ` [PATCH/RFC v4 0/2] Add -e/--exclude to git clean Jared Hance
  0 siblings, 1 reply; 8+ messages in thread
From: Jared Hance @ 2010-07-19 18:39 UTC (permalink / raw)
  To: git

With the -e/--exclude option for git-clean, a user can specify files
that they haven't yet told git about, but either need for a short amount
of time or plan to tell git about them later. This allows one to still
use git-clean while these files are around without losing data.

Signed-off-by: Jared Hance <jaredhance@gmail.com>
---
 Documentation/git-clean.txt |    7 ++++++-
 builtin/clean.c             |   21 +++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/Documentation/git-clean.txt b/Documentation/git-clean.txt
index a81cb6c..488e103 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] [-x | -X] [--] <path>...
+'git clean' [-d] [-f] [-n] [-q] [-e] [-x | -X] [--] <path>...
 
 DESCRIPTION
 -----------
@@ -45,6 +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.
+
 -x::
 	Don't use the ignore rules.  This allows removing all untracked
 	files, including build products.  This can be used (possibly in
diff --git a/builtin/clean.c b/builtin/clean.c
index fac64e6..b1da923 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -13,6 +13,7 @@
 #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>...",
@@ -36,6 +37,8 @@ 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;
 	const char *qname;
 	char *seen = NULL;
 	struct option options[] = {
@@ -44,6 +47,7 @@ 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"),
 		OPT_BOOLEAN('x', NULL, &ignored, "remove ignored files, too"),
 		OPT_BOOLEAN('X', NULL, &ignored_only,
 				"remove only ignored files"),
@@ -81,6 +85,17 @@ 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);
+		}
+	}
+
 	pathspec = get_pathspec(prefix, argv);
 
 	fill_directory(&dir, pathspec);
@@ -167,5 +182,11 @@ 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]);
+		}
+	}
 	return (errors != 0);
 }
-- 
1.7.1.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-07-20 23:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-20 19:35 [PATCH 0/2] Add -e/--exclude to git-clean Jared Hance
2010-07-20 19:35 ` [PATCH 1/2] " Jared Hance
2010-07-20 20:27   ` Junio C Hamano
2010-07-20 19:36 ` [PATCH 2/2] Add test for git clean -e Jared Hance
2010-07-20 20:34   ` Junio C Hamano
2010-07-20 23:35     ` Jared Hance
2010-07-20 19:43 ` [PATCH 0/2] Add -e/--exclude to git-clean Jared Hance
  -- strict thread matches above, loose matches on Subject: below --
2010-07-19 18:39 [PATCH v3] Add --exclude " Jared Hance
2010-07-20 16:28 ` [PATCH/RFC v4 0/2] Add -e/--exclude to git clean Jared Hance
2010-07-20 16:30   ` [PATCH 2/2] Add test for git clean -e Jared Hance

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).