From: Junio C Hamano <gitster@pobox.com>
To: Glen Choo <chooglen@google.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] checkout, clone: die if tree cannot be parsed
Date: Tue, 01 Mar 2022 23:26:47 -0800 [thread overview]
Message-ID: <xmqq5yowolvs.fsf@gitster.g> (raw)
In-Reply-To: <20220302003613.15567-1-chooglen@google.com> (Glen Choo's message of "Tue, 1 Mar 2022 16:36:13 -0800")
Glen Choo <chooglen@google.com> writes:
> Note that there are many other callsites that don't check for NULLs from
> parse_tree_indirect(), and some of which are fairly subtle. I wasn't
> confident in changing those, so I stayed on the conservative side and
> only changed the ones that I could get to segfault.
Thanks.
> - tree = parse_tree_indirect(old_branch_info->commit ?
> - &old_branch_info->commit->object.oid :
> - the_hash_algo->empty_tree);
> +
> + old_commit_oid = old_branch_info->commit ?
> + &old_branch_info->commit->object.oid :
> + the_hash_algo->empty_tree;
I guess this is done only so that you can use the object name in the
error message, which is fine.
> + tree = parse_tree_indirect(old_commit_oid);
> + if (!tree)
> + die(_("unable to parse commit %s"),
> + oid_to_hex(old_commit_oid));
"unable to parse commit" is a bit of a white lie. In fact, there is
nothing that makes oid_commit_oid the name of a commit object.
"unable to parse object '%s' as a tree" would be more technically
correct, but one random-looking hexadecimal string is almost
indistinguishable from another, and neither would be a very useful
message from the end user's point of view. I am wondering if we can
use old_branch_info to formulate something easier to understand for
the user. update_refs_for_switch() seems to compute old_desc as a
human readable name by using old_branch_info->name if available
before falling back to old_branch_info->commit object name, which
might be a source of inspiration.
> init_tree_desc(&trees[0], tree->buffer, tree->size);
> parse_tree(new_tree);
> tree = new_tree;
> diff --git a/builtin/clone.c b/builtin/clone.c
> index a572cda503..0aea177660 100644
> --- a/builtin/clone.c
> +++ b/builtin/clone.c
> @@ -700,6 +700,8 @@
> init_checkout_metadata(&opts.meta, head, &oid, NULL);
>
> tree = parse_tree_indirect(&oid);
> + if (!tree)
> + die(_("unable to parse commit %s"), oid_to_hex(&oid));
If we follow the code path, we can positively tell that oid here has
always came from reading HEAD, so "unable to parse HEAD as a tree"
would be an easier version of the message, I think.
Thanks.
next prev parent reply other threads:[~2022-03-02 7:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-02 0:36 [PATCH] checkout, clone: die if tree cannot be parsed Glen Choo
2022-03-02 7:26 ` Junio C Hamano [this message]
2022-03-02 19:35 ` Glen Choo
2022-03-09 22:20 ` 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=xmqq5yowolvs.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=chooglen@google.com \
--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).