From: Jeff King <peff@peff.net>
To: Phil Hord <phil.hord@gmail.com>
Cc: "Stefan Näwe" <stefan.naewe@atlas-elektronik.com>,
"Git List" <git@vger.kernel.org>
Subject: Re: git clone -b
Date: Wed, 3 Jul 2013 06:01:19 -0400 [thread overview]
Message-ID: <20130703100118.GA21130@sigill.intra.peff.net> (raw)
In-Reply-To: <CABURp0oQ9MNGZecD4mkniXMEUJ5L7Xn+JFQMEgc97Mfe26JYvg@mail.gmail.com>
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,
next prev parent reply other threads:[~2013-07-03 10:01 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-28 11:59 git clone -b Stefan Näwe
2013-06-28 12:15 ` Stefan Näwe
2013-06-28 12:18 ` Fredrik Gustafsson
2013-06-28 12:27 ` Stefan Näwe
2013-07-01 7:04 ` Stefan Näwe
2013-07-01 16:46 ` Junio C Hamano
2013-07-02 6:35 ` Stefan Näwe
2013-07-02 18:21 ` Junio C Hamano
2013-07-01 17:49 ` Phil Hord
2013-07-03 10:01 ` Jeff King [this message]
-- strict thread matches above, loose matches on Subject: below --
2017-05-08 6:30 Дилян Палаузов
2017-05-08 7:42 ` Jeff King
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=20130703100118.GA21130@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=phil.hord@gmail.com \
--cc=stefan.naewe@atlas-elektronik.com \
/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).