From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Stefano Lattarini <stefano.lattarini@gmail.com>, git@vger.kernel.org
Subject: Re: Re* [BUG] "git checkout -b" erronously thinks a branch already exists
Date: Mon, 6 Jun 2011 12:05:38 -0400 [thread overview]
Message-ID: <20110606160538.GA11485@sigill.intra.peff.net> (raw)
In-Reply-To: <7v1uz7bkc9.fsf@alter.siamese.dyndns.org>
On Sun, Jun 05, 2011 at 10:27:34PM -0700, Junio C Hamano wrote:
> Let's do this instead. I don't know what I was thinking when I wrote that
> inefficient "loop refs to see if there is that one" patch.
>
> -- >8 --
> Subject: [PATCH] checkout -b <name>: correctly detect existing branch
Yeah, I did a double-take seeing your other patch and wondering why you
weren't just using resolve_ref.
So this patch looks good to me.
> +int ref_exists(char *refname)
> +{
> + unsigned char sha1[20];
> + return !!resolve_ref(refname, sha1, 1, NULL);
> +}
I was tempted to suggest that ref_exists could be used in lots of other
places to make the code slightly more readable. But in many cases, the
variable holding the dummy sha1 cannot go away (because it is used
elsewhere in the function), which means manually figuring out whether or
not the sha1 was actually a dummy or not[1]. So it's probably not worth
the effort for such minor gain.
-Peff
[1] For example, the one in create_branch is OK to change, but the one
in delete_branch is not.
prev parent reply other threads:[~2011-06-06 16:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-05 11:05 [BUG] "git checkout -b" erronously thinks a branch already exists Stefano Lattarini
2011-06-06 1:38 ` Re* " Junio C Hamano
2011-06-06 5:27 ` Junio C Hamano
2011-06-06 8:26 ` Stefano Lattarini
2011-06-06 16:05 ` Jeff King [this message]
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=20110606160538.GA11485@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=stefano.lattarini@gmail.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).