From: Jeff King <peff@peff.net>
To: "Björn Steinbrink" <B.Steinbrink@gmx.de>
Cc: "Kirill A. Korinskiy" <catap@catap.ru>, git@vger.kernel.org
Subject: Re: [PATCH] Add option -b/--branch to clone for select a new HEAD
Date: Wed, 26 Aug 2009 12:10:59 -0400 [thread overview]
Message-ID: <20090826161059.GC32741@coredump.intra.peff.net> (raw)
In-Reply-To: <20090826155029.GA5750@atjola.homenet>
On Wed, Aug 26, 2009 at 05:50:29PM +0200, Björn Steinbrink wrote:
> Using guess_remote_head() seems pretty wrong. With -b given, you don't
> want to guess anymore, you _know_ which one you want. Unfortunately, I
> don't see a straight-forward way to handle that (but I'm totally
> clueless about the code, so don't let me scare you ;-)).
Thanks for pointing this out, Björn (I really should have noticed it on
first review, but I guess many eyes, shallow bugs, etc. :) ).
This code is a little bit confusing, so let me explain:
- we look up the remote HEAD, getting its commit sha1. If the protocol
supports it, we also get its symref information.
- we then pass the result to guess_remote_head. _If_ we have symref
information, then we can quit immediately, as the symref contains
what we want. If it doesn't, then we proceed with trying to match up
the commit sha1 with one of the other refs.
So if you want to create a "remote_head" object via "-b" which acts as
if it was the remote HEAD, you would need to actually create a new ref
object and set the "symref" field appropriately.
But I don't think there is any need to do that here. We simply want to
avoid calling guess_remote_head at all, since we know there is nothing
to guess at. We do still need to know whether remote_head is non-NULL
later, though.
So I think the code should probably look like this (totally untested):
remote_head = find_ref_by_name(refs, "HEAD");
if (option_branch) {
strbuf_addf(&branch_head, "%s%s", src_ref_prefix, option_branch);
head_points_at = find_ref_by_name(refs, branch_head.buf);
if (!head_points_at)
warning("remote branch not found, etc");
}
if (!head_points_at)
head_points_at = guess_remote_head(remote_head, mapped_refs, 0);
and then initialize head_points_at to NULL instead of remote_head.
-Peff
next prev parent reply other threads:[~2009-08-26 16:11 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <87praj90n8.wl%catap@catap.ru>
2009-08-25 19:25 ` [PATCH] Add option -b/--branch to clone for select a new HEAD Kirill A. Korinskiy
2009-08-25 19:27 ` Kirill A. Korinskiy
2009-08-25 21:57 ` Jeff King
2009-08-25 22:42 ` Junio C Hamano
2009-08-25 22:36 ` Björn Steinbrink
[not found] ` <87ljl694fd.wl%catap@catap.ru>
2009-08-26 12:16 ` Björn Steinbrink
2009-08-26 14:46 ` Kirill A. Korinskiy
2009-08-26 15:50 ` Björn Steinbrink
2009-08-26 16:10 ` Jeff King [this message]
2009-08-26 16:56 ` Björn Steinbrink
2009-08-26 17:48 ` Jeff King
2009-08-26 19:05 ` Jeff King
2009-08-28 10:31 ` Tor Arne Vestbø
2009-08-28 11:05 ` Martin Langhoff
2009-08-28 12:10 ` Julian Phillips
2009-08-24 20:42 Kirill A. Korinskiy
2009-08-25 1:57 ` Jeff King
2009-08-25 2:13 ` Junio C Hamano
2009-08-25 17:20 ` Kirill A. Korinskiy
2009-08-25 19:00 ` Jeff King
2009-08-25 12:30 ` Kirill A. Korinskiy
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=20090826161059.GC32741@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=B.Steinbrink@gmx.de \
--cc=catap@catap.ru \
--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).