Make builtin-count-objects.c use parse_options.
Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Pierre Habouzit committed
Oct 15, 2007 at 22:38 UTC
833f3abd821434fd9b12d6cea66f04f232479c22
1 file changed
+15
-17
builtin-count-objects.c
+15
-17
@@ -6,8 +6,7 @@
6
7
#include "cache.h"
8
#include "builtin.h"
9
-
10
-static const char count_objects_usage[] = "git-count-objects [-v]";
9
+#include "parse-options.h"
10
11
static void count_objects(DIR *d, char *path, int len, int verbose,
12
unsigned long *loose,
@@ -67,29 +66,28 @@ static void count_objects(DIR *d, char *path, int len, int verbose,
66
}
67
}
68
70
-int cmd_count_objects(int ac, const char **av, const char *prefix)
69
+static char const * const count_objects_usage[] = {
70
+ "git-count-objects [-v]",
71
+ NULL
72
+};
73
+
74
+int cmd_count_objects(int argc, const char **argv, const char *prefix)
75
{
72
- int i;
73
- int verbose = 0;
76
+ int i, verbose = 0;
77
const char *objdir = get_object_directory();
78
int len = strlen(objdir);
79
char *path = xmalloc(len + 50);
80
unsigned long loose = 0, packed = 0, packed_loose = 0, garbage = 0;
81
unsigned long loose_size = 0;
82
+ struct option opts[] = {
83
+ OPT__VERBOSE(&verbose),
84
+ OPT_END(),
85
+ };
86
80
- for (i = 1; i < ac; i++) {
81
- const char *arg = av[i];
82
- if (*arg != '-')
83
- break;
84
- else if (!strcmp(arg, "-v"))
85
- verbose = 1;
86
- else
87
- usage(count_objects_usage);
88
- }
89
-
87
+ argc = parse_options(argc, argv, opts, count_objects_usage, 0);
88
/* we do not take arguments other than flags for now */
91
- if (i < ac)
92
- usage(count_objects_usage);
89
+ if (argc)
90
+ usage_with_options(count_objects_usage, opts);
91
memcpy(path, objdir, len);
92
if (len && objdir[len-1] != '/')
93
path[len++] = '/';