From: "Sean" <seanlkml@sympatico.ca>
To: git@vger.kernel.org
Subject: [RFC] git-fsck-cache argument processing
Date: Fri, 20 May 2005 23:38:52 -0400 (EDT) [thread overview]
Message-ID: <4870.10.10.10.24.1116646732.squirrel@linux1> (raw)
In-Reply-To:
[-- Attachment #1: Type: text/plain, Size: 1299 bytes --]
Here is a first crack at using argp as suggested by Jeff Garzik to
implement argument processing as requested by Junio and Linus. Each of
the long arguments have been given a single character equivalent as well.
This patch only converts fsck-cache to use argp in case anyone has
objections to the basic format or style. The patch includes a version
number inside of fsck-cache.c; this should really be in a separate include
file so you can run any command with --version and get the same answer.
With this change you have:
$ git-fsck-cache -?
Usage: git-fsck-cache [OPTION...] [HEAD-SHA1...]
git-fsck-cache - repository consistency check
-c, --cache Mark all objects referenced by cache as reachable
-d, --delta-depth Show the maximum length of delta chains
-r, --root Show root objects, ie. those without parents
-t, --tags Show revision tags
-u, --unreachable Show missing objects or deltas
-?, --help Give this help list
--usage Give a short usage message
-V, --version Print program version
And the following should work as expected:
$ git-fsck-cache -crudt
fsck-cache.c | 64
+++++++++++++++++++++++++++++++++++------------------------
1 files changed, 39 insertions(+), 25 deletions(-)
Sean
[-- Attachment #2: fsck-cache-argp-v1.patch --]
[-- Type: application/octet-stream, Size: 2375 bytes --]
fsck-cache.c: needs update
Index: fsck-cache.c
===================================================================
--- 58741c69570705801db4b785681790d636475695/fsck-cache.c (mode:100644)
+++ uncommitted/fsck-cache.c (mode:100644)
@@ -1,5 +1,7 @@
#include <sys/types.h>
#include <dirent.h>
+#include <argp.h>
+const char *argp_program_version = "git 1.0";
#include "cache.h"
#include "commit.h"
@@ -407,36 +409,48 @@
find_file_objects(git_dir, "refs");
}
+#define O_UNREACH 'u'
+#define O_TAGS 't'
+#define O_ROOT 'r'
+#define O_DELTA 'd'
+#define O_CACHE 'c'
+
+static const char doc[] = "Perform repository consistency check";
+
+static struct argp_option options[] = {
+ {"unreachable", O_UNREACH, 0, 0, "Show missing objects or deltas"},
+ {"tags", O_TAGS, 0, 0, "Show revision tags"},
+ {"root", O_ROOT, 0, 0, "Show root objects, ie. those without parents"},
+ {"delta-depth", O_DELTA, 0, 0, "Show the maximum length of delta chains"},
+ {"cache", O_CACHE, 0, 0, "Mark all objects referenced by cache as reachable"},
+ { }
+};
+
+static error_t parse_opt (int key, char *arg, struct argp_state *state)
+{
+ switch (key) {
+ case O_UNREACH: show_unreachable = 1; break;
+ case O_TAGS: show_tags = 1; break;
+ case O_ROOT: show_root = 1; break;
+ case O_DELTA: show_max_delta_depth = 1; break;
+ case O_CACHE: keep_cache_objects = 1; break;
+ case ARGP_KEY_ARG: state->next = state->argc; break;
+ default: return ARGP_ERR_UNKNOWN;
+ }
+ return 0;
+}
+
+static const struct argp argp = { options, parse_opt, "[HEAD-SHA1...]", doc };
+
int main(int argc, char **argv)
{
int i, heads;
char *sha1_dir;
- for (i = 1; i < argc; i++) {
- const char *arg = argv[i];
-
- if (!strcmp(arg, "--unreachable")) {
- show_unreachable = 1;
- continue;
- }
- if (!strcmp(arg, "--tags")) {
- show_tags = 1;
- continue;
- }
- if (!strcmp(arg, "--root")) {
- show_root = 1;
- continue;
- }
- if (!strcmp(arg, "--delta-depth")) {
- show_max_delta_depth = 1;
- continue;
- }
- if (!strcmp(arg, "--cache")) {
- keep_cache_objects = 1;
- continue;
- }
- if (*arg == '-')
- usage("git-fsck-cache [--tags] [[--unreachable] [--cache] <head-sha1>*]");
+ error_t rc = argp_parse(&argp, argc, argv, 0, NULL, NULL);
+ if (rc) {
+ fprintf(stderr, "argument failed: %s\n", strerror(rc));
+ return 1;
}
sha1_dir = get_object_directory();
next reply other threads:[~2005-05-21 3:38 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-05-21 3:38 Sean [this message]
2005-05-21 4:08 ` [RFC] git-fsck-cache argument processing Jeff Garzik
2005-05-21 4:36 ` Sean
2005-05-21 5:09 ` Jeff Garzik
2005-05-21 5:08 ` Junio C Hamano
2005-05-21 5:15 ` Jeff Garzik
2005-05-21 5:59 ` Junio C Hamano
2005-05-21 15:09 ` Olivier Galibert
2005-05-21 15:35 ` Jeff Garzik
2005-05-21 17:22 ` Sean
2005-05-21 18:49 ` Olivier Galibert
2005-05-21 19:00 ` Sean
2005-05-21 23:53 ` Jeff Garzik
2005-05-21 22:14 ` Joel Becker
2005-05-21 19:47 ` Linus Torvalds
2005-05-21 20:46 ` Sean
2005-05-21 21:09 ` Sean
2005-05-21 19:49 ` Linus Torvalds
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=4870.10.10.10.24.1116646732.squirrel@linux1 \
--to=seanlkml@sympatico.ca \
--cc=git@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.