Re: [RFC PATCH] branch: add "inherit" option for branch.autoSetupMerge
- From
Glen Choo <chooglen@google.com>
- Date
- Oct 18, 2021, 17:50 UTC
- Message-ID
- <kl6lwnmaz0gy.fsf@chooglen-macbookpro.roam.corp.google.com>
- In-Reply-To
- <9628d145881cb875f8e284967e10f587b9f686f9.1631126999.git.steadmon@google.com>
Josh Steadmon <steadmon@google.com> writes:
Show 31 quoted lines
> +static int inherit_tracking(struct tracking *tracking, const char *orig_ref)
> +{
> + struct strbuf key = STRBUF_INIT;
> + char *remote;
> + const char *bare_ref;
> +
> + bare_ref = orig_ref;
> + skip_prefix(orig_ref, "refs/heads/", &bare_ref);
> +
> + strbuf_addf(&key, "branch.%s.remote", bare_ref);
> + if (git_config_get_string(key.buf, &remote)) {
> + warning("branch.autoSetupMerge=inherit, but could not find %s",
> + key.buf);
> + strbuf_release(&key);
> + return 1;
> + }
> + tracking->remote = remote;
> +
> + strbuf_reset(&key);
> + strbuf_addf(&key, "branch.%s.merge", bare_ref);
> + if (git_config_get_string(key.buf, &tracking->src)) {
> + warning("branch.autoSetupMerge=inherit, but could not find %s",
> + key.buf);
> + strbuf_release(&key);
> + return 1;
> + }
> +
> + tracking->matches = 1;
> + strbuf_release(&key);
> + return 0;
> +}I believe that we can get the branch remote via struct branch. Instead of reading the config, we could do something along the lines of:
int *explicit;
struct branch *branch = branch_get();
char *remote = remote_for_branch(branch, explicit);
/* Optionally check explicit if we don't want to fall back to
* "origin" */I'm not sure which is the idiomatic way to get the branch remote, feel free to correct me.