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

[PATCH 4/4] prune-packed: migrate to parse-options

From
Stephen Boyd <bebarino@gmail.com>
Date
Jul 8, 2009, 05:15 UTC
Message-ID
<1247030141-11695-5-git-send-email-bebarino@gmail.com>
In-Reply-To
<1247030141-11695-4-git-send-email-bebarino@gmail.com>
Add --dry-run and --quiet to be more consistent with the rest of git.
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
---
 Documentation/git-prune-packed.txt |    4 +++-
 builtin-prune-packed.c             |   29 ++++++++++++-----------------
 2 files changed, 15 insertions(+), 18 deletions(-)
diff --git a/Documentation/git-prune-packed.txt b/Documentation/git-prune-packed.txt
index b5f26ce..abfc6b6 100644
--- a/Documentation/git-prune-packed.txt
+++ b/Documentation/git-prune-packed.txt
@@ -8,7 +8,7 @@ git-prune-packed - Remove extra objects that are already in pack files
 
 SYNOPSIS
 --------
-'git prune-packed' [-n] [-q]
+'git prune-packed' [-n|--dry-run] [-q|--quiet]
 
 
 DESCRIPTION
@@ -28,10 +28,12 @@ disk storage, etc.
 OPTIONS
 -------
 -n::
+--dry-run::
         Don't actually remove any objects, only show those that would have been
         removed.
 
 -q::
+--quiet::
 	Squelch the progress indicator.
 
 Author
diff --git a/builtin-prune-packed.c b/builtin-prune-packed.c
index 00590b1..be99eb0 100644
--- a/builtin-prune-packed.c
+++ b/builtin-prune-packed.c
@@ -1,9 +1,12 @@
 #include "builtin.h"
 #include "cache.h"
 #include "progress.h"
+#include "parse-options.h"
 
-static const char prune_packed_usage[] =
-"git prune-packed [-n] [-q]";
+static const char * const prune_packed_usage[] = {
+	"git prune-packed [-n|--dry-run] [-q|--quiet]",
+	NULL
+};
 
 #define DRY_RUN 01
 #define VERBOSE 02
@@ -68,24 +71,16 @@ void prune_packed_objects(int opts)
 
 int cmd_prune_packed(int argc, const char **argv, const char *prefix)
 {
-	int i;
 	int opts = VERBOSE;
+	const struct option prune_packed_options[] = {
+		OPT_BIT('n', "dry-run", &opts, "dry run", DRY_RUN),
+		OPT_NEGBIT('q', "quiet", &opts, "be quiet", VERBOSE),
+		OPT_END()
+	};
 
-	for (i = 1; i < argc; i++) {
-		const char *arg = argv[i];
+	argc = parse_options(argc, argv, prefix, prune_packed_options,
+			     prune_packed_usage, 0);
 
-		if (*arg == '-') {
-			if (!strcmp(arg, "-n"))
-				opts |= DRY_RUN;
-			else if (!strcmp(arg, "-q"))
-				opts &= ~VERBOSE;
-			else
-				usage(prune_packed_usage);
-			continue;
-		}
-		/* Handle arguments here .. */
-		usage(prune_packed_usage);
-	}
 	prune_packed_objects(opts);
 	return 0;
 }
-- 
1.6.3.3.385.g60647
Previous: Stephen BoydNext: Johannes Schindelin
Message 5 of 9 in “Migrate simple builtins to parse-options”
  1. 0/4 Migrate simple builtins to parse-optionsStephen Boyd, Jul 8, 2009
  2. 1/4 write-tree: migrate to parse-optionsStephen Boyd, Jul 8, 2009
  3. 2/4 tag-verify: migrate to parse-optionsStephen Boyd, Jul 8, 2009
  4. 3/4 verify-pack: migrate to parse-optionsStephen Boyd, Jul 8, 2009
  5. 4/4 prune-packed: migrate to parse-optionsStephen Boyd, Jul 8, 2009
  6. Johannes SchindelinJul 9, 2009
  7. Stephen BoydJul 9, 2009
  8. Stephen BoydJul 9, 2009
  9. Stephen BoydJul 9, 2009

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.