[PATCH] unpack-objects: migrate to parse-options

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Stephen Boyd <bebarino@xxxxxxxxx>
---
 builtin/unpack-objects.c |   80 ++++++++++++++++++++++------------------------
 1 files changed, 38 insertions(+), 42 deletions(-)

diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index f63973c..183a967 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -11,9 +11,13 @@
 #include "progress.h"
 #include "decorate.h"
 #include "fsck.h"
+#include "parse-options.h"
 
 static int dry_run, quiet, recover, has_errors, strict;
-static const char unpack_usage[] = "git unpack-objects [-n] [-q] [-r] [--strict] < pack-file";
+static const char * const unpack_usage[] = {
+	"git unpack-objects [options] < pack-file",
+	NULL
+};
 
 /* We always read in 4kB chunks. */
 static unsigned char buffer[4096];
@@ -492,10 +496,38 @@ static void unpack_all(void)
 		die("unresolved deltas left after unpacking");
 }
 
+static int pack_header_cb(const struct option *opt, const char *arg, int unset)
+{
+	struct pack_header *hdr;
+	char *c;
+
+	hdr = (struct pack_header *)buffer;
+	hdr->hdr_signature = htonl(PACK_SIGNATURE);
+	hdr->hdr_version = htonl(strtoul(arg, &c, 10));
+	if (*c != ',')
+		die("bad %s", arg);
+	hdr->hdr_entries = htonl(strtoul(c + 1, &c, 10));
+	if (*c)
+		die("bad %s", arg);
+	len = sizeof(*hdr);
+	return 0;
+}
+
 int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
 {
-	int i;
 	unsigned char sha1[20];
+	const struct option unpack_options[] = {
+		OPT__DRY_RUN(&dry_run,
+			    "check the pack file but don't actually unpack it"),
+		OPT__QUIET(&quiet, "suppress percentage progress"),
+		OPT_BOOLEAN('r', NULL, &recover, "ignore corrupt packfiles"),
+		OPT_BOOLEAN(0, "strict", &strict,
+			    "don't write objects with broken content or links"),
+		{ OPTION_CALLBACK, 0, "pack_header", NULL, "<ver>,<entries>",
+		  "internal option", PARSE_OPT_HIDDEN | PARSE_OPT_NONEG |
+		  PARSE_OPT_LITERAL_ARGHELP, pack_header_cb },
+		OPT_END()
+	};
 
 	read_replace_refs = 0;
 
@@ -503,47 +535,11 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
 
 	quiet = !isatty(2);
 
-	for (i = 1 ; i < argc; i++) {
-		const char *arg = argv[i];
-
-		if (*arg == '-') {
-			if (!strcmp(arg, "-n")) {
-				dry_run = 1;
-				continue;
-			}
-			if (!strcmp(arg, "-q")) {
-				quiet = 1;
-				continue;
-			}
-			if (!strcmp(arg, "-r")) {
-				recover = 1;
-				continue;
-			}
-			if (!strcmp(arg, "--strict")) {
-				strict = 1;
-				continue;
-			}
-			if (!prefixcmp(arg, "--pack_header=")) {
-				struct pack_header *hdr;
-				char *c;
-
-				hdr = (struct pack_header *)buffer;
-				hdr->hdr_signature = htonl(PACK_SIGNATURE);
-				hdr->hdr_version = htonl(strtoul(arg + 14, &c, 10));
-				if (*c != ',')
-					die("bad %s", arg);
-				hdr->hdr_entries = htonl(strtoul(c + 1, &c, 10));
-				if (*c)
-					die("bad %s", arg);
-				len = sizeof(*hdr);
-				continue;
-			}
-			usage(unpack_usage);
-		}
-
+	argc = parse_options(argc, argv, prefix, unpack_options,
+			     unpack_usage, 0);
+	if (argc)
 		/* We don't take any non-flag arguments now.. Maybe some day */
-		usage(unpack_usage);
-	}
+		usage_with_options(unpack_usage, unpack_options);
 	git_SHA1_Init(&ctx);
 	unpack_all();
 	git_SHA1_Update(&ctx, buffer, offset);
-- 
1.7.4.2.422.g537d99

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]