All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: James Bowes <jbowes@dangerouslyinc.com>
Cc: Junio C Hamano <junkio@cox.net>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	git@vger.kernel.org
Subject: Re: [PATCH] Make gc a builtin.
Date: Mon, 12 Mar 2007 10:43:12 -0400	[thread overview]
Message-ID: <20070312144312.GE15150@spearce.org> (raw)
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...

> +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);
}

> +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.

  reply	other threads:[~2007-03-12 14:43 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-11 22:06 [PATCH 0/2] Make gc a builtin James Bowes
2007-03-11 22:06 ` [PATCH 1/2] run-command: Make run_command_va_opt public and add run_command_va James Bowes
2007-03-11 22:06 ` [PATCH 2/2] Make gc a builtin James Bowes
2007-03-11 22:48   ` Johannes Schindelin
2007-03-12  2:11     ` Junio C Hamano
2007-03-12  2:51       ` [PATCH] " James Bowes
2007-03-12 14:43         ` Shawn O. Pearce [this message]
2007-03-12  3:07       ` [PATCH 2/2] " Johannes Schindelin
2007-03-12  2:57 ` [PATCH 0/2] " Theodore Tso
2007-03-12 11:23   ` Johannes Schindelin
2007-03-12 13:36     ` Theodore Tso
2007-03-12 19:14       ` Linus Torvalds
2007-03-13  0:48         ` Jakub Narebski
2007-03-13  1:20           ` Linus Torvalds
2007-03-12 14:29     ` Shawn O. Pearce
  -- strict thread matches above, loose matches on Subject: below --
2007-03-13 23:03 [PATCH] " James Bowes
2007-03-14  1:05 ` Johannes Schindelin
2007-03-14  1:37   ` Brian Gernhardt
2007-03-14  1:58 James Bowes
2007-03-14  6:07 ` Shawn O. Pearce
2007-03-14  7:19   ` Junio C Hamano
2007-03-14  7:44     ` Theodore Tso
2007-03-14  7:55       ` Santi Béjar
2007-03-14  9:29         ` Junio C Hamano
2007-03-14 10:45       ` Andy Parkins
2007-03-14 11:12         ` Junio C Hamano
2007-03-14 11:48           ` Andy Parkins
2007-03-14 12:19           ` Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070312144312.GE15150@spearce.org \
    --to=spearce@spearce.org \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=jbowes@dangerouslyinc.com \
    --cc=junkio@cox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.