From: Junio C Hamano <gitster@pobox.com>
To: Paul Tan <pyokagan@gmail.com>
Cc: git@vger.kernel.org,
Johannes Schindelin <johannes.schindelin@gmx.de>,
Duy Nguyen <pclouds@gmail.com>
Subject: Re: [PATCH/RFC/GSOC] make git-pull a builtin
Date: Wed, 18 Mar 2015 15:26:02 -0700 [thread overview]
Message-ID: <xmqqpp86kkn9.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1426600662-32276-1-git-send-email-pyokagan@gmail.com> (Paul Tan's message of "Tue, 17 Mar 2015 21:57:42 +0800")
Paul Tan <pyokagan@gmail.com> writes:
> +/* Global vars since they are used often */
> +static char *head_name;
> +static const char *head_name_short;
> +static unsigned char head_sha1[20];
> +static int head_flags;
> +
> +enum rebase_type {
> + REBASE_FALSE = 0,
> + REBASE_TRUE = 1,
> + REBASE_PRESERVE = 2
> +};
> +
> +/**
> + * Parse rebase config/option value and return corresponding int
> + */
> +static int parse_rebase(const char *arg)
> +{
> + if (!strcmp(arg, "true"))
> + return REBASE_TRUE;
> + else if (!strcmp(arg, "false"))
> + return REBASE_FALSE;
> + else if (!strcmp(arg, "preserve"))
> + return REBASE_PRESERVE;
> + else
> + return -1; /* Invalid value */
> +}
Even though the original does not use bool-or-string-config, we
would want to do the same by doing something like
case (config_maybe_bool()) {
case 0:
return REBASE_FALSE;
case 1:
return REBASE_TRUE;
default:
if (!strcmp(arg, "preserve"))
return REBASE_PRESERVE;
return -1;
}
and then use that in rebase_config_default().
> +
> +/**
> + * Returns default rebase option value
> + */
> +static int rebase_config_default(void)
> +{
> + struct strbuf name = STRBUF_INIT;
> + const char *value = NULL;
> + int boolval;
> +
> + strbuf_addf(&name, "branch.%s.rebase", head_name_short);
> + if (git_config_get_value(name.buf, &value))
> + git_config_get_value("pull.rebase", &value);
What happens when neither is defined?
> + strbuf_release(&name);
> + if (!value)
> + return REBASE_FALSE;
Hmph, are you sure about this? Isn't this "[pull] rebase" that does
not have "= value", in which case pull.rebase is "true"?
You cannot use NULL as the sentinel value to tell that you did not
find either branch.*.rebase nor pull.rebase (in which case you want
to default to 'false'). Either of them can be spelled as an
equal-less true, which you will see as value==NULL, and you want to
take that as 'true'.
const char *value = "false";
...
if (get_value(..., &value))
get_value(..., &value));
strbuf_release(&name);
if (!value)
return REBASE_TRUE;
return parse_rebase(value);
or something along that line, perhaps?
> + boolval = git_config_maybe_bool("pull.rebase", value);
> + if (boolval >= 0)
> + return boolval ? REBASE_TRUE : REBASE_FALSE;
> + else if (value && !strcmp(value, "preserve"))
> + return REBASE_PRESERVE;
Is value something you need to free before returning from this
function?
> +static int parse_opt_recurse_submodules(const struct option *opt, const char *arg, int unset)
> +{
> + if (!arg)
> + *(int *)opt->value = unset ? RS_NO : RS_YES;
> + else if (!strcmp(arg, "no"))
> + *(int *)opt->value = RS_NO;
> + else if (!strcmp(arg, "yes"))
> + *(int *)opt->value = RS_YES;
> + else if (!strcmp(arg, "on-demand"))
> + *(int *)opt->value = RS_ON_DEMAND;
> + else
> + return -1;
> + return 0;
I suspect that maybe-bool-or-string comment applies equally here for
the UI consistency.
I'll stop here for now. Thanks.
next prev parent reply other threads:[~2015-03-18 22:49 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-17 13:57 [PATCH/RFC/GSOC] make git-pull a builtin Paul Tan
2015-03-18 8:38 ` Stephen Robin
2015-03-18 9:24 ` Johannes Schindelin
2015-03-18 9:00 ` Johannes Schindelin
2015-03-21 14:00 ` Paul Tan
2015-03-21 17:27 ` Johannes Schindelin
2015-03-18 17:52 ` Matthieu Moy
2015-03-21 13:23 ` Paul Tan
2015-03-21 17:35 ` Johannes Schindelin
2015-03-22 17:39 ` Paul Tan
2015-03-23 9:07 ` Johannes Schindelin
2015-03-23 10:18 ` Duy Nguyen
2015-03-24 15:58 ` Paul Tan
2015-03-18 22:26 ` Junio C Hamano [this message]
2015-03-21 13:40 ` Paul Tan
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqpp86kkn9.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=johannes.schindelin@gmx.de \
--cc=pclouds@gmail.com \
--cc=pyokagan@gmail.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).