From: Patrick Steinhardt <ps@pks.im>
To: Kristofer Karlsson via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Derrick Stolee <stolee@gmail.com>,
Taylor Blau <me@ttaylorr.com>, Jeff King <peff@peff.net>,
Kristofer Karlsson <krka@spotify.com>
Subject: Re: [PATCH v2 2/2] fetch: write commit-graph using updated refs only
Date: Wed, 7 Oct 2026 08:39:11 +0200 [thread overview]
Message-ID: <asXpD2YB_MpunVFs@pks.im> (raw)
In-Reply-To: <7507354cc97bb63b3bcdc4a089b5387da28500a0.1791279992.git.gitgitgadget@gmail.com>
On Tue, Oct 06, 2026 at 09:46:32AM +0000, Kristofer Karlsson via GitGitGadget wrote:
> From: Kristofer Karlsson <krka@spotify.com>
>
> When fetch.writeCommitGraph was introduced in
>
> 50f26bd035 (fetch: add fetch.writeCommitGraph config
> setting, 2019-09-02),
Tiny nit, not worth a reroll and something I missed in the first round:
it's rather uncustomary to have this commit stand out like this, we
typically have it embedded in the free-flowing text.
> the stated goal was to stay updated with the latest commits after
> fetching new objects. The implementation used
> write_commit_graph_reachable() because it was the only API available,
> but two things have changed since then:
>
> 1. write_commit_graph() was added, and it accepts an explicit set of
> commits as seeds, enabling more targeted commit-graph updates.
>
> 2. The ref-scanning callback add_ref_to_set() became more expensive
> in
> 630cd5194e (commit-graph.c: peel refs in 'add_ref_to_set',
> 2020-07-22)
Likewise.
> when it started to validate the refs against the odb
> for correctness. On a repository with many refs, this makes the
> full reachable scan unnecessarily costly for a targeted fetch.
>
> Optimize the commit-graph write by using only the newly updated refs
> as seeds instead of scanning all refs after every fetch. To keep
> this change small, skip the optimization for multi-remote fetches
> (since that would require propagating the set of refs across process
> boundaries).
>
> Since do_fetch() already knows which refs were updated, collect them
> into an oidset and then pass them directly to write_commit_graph().
> fetch always writes the commit-graph in split mode, so this adds a
> new layer on top of the existing chain rather than replacing it:
> close_reachable() walks from the updated tips and stops at commits
> already present in the graph, so the new layer only contains the
> newly fetched history, and commits covered by the existing layers
> remain covered. This relies on split mode; a non-split write would
> replace the graph with just the closure of the seeds.
The part about split commit graphs is important to point out here, as
this is what we rely on to make this whole infra even work. The other
parts about how we collect the object IDs feels overly verbose though,
as you're basically just explaining the diff without providing much
context.
> The reachability closure also covers auto-followed tags, since their
> targets are reachable from the fetched tips that caused them to be
> auto-followed.
This piece of information feels a bit random to me. Tags aren't even
part of the commit graph, are they? And for auto-followed tags we'd
of course naturally cover the commits they point to, but that's just
business as usual and nothing that we specifically had to make sure
keeps on working, right?. So I wonder why this is explicitly being
pointed out now.
> Refs that are rejected because they would require changes to
> .git/shallow are skipped, just like store_updated_refs() does. Their
> objects are received but their history is incomplete, so walking from
> them would make the commit-graph write fail.
And this bordering on the line of getting too verbose, as well. You
already explain this in code with a comment already, so you're basically
just repeating that.
> diff --git a/builtin/fetch.c b/builtin/fetch.c
> index 533fdfe7d8..574c361530 100644
> --- a/builtin/fetch.c
> +++ b/builtin/fetch.c
> @@ -1903,10 +1903,34 @@ out:
> return retcode;
> }
>
> +static void collect_updated_tips(struct oidset *tips, struct ref *ref_map)
> +{
> + struct ref *rm;
> + for (rm = ref_map; rm; rm = rm->next) {
> + struct commit *commit;
> + /*
> + * Like store_updated_refs(), skip shallow-rejected refs:
> + * they are not stored, and their history is incomplete.
> + */
Okay. It's unclear why the reference to `store_updated_refs()` exists
here, as it doesn't seem to give me any useful context. But the other
part about why we skip this is helpful.
> diff --git a/t/t5537-fetch-shallow.sh b/t/t5537-fetch-shallow.sh
> index f323ceebd2..624bd124be 100755
> --- a/t/t5537-fetch-shallow.sh
> +++ b/t/t5537-fetch-shallow.sh
> @@ -135,6 +135,34 @@ test_expect_success 'fetch that requires changes in .git/shallow is filtered' '
> )
> '
>
> +test_expect_success 'fetch.writeCommitGraph skips refs that require changes in .git/shallow' '
> + git clone --no-local --depth=2 .git shallow-graph &&
> + (
> + cd shallow-graph &&
> + git checkout --orphan no-shallow &&
> + commit no-shallow
> + ) &&
Can't we instead:
git -C shallow-graph checkout --orphan no-shallow &&
test_commit -C shallow-graph no-shallow
> + git init notshallow-graph &&
> + git -C notshallow-graph -c fetch.writeCommitGraph=true \
> + fetch ../shallow-graph/.git "refs/heads/*:refs/remotes/shallow/*" &&
> + (
> + cd shallow-graph &&
> + commit no-shallow-2
> + ) &&
And likewise, `test_commit -C shallow-graph no-shallow-2`?
> + rejected=$(git -C shallow-graph rev-parse main) &&
> + (
> + cd notshallow-graph &&
> + git -c fetch.writeCommitGraph=true \
> + fetch ../shallow-graph/.git "refs/heads/*:refs/remotes/shallow/*" &&
> + git for-each-ref --format="%(refname)" >actual.refs &&
> + echo refs/remotes/shallow/no-shallow >expect.refs &&
> + test_cmp expect.refs actual.refs &&
> + test-tool read-graph commit-info shallow/no-shallow &&
> + test_expect_code 1 \
> + test-tool read-graph commit-info $rejected 2>/dev/null
Okay. So if I understand correctly, this test here verifies that we can
read the non-shallow commit from the graph, but not the shallow one.
Makes sense.
> + )
> +'
Thanks!
Patrick
next prev parent reply other threads:[~2026-10-07 6:39 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-02 8:33 [PATCH 0/2] fetch: write commit-graph using updated refs only Kristofer Karlsson via GitGitGadget
2026-10-02 8:33 ` [PATCH 1/2] test-tool read-graph: add commit-info subcommand Kristofer Karlsson via GitGitGadget
2026-10-02 8:33 ` [PATCH 2/2] fetch: write commit-graph using updated refs only Kristofer Karlsson via GitGitGadget
2026-10-02 11:22 ` Patrick Steinhardt
2026-10-02 12:40 ` Kristofer Karlsson
2026-10-05 6:27 ` Patrick Steinhardt
2026-10-05 14:47 ` Kristofer Karlsson
2026-10-06 9:46 ` [PATCH v2 0/2] " Kristofer Karlsson via GitGitGadget
2026-10-06 9:46 ` [PATCH v2 1/2] test-tool read-graph: add commit-info subcommand Kristofer Karlsson via GitGitGadget
2026-10-06 9:46 ` [PATCH v2 2/2] fetch: write commit-graph using updated refs only Kristofer Karlsson via GitGitGadget
2026-10-07 6:39 ` Patrick Steinhardt [this message]
2026-10-07 7:33 ` Kristofer Karlsson
2026-10-07 14:22 ` [PATCH v3 0/2] " Kristofer Karlsson via GitGitGadget
2026-10-07 14:22 ` [PATCH v3 1/2] test-tool read-graph: add commit-info subcommand Kristofer Karlsson via GitGitGadget
2026-10-07 14:22 ` [PATCH v3 2/2] fetch: write commit-graph using updated refs only Kristofer Karlsson via GitGitGadget
2026-10-08 6:01 ` Patrick Steinhardt
2026-10-08 6:49 ` Kristofer Karlsson
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=asXpD2YB_MpunVFs@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=krka@spotify.com \
--cc=me@ttaylorr.com \
--cc=peff@peff.net \
--cc=stolee@gmail.com \
/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