Re: [RFC PATCH] branch: add "inherit" option for branch.autoSetupMerge

From
Glen Choo <hidden>
Date
2021-10-18 17:50:24
Reply to
Josh Steadmon, 2021-09-08
Josh Steadmon [off-list ref] writes:
quoted hunk ↗ jump to hunk
+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.
Thread (69 messages) 69 messages, 5 authors, last reply 2022-01-20
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help