git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] gc: use parse_options

From
Pierre Habouzit <madcoder@debian.org>
Date
Nov 2, 2007, 08:32 UTC
Message-ID
<20071102083247.GB20200@artemis.corp>
In-Reply-To
<7vhck579pm.fsf@gitster.siamese.dyndns.org>
On Fri, Nov 02, 2007 at 12:49:25AM +0000, Junio C Hamano wrote:
Show 32 quoted lines
> James Bowes <jbowes@dangerouslyinc.com> writes:
> 
> > +	struct option builtin_gc_options[] = {
> > +		OPT_BOOLEAN(0, "prune", &prune, "prune unused objects"),
> 
> I would write "unreferenced loose" instead of "unused" here...
> 
> > +		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
Previous: James BowesNext: Brandon Casey
Message 4 of 6 in “gc: use parse_options”
  1. gc: use parse_optionsJames Bowes, Nov 2, 2007
  2. Junio C HamanoNov 2, 2007
  3. gc: use parse_optionsJames Bowes, Nov 2, 2007
  4. Pierre HabouzitNov 2, 2007
  5. Brandon CaseyNov 5, 2007
  6. Junio C HamanoNov 6, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.