From: Jeff King <peff@peff.net>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: "René Scharfe" <l.s.r@web.de>,
"Git Mailing List" <git@vger.kernel.org>,
"Junio C Hamano" <gitster@pobox.com>
Subject: Re: [PATCH] use skip_prefix() to avoid more magic numbers
Date: Sun, 5 Oct 2014 21:18:28 -0400 [thread overview]
Message-ID: <20141006011827.GA11027@peff.net> (raw)
In-Reply-To: <20141005224919.GA19998@google.com>
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).
> > @@ -809,18 +808,19 @@ static void parse_commit_header(struct format_commit_context *context)
> > int i;
> >
> > for (i = 0; msg[i]; i++) {
> > + const char *name;
>
> ident instead of name, maybe? (since it's a 'name <email> timestamp'
> field)
Yeah, agreed.
-Peff
next prev parent reply other threads:[~2014-10-06 1:18 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 [this message]
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
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=20141006011827.GA11027@peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=l.s.r@web.de \
/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.