public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: Jeff King <peff@peff•net>
Cc: "Jonathan Nieder" <jrnieder@gmail•com>,
	"René Scharfe" <l.s.r@web•de>,
	"Git Mailing List" <git@vger•kernel.org>
Subject: Re: [PATCH] use skip_prefix() to avoid more magic numbers
Date: Tue, 07 Oct 2014 11:21:58 -0700	[thread overview]
Message-ID: <xmqqfvezg2pl.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <20141006011827.GA11027@peff.net> (Jeff King's message of "Sun, 5 Oct 2014 21:18:28 -0400")

Jeff King <peff@peff•net> writes:

> On Sun, Oct 05, 2014 at 03:49:19PM -0700, Jonathan Nieder wrote:
>
>> > --- a/builtin/branch.c
>> > +++ b/builtin/branch.c
>> > @@ -81,14 +81,16 @@ static int parse_branch_color_slot(const char *var, int ofs)
>> >  
>> >  static int git_branch_config(const char *var, const char *value, void *cb)
>> >  {
>> > +	const char *slot_name;
>> > +
>> >  	if (starts_with(var, "column."))
>> >  		return git_column_config(var, value, "branch", &colopts);
>> >  	if (!strcmp(var, "color.branch")) {
>> >  		branch_use_color = git_config_colorbool(var, value);
>> >  		return 0;
>> >  	}
>> > -	if (starts_with(var, "color.branch.")) {
>> > -		int slot = parse_branch_color_slot(var, 13);
>> > +	if (skip_prefix(var, "color.branch.", &slot_name)) {
>> > +		int slot = parse_branch_color_slot(var, slot_name - var);
>> 
>> I wonder why the separate var and offset parameters exist in the first
>> place.  Wouldn't taking a single const char * so the old code could use
>> 'var + 13' instead of 'var, 13' have worked?
>
> I think this is in the same boat as parse_diff_color_slot, which I fixed
> in 9e1a5eb (parse_diff_color_slot: drop ofs parameter, 2014-06-18). The
> short of it is that the function used to want both the full name and the
> slot name, but now needs only the latter.
>
> The fix you proposed below is along the same line, and looks good to me
> (and grepping for 'var *+ *ofs' shows only the two sites you found, so
> hopefully that is the last of it).

builtin/commit.c::parse_status_slot() has the same construct.

  parent reply	other threads:[~2014-10-07 18:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-04 18:54 [PATCH] use skip_prefix() to avoid more magic numbers René Scharfe
2014-10-05 22:49 ` Jonathan Nieder
2014-10-06  1:18   ` Jeff King
2014-10-07 18:14     ` Junio C Hamano
2014-10-07 19:16       ` Jeff King
2014-10-07 19:33         ` Jeff King
2014-10-07 19:47           ` Junio C Hamano
2014-10-07 18:21     ` Junio C Hamano [this message]
2014-10-07 18:31       ` Jeff King
2014-10-06  1:35 ` Jeff King
2014-10-07 18:23 ` Junio C Hamano
2014-10-09 20:06   ` René Scharfe
2014-10-09 20:12     ` Junio C Hamano

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=xmqqfvezg2pl.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=jrnieder@gmail$(echo .)com \
    --cc=l.s.r@web$(echo .)de \
    --cc=peff@peff$(echo .)net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox