From: Junio C Hamano <gitster@pobox.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: git@vger.kernel.org, "Todd Zullinger" <tmz@pobox.com>,
"Petr Šplíchal" <psplicha@redhat.com>
Subject: Re: [PATCH] checkout: fix BUG() case in 9081a421a6
Date: Fri, 21 Jan 2022 16:33:47 -0800 [thread overview]
Message-ID: <xmqqr190d2xg.fsf@gitster.g> (raw)
In-Reply-To: <patch-1.1-21ddf7c628d-20220120T212233Z-avarab@gmail.com> ("Ævar Arnfjörð Bjarmason"'s message of "Thu, 20 Jan 2022 22:26:57 +0100")
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> diff --git a/builtin/checkout.c b/builtin/checkout.c
> index 6a5dd2a2a22..52a47ef40e1 100644
> --- a/builtin/checkout.c
> +++ b/builtin/checkout.c
> @@ -1090,13 +1090,10 @@ static int switch_branches(const struct checkout_opts *opts,
> FREE_AND_NULL(old_branch_info.path);
>
> if (old_branch_info.path) {
> - const char *const prefix = "refs/heads/";
> - const char *p;
> - if (skip_prefix(old_branch_info.path, prefix, &p))
> - old_branch_info.name = xstrdup(p);
> - else
> - BUG("should be able to skip past '%s' in '%s'!",
> - prefix, old_branch_info.path);
> + const char *p = old_branch_info.path;
> +
> + skip_prefix(old_branch_info.path, "refs/heads/", &p);
> + old_branch_info.name = xstrdup(p);
> }
What we want is a faithful reversion wrt the behaviour, while
keeping the leakfix.
The old code did
skip_prefix(old_branch_info.path, "refs/heads", &old_branch_info.name);
meaning that old_branch_info.name is left unchanged if .path did not
begin with "refs/heads".
The function that uses old_branch_info.name prepared at this point
in the flow is merge_working_tree(), where it uses .name for the
textual label for the "ancestor" tree. It is preferrable to have a
branch name, but the code is prepared to see NULL in there, where it
comes up with an abbreviated commit object name.
o.ancestor = old_branch_info->name;
if (old_branch_info->name == NULL) {
strbuf_add_unique_abbrev(&old_commit_shortname,
&old_branch_info->commit->object.oid,
DEFAULT_ABBREV);
o.ancestor = old_commit_shortname.buf;
}
As 9081a421a6 properly 0-initializes old_branch_info, I think it is
sufficient to just drop the "else BUG" clause; we shouldn't have to
copy the .path that does not begin with "refs/heads/" there; .name
member would be NULL in such a case.
I do not care too much about reverting the constant that is only
used once into a literal. So, how about doing it this way instead?
builtin/checkout.c | 3 ---
1 file changed, 3 deletions(-)
diff --git i/builtin/checkout.c w/builtin/checkout.c
index 43d0275187..1fb34d537d 100644
--- i/builtin/checkout.c
+++ w/builtin/checkout.c
@@ -1094,9 +1094,6 @@ static int switch_branches(const struct checkout_opts *opts,
const char *p;
if (skip_prefix(old_branch_info.path, prefix, &p))
old_branch_info.name = xstrdup(p);
- else
- BUG("should be able to skip past '%s' in '%s'!",
- prefix, old_branch_info.path);
}
if (opts->new_orphan_branch && opts->orphan_from_empty_tree) {
next prev parent reply other threads:[~2022-01-22 0:33 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-20 16:51 [BUG] builtin/checkout.c:1098: should be able to skip past 'refs/heads/' Todd Zullinger
2022-01-20 17:04 ` Todd Zullinger
2022-01-20 21:26 ` [PATCH] checkout: fix BUG() case in 9081a421a6 Ævar Arnfjörð Bjarmason
2022-01-20 22:29 ` Junio C Hamano
2022-01-20 22:33 ` Junio C Hamano
2022-01-21 11:14 ` Ævar Arnfjörð Bjarmason
2022-01-21 14:29 ` Petr Šplíchal
2022-01-21 21:58 ` Todd Zullinger
2022-01-21 21:19 ` Junio C Hamano
2022-01-20 22:33 ` Todd Zullinger
2022-01-22 0:33 ` Junio C Hamano [this message]
2022-01-22 0:45 ` Junio C Hamano
2022-01-22 0:58 ` [PATCH] checkout: avoid BUG() when hitting a broken repository Junio C Hamano
2022-01-22 8:10 ` Johannes Sixt
2022-01-22 11:55 ` Ævar Arnfjörð Bjarmason
2022-01-23 16:38 ` Johannes Schindelin
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=xmqqr190d2xg.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=psplicha@redhat.com \
--cc=tmz@pobox.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.