Re: [PATCH 02/11] diff: handle NULL return from repo_get_commit_tree()
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jul 10, 2026, 03:11 UTC
- Message-ID
- <xmqqldbjh73r.fsf@gitster.g>
- In-Reply-To
- <4fdba0542b3d643affe32ec35f27fdbabccf54d0.1783590159.git.gitgitgadget@gmail.com>
"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 18 quoted lines
> diff --git a/builtin/diff.c b/builtin/diff.c
> index 4b46e394ce..18b1083e98 100644
> --- a/builtin/diff.c
> +++ b/builtin/diff.c
> @@ -579,9 +579,13 @@ int cmd_diff(int argc,
> obj = deref_tag(the_repository, obj, NULL, 0);
> if (!obj)
> die(_("invalid object '%s' given."), name);
> - if (obj->type == OBJ_COMMIT)
> - obj = &repo_get_commit_tree(the_repository,
> - ((struct commit *)obj))->object;
> + if (obj->type == OBJ_COMMIT) {
> + struct tree *tree = repo_get_commit_tree(
> + the_repository, (struct commit *)obj);
> + if (!tree)
> + die(_("unable to read tree object for commit '%s'"), name);
> + obj = &tree->object;
> + }Obviously correct.
> if (obj->type == OBJ_TREE) {
> if (sdiff.skip && bitmap_get(sdiff.skip, i))