From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, Rasmus Villemoes <ravi@prevas.dk>,
Daniel Mach <daniel.mach@suse.com>
Subject: Re: [PATCH] commit: fall back to full read when maybe_tree is NULL
Date: Tue, 19 May 2026 14:56:51 +0900 [thread overview]
Message-ID: <xmqqcxys7xi4.fsf@gitster.g> (raw)
In-Reply-To: <20260519050513.GA1635924@coredump.intra.peff.net> (Jeff King's message of "Tue, 19 May 2026 01:05:13 -0400")
Jeff King <peff@peff.net> writes:
> It also means we have to reimplement a bit of the commit parsing. We
> can't just use parse_commit_buffer() here, because it expects an
> unparsed struct and wants to load everything, including parent links.
> But we don't know if the parent list has been munged during traversal,
> so it's not safe for us to touch it. Fortunately, it's quite easy to
> load just the tree, as it is always the first line of the commit object.
I was hoping that existing code to parse out the tree in
parse_commit_buffer() will become a call into this new helper
function, so that we avoid duplicating the logic.
> Moreover, this strategy does nothing if we lose access to the graph file
> unexpectedly (e.g., due to a system error).
Or simultaneous repack may lose the file from the filesystem,
perhaps?
> +static void load_tree_from_commit_contents(struct repository *r, struct commit *commit)
> +{
> + enum object_type type;
> + unsigned long size;
> + char *buf;
> + const char *p;
> + struct object_id tree_oid;
> +
> + buf = odb_read_object(r->objects, &commit->object.oid, &type, &size);
> + if (!buf)
> + return;
> +
> + if (type == OBJ_COMMIT &&
> + skip_prefix(buf, "tree ", &p) &&
> + !parse_oid_hex(p, &tree_oid, &p) &&
> + *p == '\n')
> + set_commit_tree(commit, lookup_tree(r, &tree_oid));
> +
> + free(buf);
> +}
Looks quite straight-forward. Don't you need to pay attention to
r->hash_algo and call parse_oid_hex_algop() instead?
Or are we pretty much sure that "r" is always "the_repository" here,
in which case parse_oid_hex() that uses "the_hash_algo" would be
sufficient?
Thanks.
next prev parent reply other threads:[~2026-05-19 5:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-19 5:05 [PATCH] commit: fall back to full read when maybe_tree is NULL Jeff King
2026-05-19 5:56 ` Junio C Hamano [this message]
2026-05-19 6:15 ` Jeff King
2026-05-20 16:22 ` Derrick Stolee
2026-05-19 6:25 ` Rasmus Villemoes
2026-05-20 16:20 ` Derrick Stolee
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=xmqqcxys7xi4.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=daniel.mach@suse.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=ravi@prevas.dk \
/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.