git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/2] builtin-prune.c: fix object parsing and use parse_options()
@ 2008-03-23 20:50 Michele Ballabio
  2008-03-23 22:21 ` Johannes Schindelin
  0 siblings, 1 reply; 22+ messages in thread
From: Michele Ballabio @ 2008-03-23 20:50 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

git-prune used to remove loose objects whether they were specified in
the command line or not. This patch makes git-prune behave as stated
in the manpage: it does not prune any listed head nor reachable objects;
the parsing machinery now uses parse_options().

Signed-off-by: Michele Ballabio <barra_cuda@katamail.com>
---
 builtin-prune.c  |   50 ++++++++++++++++++++++++++++++--------------------
 t/t5304-prune.sh |    2 +-
 2 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/builtin-prune.c b/builtin-prune.c
index bb8ead9..7b3e15d 100644
--- a/builtin-prune.c
+++ b/builtin-prune.c
@@ -4,8 +4,12 @@
 #include "revision.h"
 #include "builtin.h"
 #include "reachable.h"
+#include "parse-options.h"
 
-static const char prune_usage[] = "git-prune [-n]";
+static const char * const prune_usage[] = {
+	"git-prune [-n] [--expire <time>] [--] [<head>...]",
+	NULL
+};
 static int show_only;
 static unsigned long expire;
 
@@ -121,32 +125,38 @@ static void remove_temporary_files(void)
 	closedir(dir);
 }
 
+static int parse_opt_expire(const struct option *opt, const char *arg,
+		int unset)
+{
+	expire = approxidate(arg);
+	return 0;
+}
+
 int cmd_prune(int argc, const char **argv, const char *prefix)
 {
-	int i;
 	struct rev_info revs;
 
-	for (i = 1; i < argc; i++) {
-		const char *arg = argv[i];
-		if (!strcmp(arg, "-n")) {
-			show_only = 1;
-			continue;
-		}
-		if (!strcmp(arg, "--expire")) {
-			if (++i < argc) {
-				expire = approxidate(argv[i]);
-				continue;
-			}
-		}
-		else if (!prefixcmp(arg, "--expire=")) {
-			expire = approxidate(arg + 9);
-			continue;
-		}
-		usage(prune_usage);
-	}
+	const struct option options[] = {
+		OPT_BOOLEAN('n', NULL, &show_only,
+				"do not remove, show only"),
+		OPT_CALLBACK(0, "expire", &expire, "time",
+				"expire objects older than <time>",
+				parse_opt_expire),
+		OPT_END()
+	};
+
+	argc = parse_options(argc, argv, options, prune_usage,
+			PARSE_OPT_STOP_AT_NON_OPTION |
+			PARSE_OPT_KEEP_DASHDASH);
 
 	save_commit_buffer = 0;
 	init_revisions(&revs, prefix);
+
+	if (argc > 1)
+		argc = setup_revisions(argc, argv, &revs, NULL);
+	if (argc > 1)
+		die ("unrecognized argument: %s", argv[1]);
+
 	mark_reachable_objects(&revs, 1);
 
 	prune_object_dir(get_object_directory());
diff --git a/t/t5304-prune.sh b/t/t5304-prune.sh
index d5f12f7..0638297 100644
--- a/t/t5304-prune.sh
+++ b/t/t5304-prune.sh
@@ -92,7 +92,7 @@ test_expect_success 'prune: prune unreachable heads' '
 
 '
 
-test_expect_failure 'prune: do not prune heads listed as an argument' '
+test_expect_success 'prune: do not prune heads listed as an argument' '
 
 	: > file2 &&
 	git add file2 &&
-- 
1.5.4.3

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

end of thread, other threads:[~2008-03-27 21:02 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-23 20:50 [PATCH 2/2] builtin-prune.c: fix object parsing and use parse_options() Michele Ballabio
2008-03-23 22:21 ` Johannes Schindelin
2008-03-24 12:31   ` Michele Ballabio
2008-03-24 13:13     ` Johannes Schindelin
2008-03-24 14:02       ` [PATCH 3/2] parse-options.c: introduce OPT_DATE Michele Ballabio
2008-03-24 13:59         ` Johannes Schindelin
2008-03-24 16:25         ` Michele Ballabio
2008-03-24 20:03           ` Johannes Schindelin
2008-03-24 20:10         ` Junio C Hamano
2008-03-24 21:18           ` Michele Ballabio
2008-03-25  6:58             ` Junio C Hamano
2008-03-25  6:59             ` [PATCH 1/5] " Junio C Hamano
2008-03-25  6:59             ` [PATCH 2/5] test_must_fail: 129 is a valid error code from usage() Junio C Hamano
2008-03-25 10:01               ` Johannes Schindelin
2008-03-25 11:21                 ` Johannes Sixt
2008-03-25 19:27                   ` Johannes Schindelin
2008-03-25  6:59             ` [PATCH 3/5] Add tests for git-prune Junio C Hamano
2008-03-25  6:59             ` [PATCH 4/5] builtin-prune.c: use parse_options() Junio C Hamano
2008-03-25  6:59             ` [PATCH 5/5] builtin-prune: protect objects listed on the command line Junio C Hamano
2008-03-27 16:32               ` Junio C Hamano
2008-03-27 16:35                 ` Johannes Schindelin
2008-03-27 21:11                   ` Michele Ballabio

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