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

[PATCH 4/5] builtin-prune.c: use parse_options()

From
Junio C Hamano <junio@pobox.com>
Date
Mar 25, 2008, 06:59 UTC
Message-ID
<7vzlsnmgps.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<200803242218.44026.barra_cuda@katamail.com>
From: Michele Ballabio <barra_cuda@katamail.com>
Date: Sun, 23 Mar 2008 21:50:29 +0100

Using the OPT_DATE() introduced earlier, this updates builtin-prune to use parse_options().

Signed-off-by: Michele Ballabio <barra_cuda@katamail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-prune.c |   38 ++++++++++++++++----------------------
 1 files changed, 16 insertions(+), 22 deletions(-)
diff --git a/builtin-prune.c b/builtin-prune.c
index bb8ead9..71caac5 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;
 
@@ -123,32 +127,22 @@ static void remove_temporary_files(void)
 
 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_DATE(0, "expire", &expire,
+			 "expire objects older than <time>"),
+		OPT_END()
+	};
 
 	save_commit_buffer = 0;
 	init_revisions(&revs, prefix);
-	mark_reachable_objects(&revs, 1);
 
+	argc = parse_options(argc, argv, options, prune_usage, 0);
+	if (argc)
+		die ("unrecognized argument: %s", name);
+	mark_reachable_objects(&revs, 1);
 	prune_object_dir(get_object_directory());
 
 	sync();
-- 
1.5.5.rc1.121.g1594
Previous: Junio C HamanoNext: Junio C Hamano
Message 18 of 22 in “builtin-prune.c: fix object parsing and use parse_options()”
  1. 2/2 builtin-prune.c: fix object parsing and use parse_options()Michele Ballabio, Mar 23, 2008
  2. Johannes SchindelinMar 23, 2008
  3. Michele BallabioMar 24, 2008
  4. Johannes SchindelinMar 24, 2008
  5. 3/2 parse-options.c: introduce OPT_DATEMichele Ballabio, Mar 24, 2008
  6. Johannes SchindelinMar 24, 2008
  7. Michele BallabioMar 24, 2008
  8. Johannes SchindelinMar 24, 2008
  9. Junio C HamanoMar 24, 2008
  10. Michele BallabioMar 24, 2008
  11. Junio C HamanoMar 25, 2008
  12. 1/5 parse-options.c: introduce OPT_DATEJunio C Hamano, Mar 25, 2008
  13. 2/5 test_must_fail: 129 is a valid error code from usage()Junio C Hamano, Mar 25, 2008
  14. Johannes SchindelinMar 25, 2008
  15. Johannes SixtMar 25, 2008
  16. Johannes SchindelinMar 25, 2008
  17. 3/5 Add tests for git-pruneJunio C Hamano, Mar 25, 2008
  18. 4/5 builtin-prune.c: use parse_options()Junio C Hamano, Mar 25, 2008
  19. 5/5 builtin-prune: protect objects listed on the command lineJunio C Hamano, Mar 25, 2008
  20. Junio C HamanoMar 27, 2008
  21. Johannes SchindelinMar 27, 2008
  22. Michele BallabioMar 27, 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.