git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] commit: fall back to full read when maybe_tree is NULL

From
Junio C Hamano <gitster@pobox.com>
Date
May 19, 2026, 05:56 UTC
Message-ID
<xmqqcxys7xi4.fsf@gitster.g>
In-Reply-To
<20260519050513.GA1635924@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 6 quoted lines
> 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?

Show 20 quoted lines
> +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.
Previous: Jeff KingNext: Jeff King
Message 2 of 6 in “commit: fall back to full read when maybe_tree is NULL”
  1. commit: fall back to full read when maybe_tree is NULLJeff King, May 19, 2026
  2. Junio C HamanoMay 19, 2026
  3. Jeff KingMay 19, 2026
  4. Derrick StoleeMay 20, 2026
  5. Rasmus VillemoesMay 19, 2026
  6. Derrick StoleeMay 20, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.