From: Stephen Boyd <bebarino@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH] unpack-objects: migrate to parse-options
Date: Wed, 30 Mar 2011 01:37:26 -0700 [thread overview]
Message-ID: <1301474246-7515-1-git-send-email-bebarino@gmail.com> (raw)
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
---
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
reply other threads:[~2011-03-30 8:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1301474246-7515-1-git-send-email-bebarino@gmail.com \
--to=bebarino@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).