Thread (4 messages) flat view 4 messages, 4 authors, 2016-06-15

Re: [PATCH] gc: use parse_options

From: Pierre Habouzit <hidden>
Date: 2016-06-15 22:43:46

Possibly related (same subject, not in this thread)

On Fri, Nov 02, 2007 at 12:49:25AM +0000, Junio C Hamano wrote:
James Bowes [off-list ref] writes:
quoted
+	struct option builtin_gc_options[] = {
+		OPT_BOOLEAN(0, "prune", &prune, "prune unused objects"),
I would write "unreferenced loose" instead of "unused" here...
quoted
+		OPT_BOOLEAN(0, "aggressive", &aggressive, "be more thorough (increased runtime)"),
+		OPT_BOOLEAN(0, "auto", &auto_gc, "enable auto-gc mode"),
+		OPT_END()
+	};
+
 	git_config(gc_config);
 
 	if (pack_refs < 0)
 		pack_refs = !is_bare_repository();
 
+	parse_options(argc, argv, builtin_gc_options, builtin_gc_usage, 0);
+
+	if (aggressive) {
+		append_option(argv_repack, "-f", MAX_ADD);
+		if (aggressive_window > 0) {
+			sprintf(buf, "--window=%d", aggressive_window);
+			append_option(argv_repack, buf, MAX_ADD);
 		}
 	}
-	if (i != argc)
-		usage(builtin_gc_usage);
Now, what makes the command report error when the user says:

	$ git gc unwanted parameter
the commands works fine, because no additionnal checks were made. To
"fix" this, that should be done:

argc = parse_options(argc, argv, builtin_gc_options, builtin_gc_usage, 0);
if (argc)
    usage_with_options(......);

-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help