git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Krzesimir Nowak <krzesimir@endocode.com>
To: git@vger.kernel.org
Cc: Krzesimir Nowak <krzesimir@endocode.com>
Subject: [PATCH] RFC: make --set-upstream work for branches not in refs/heads/
Date: Tue,  4 Mar 2014 15:07:26 +0100	[thread overview]
Message-ID: <1393942046-11488-2-git-send-email-krzesimir@endocode.com> (raw)
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

  reply	other threads:[~2014-03-04 14:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-04 14:07 [RFC] make --set-upstream work for local branches not in refs/heads Krzesimir Nowak
2014-03-04 14:07 ` Krzesimir Nowak [this message]
2014-03-04 19:44 ` Junio C Hamano
2014-03-06  9:27   ` Krzesimir Nowak

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=1393942046-11488-2-git-send-email-krzesimir@endocode.com \
    --to=krzesimir@endocode.com \
    --cc=git@vger.kernel.org \
    /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 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 NNTP newsgroup(s).