git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] RFC: make --set-upstream work for branches not in refs/heads/

From
Krzesimir Nowak <krzesimir@endocode.com>
Date
Mar 4, 2014, 14:07 UTC
Message-ID
<1393942046-11488-2-git-send-email-krzesimir@endocode.com>
In-Reply-To
<1393942046-11488-1-git-send-email-krzesimir@endocode.com>
---
 transport.c | 41 ++++++++++++++++++++++++++++++++++-------
 1 file changed, 34 insertions(+), 7 deletions(-)
diff --git a/transport.c b/transport.c
index ca7bb44..ac933ee 100644
--- a/transport.c
+++ b/transport.c
@@ -143,6 +143,25 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list)
 	}
 }
 
+/* That of course should not be hardcoded. */
+static const char* list_of_local_refs[] = {"refs/heads/", "refs/wip/", NULL};
+static const char** get_local_refs(void)
+{
+	return list_of_local_refs;
+}
+
+static int is_local_ref(const char *ref)
+{
+	const char **local_refs = get_local_refs();
+	const char **iter;
+
+	for (iter = local_refs; iter != NULL; ++iter)
+		if (starts_with(ref, *iter))
+			return strlen(*iter);
+
+	return 0;
+}
+
 static void set_upstreams(struct transport *transport, struct ref *refs,
 	int pretend)
 {
@@ -153,6 +172,8 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
 		const char *remotename;
 		unsigned char sha[20];
 		int flag = 0;
+		int localadd = 0;
+		int remoteadd = 0;
 		/*
 		 * Check suitability for tracking. Must be successful /
 		 * already up-to-date ref create/modify (not delete).
@@ -169,23 +190,29 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
 		localname = ref->peer_ref->name;
 		remotename = ref->name;
 		tmp = resolve_ref_unsafe(localname, sha, 1, &flag);
-		if (tmp && flag & REF_ISSYMREF &&
-			starts_with(tmp, "refs/heads/"))
-			localname = tmp;
+
+		if (tmp && flag & REF_ISSYMREF) {
+			localadd = is_local_ref (tmp);
+			if (localadd > 0)
+				localname = tmp;
+		}
+		if (localadd == 0)
+			localadd = is_local_ref(localname);
+		remoteadd = is_local_ref(remotename);
 
 		/* Both source and destination must be local branches. */
-		if (!localname || !starts_with(localname, "refs/heads/"))
+		if (!localname || localadd == 0)
 			continue;
-		if (!remotename || !starts_with(remotename, "refs/heads/"))
+		if (!remotename || remoteadd == 0)
 			continue;
 
 		if (!pretend)
 			install_branch_config(BRANCH_CONFIG_VERBOSE,
-				localname + 11, transport->remote->name,
+				localname + localadd, transport->remote->name,
 				remotename);
 		else
 			printf("Would set upstream of '%s' to '%s' of '%s'\n",
-				localname + 11, remotename + 11,
+				localname + localadd, remotename + remoteadd,
 				transport->remote->name);
 	}
 }
-- 
1.8.3.1
Previous: Krzesimir NowakNext: Junio C Hamano
Message 2 of 4 in “[RFC] make --set-upstream work for local branches not in refs/heads”
  1. Krzesimir NowakMar 4, 2014
  2. RFC: make --set-upstream work for branches not in refs/heads/Krzesimir Nowak, Mar 4, 2014
  3. Junio C HamanoMar 4, 2014
  4. Krzesimir NowakMar 6, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.