Skip to content

revwalk: don't use the commit-graph in shallow or grafted repos - #7489

Open
Grinv wants to merge 1 commit into
libgit2:mainfrom
Grinv:shallow-commit-graph
Open

Grinv wants to merge 1 commit into
libgit2:mainfrom
Grinv:shallow-commit-graph

Conversation

@Grinv

@Grinv Grinv commented Nov 20, 2026

Copy link
Copy Markdown

A revwalk takes parents from the commit-graph, while git_commit_lookup() applies shallow roots and grafts, so in a shallow repository with a commit-graph the walk goes past the shallow boundary. git never writes a graph in a shallow repository but keeps an existing one, even across gc, so this happens after git fetch --depth on a full clone. With testrepo.git and shallow set to be3563a, the walk from HEAD returns 7 commits instead of 2.

Like git's commit_graph_compatible(), the new git_repository__commit_graph_compatible() rejects the graph when grafts or shallow roots are present (libgit2 has no replace refs). git_commit_list_parse(), the only reader of graph parents and generation numbers, checks it.

The new tests (shallow roots and info/grafts) fail without the change; the full suite passes on Linux. libgit2 1.9 is less affected only because it can't open graphs with generation-v2 data.

Not in this PR:

  • The commit-graph writer has the same gap: in a shallow clone it writes the grafted parents, and after git fetch --unshallow git itself stops at the old boundary (git commit-graph verify: "parent list for commit ... terminates early"). I can send a separate PR.
  • libgit2 doesn't read core.commitGraph.

Related: #7487.

Prepared with Claude Code; I reviewed the changes.

git_commit_list_parse() took parents from the commit-graph whenever
one was present, while git_commit__parse_ext() applies grafts and
shallow roots. In a shallow repository that still has a commit-graph
from before it became shallow (git leaves it in place, even across
gc), a revwalk went past the shallow boundary.

Like git's commit_graph_compatible(), don't use the commit-graph while
grafts or shallow roots rewrite parents. The graph's generation numbers
come from the real parents too, so the whole graph is skipped rather
than only the grafted commits.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant