On Mon, Jul 01, 2013 at 01:49:37PM -0400, Phil Hord wrote:
> It would be nice to support more generic specs for the --branch
> switch. But it is complicated because the refs have not been fetched
> yet during the clone, and so normal refs operations -- which expect to
> work on a local repository -- do not work. So, the ref is looked up
> locally from a list in expected locations after fetching the remote
> refs but before the clone occurs. The remote refs which are fetched
> is not configurable during clone, and so only 'refs/heads/*' is
> fetched for non-mirrors.
I think there are two problems:
1. Our find_remote_branch function implements only half of the regular
ref_rev_parse_rules (heads and tags). Fixing that to make "-b
refs/heads/master" work is pretty easy. Patch is below.
2. When we give a ref that is not going to be fetched, we should
fetch it explicitly. It looks like --single-branch tries to do
this, but only handles tags. I am not sure what a non-single-branch
would want to do (since you are effectively overriding the
default refspecs).
So even with the patch, doing "clone -b refs/foo/bar" does not
quite work.
diff --git a/builtin/clone.c b/builtin/clone.c
index 14b1323..5984303 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -433,24 +433,24 @@ static struct ref *find_remote_branch(const struct ref
*refs, const char *branch
raise(signo);
}
-static struct ref *find_remote_branch(const struct ref *refs, const char
*branch)
+static struct ref *find_remote_branch(const struct ref *refs, const char *name)
{
- struct ref *ref;
- struct strbuf head = STRBUF_INIT;
- strbuf_addstr(&head, "refs/heads/");
- strbuf_addstr(&head, branch);
- ref = find_ref_by_name(refs, head.buf);
- strbuf_release(&head);
-
- if (ref)
- return ref;
-
- strbuf_addstr(&head, "refs/tags/");
- strbuf_addstr(&head, branch);
- ref = find_ref_by_name(refs, head.buf);
- strbuf_release(&head);
-
- return ref;
+ int len = strlen(name);
+ const char **p;
+
+ for (p = ref_rev_parse_rules; *p; p++) {
+ struct ref *ref;
+
+ ref = find_ref_by_name(refs, mkpath(*p, len, name));
+ if (ref)
+ /*
+ * optionally check for and complain about ambiguity
+ * here, like dwim_ref does
+ */
+ return ref;
+ }
+
+ return NULL;
}
static struct ref *wanted_peer_refs(const struct ref *refs,
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html