]> git.ipfire.org Git - thirdparty/git.git/commitdiff
replay: parse commits before dereferencing them
authorPatrick Steinhardt <ps@pks.im>
Wed, 1 Oct 2025 15:57:30 +0000 (17:57 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Oct 2025 19:33:29 +0000 (12:33 -0700)
When looking up a commit it may not be parsed yet. Callers that wish to
access the fields of `struct commit` have to call `repo_parse_commit()`
first so that it is guaranteed to be populated.

We didn't yet care about doing so, because code paths that lead to
`pick_regular_commit()` in "builtin/replay.c" already implicitly parsed
the commits. But now that the function is exposed to outside callers
it's quite easy to get this wrong.

Make the function easier to use by calling `repo_parse_commit()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
replay.c

index 13d75d8054316616c80e49ed6924bda9b3f7cb2b..c3628d2488b8ba86a61760ae7c1574581fb0942c 100644 (file)
--- a/replay.c
+++ b/replay.c
@@ -90,6 +90,9 @@ struct commit *replay_pick_regular_commit(struct repository *repo,
        struct commit *base, *replayed_base;
        struct tree *pickme_tree, *base_tree;
 
+       if (repo_parse_commit(repo, pickme))
+               return NULL;
+
        base = pickme->parents->item;
        replayed_base = mapped_commit(replayed_commits, base, onto);