gc: use parse_options
Signed-off-by: James Bowes <jbowes@dangerouslyinc.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
James Bowes committed
Nov 1, 2007 at 21:02 UTC
44c637c8021e44253f0f8cb17391092e08b39e73
1 file changed
+22
-22
builtin-gc.c
+22
-22
@@ -12,11 +12,15 @@
12
13
#include "builtin.h"
14
#include "cache.h"
15
+#include "parse-options.h"
16
#include "run-command.h"
17
18
#define FAILED_RUN "failed to run %s"
19
19
-static const char builtin_gc_usage[] = "git-gc [--prune] [--aggressive]";
20
+static const char * const builtin_gc_usage[] = {
21
+ "git-gc [options]",
22
+ NULL
23
+};
24
25
static int pack_refs = 1;
26
static int aggressive_window = -1;
@@ -165,38 +169,34 @@ static int need_to_gc(void)
169
170
int cmd_gc(int argc, const char **argv, const char *prefix)
171
{
168
- int i;
172
int prune = 0;
173
+ int aggressive = 0;
174
int auto_gc = 0;
175
char buf[80];
176
177
+ struct option builtin_gc_options[] = {
178
+ OPT_BOOLEAN(0, "prune", &prune, "prune unreferenced loose objects"),
179
+ OPT_BOOLEAN(0, "aggressive", &aggressive, "be more thorough (increased runtime)"),
180
+ OPT_BOOLEAN(0, "auto", &auto_gc, "enable auto-gc mode"),
181
+ OPT_END()
182
+ };
183
+
184
git_config(gc_config);
185
186
if (pack_refs < 0)
187
pack_refs = !is_bare_repository();
188
178
- for (i = 1; i < argc; i++) {
179
- const char *arg = argv[i];
180
- if (!strcmp(arg, "--prune")) {
181
- prune = 1;
182
- continue;
183
- }
184
- if (!strcmp(arg, "--aggressive")) {
185
- append_option(argv_repack, "-f", MAX_ADD);
186
- if (aggressive_window > 0) {
187
- sprintf(buf, "--window=%d", aggressive_window);
188
- append_option(argv_repack, buf, MAX_ADD);
189
- }
190
- continue;
191
- }
192
- if (!strcmp(arg, "--auto")) {
193
- auto_gc = 1;
194
- continue;
189
+ argc = parse_options(argc, argv, builtin_gc_options, builtin_gc_usage, 0);
190
+ if (argc > 0)
191
+ usage_with_options(builtin_gc_usage, builtin_gc_options);
192
+
193
+ if (aggressive) {
194
+ append_option(argv_repack, "-f", MAX_ADD);
195
+ if (aggressive_window > 0) {
196
+ sprintf(buf, "--window=%d", aggressive_window);
197
+ append_option(argv_repack, buf, MAX_ADD);
198
}
196
- break;
199
}
198
- if (i != argc)
199
- usage(builtin_gc_usage);
200
201
if (auto_gc) {
202
/*