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

Re: [PATCH] Make gc a builtin.

From
Shawn O. Pearce <spearce@spearce.org>
Date
Mar 12, 2007, 14:43 UTC
Message-ID
<20070312144312.GE15150@spearce.org>
In-Reply-To
<3f80363f0703111951x9d88e74x8d7723af97c18c7@mail.gmail.com>
A good (second) try.
James Bowes <jbowes@dangerouslyinc.com> wrote:
> diff --git a/builtin-gc.c b/builtin-gc.c
> +
> +static int pack_refs;
Actually I think you want to use:
static int pack_refs = -1;
See below for why...
Show 11 quoted lines
> +static int gc_config(const char *var, const char *value)
> +{
> +	if (!strcmp(var, "gc.packrefs"))
> +		if (strlen(value) == 0 || !strcmp(value, "notbare"))
> +			pack_refs = !is_bare_repository();
> +		else
> +			pack_refs = git_config_bool(var, value);
> +	else
> +		return git_default_config(var, value);
> +	return 0;
> +}

Gaaah. How about some curly braces around the then part of that first if?

Actually, we typically just write this more like:
static int gc_config(const char *var, const char *value)
{
	if (!strcmp(var, "gc.packrefs")) {
		if (!strcmp(value, "notbare"))
			pack_refs = -1;
		else
			pack_refs = git_config_bool(var, value);
	}
	return git_default_config(var, value);
}
Show 6 quoted lines
> +int cmd_gc(int argc, const char **argv, const char *prefix)
> +{
> +	int i;
> +	int prune = 0;
> +
> +	git_config(gc_config);
if (pack_refs < 0)
	pack_refs = !is_bare_repository();

The is_bare_repository function guesses until the configuration is done parsing; once the configuration has been parsed it has a definate answer one way or the other. So what I'm suggesting you do here is set pack_refs = -1 to mean use the is_bare_repository setting, otherwise it stays what it was set to.

> +    if (pack_refs)
> +	    if (run_command_v_opt(argv_pack_refs, RUN_GIT_CMD))
> +            goto failure;
....
> +    if (prune)
> +        if (run_command_v_opt(argv_prune, RUN_GIT_CMD))
> +            goto failure;

Gaah. Tabs-vs-spaces, not to mention that these aren't even lining up the same way. I too prefer what Dsco suggested already:

	if (prune && run_command_v_opt(argv_prune, RUN_GIT_CMD))
		return error("failed to run %s", argv_prune[0]);
-- 
Shawn.
Previous: James BowesNext: Johannes Schindelin
Message 7 of 15 in “Make gc a builtin.”
  1. 0/2 Make gc a builtin.James Bowes, Mar 11, 2007
  2. 1/2 run-command: Make run_command_va_opt public and add run_command_vaJames Bowes, Mar 11, 2007
  3. 2/2 Make gc a builtin.James Bowes, Mar 11, 2007
  4. Johannes SchindelinMar 11, 2007
  5. Junio C HamanoMar 12, 2007
  6. Make gc a builtin.James Bowes, Mar 12, 2007
  7. Shawn O. PearceMar 12, 2007
  8. Johannes SchindelinMar 12, 2007
  9. Theodore TsoMar 12, 2007
  10. Johannes SchindelinMar 12, 2007
  11. Theodore TsoMar 12, 2007
  12. Linus TorvaldsMar 12, 2007
  13. Jakub NarebskiMar 13, 2007
  14. Linus TorvaldsMar 13, 2007
  15. Shawn O. PearceMar 12, 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.