rev-parse: honor .git/info/grafts when resolving commit parents#45
Open
mizchi wants to merge 1 commit into
Open
rev-parse: honor .git/info/grafts when resolving commit parents#45mizchi wants to merge 1 commit into
mizchi wants to merge 1 commit into
Conversation
The "large graft octopus" subtest in upstream t6101 sets up 40 orphan commits and grafts them into a chain via `.git/info/grafts` (one 40-OID line declaring commit b1's parents as b2..b40), then asserts `rev-parse --verify b1^30 == b31`. bit's rev-parse ignored grafts and read parents straight from the commit object, so the 30th parent lookup failed. The graft file lives at `<git_dir>/info/grafts`. Each non-comment line is `<commit-id> <parent-id> <parent-id>...`. If a line matches the commit being resolved, its parents replace the commit's natural parents. Both `commit_nth_parent` implementations need the fix: - `src/lib/revparse.mbt` (used by lib/cmd consumers that go through `@bitlib`). - `src/repo_ops/revparse_ops.mbt` (the implementation reached from `git rev-parse` in cmd/bit/rev_parse.mbt via `@bitrepo`). Each grew a `revparse_read_graft_parents` helper that parses the graft file and a thread of `git_dir` into `commit_nth_parent`. The caret (`^N`) and tilde (`~N`) suffix walkers now resolve parents via the grafted list when one exists, falling back to `info.parents` otherwise. The known-breakage patch `tools/git-patches/t6101-rev-parse-parents-grafts.patch` (which gated the assertion behind a `BIT_GRAFTS` prereq that nothing sets) is removed; upstream's test now runs verbatim and passes. Verified locally: t6101 subtest #17 "large graft octopus" goes from SKIP (with patch) to PASS (without patch + this fix). https://claude.ai/code/session_01M3TPgeGLDKQxep3AAYpDVs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix the
large graft octopussubtest in upstreamt6101-rev-parse-parents:rev-parsenow honours.git/info/graftswhen resolving commit parentsthrough
^N/~Nsuffixes. The known-breakage patch that gated theassertion behind a
BIT_GRAFTSprereq is removed; the subtest runsverbatim and passes.
What changed
The graft file at
<git_dir>/info/graftscontains one entry pernon-comment line:
<commit-id> <parent-id> <parent-id>.... When a linematches the commit being resolved, its parents replace the commit's
natural parents.
Two
commit_nth_parentimplementations needed the same treatment:src/lib/revparse.mbt(reached via@bitlib).src/repo_ops/revparse_ops.mbt(reached fromgit rev-parseinsrc/cmd/bit/rev_parse.mbtvia@bitrepo— this is what t6101'sgit rev-parse --verify b1^30actually hits).Each grew a small
revparse_read_graft_parentshelper that parses thegraft file once and
git_dirwas threaded intocommit_nth_parent.The caret/tilde walkers fall back to
info.parentswhen no graftapplies, so non-grafted repos see no behaviour change.
src/repo_ops/moon.pkggained an import ofmizchi/bit/string_utilsfor the existing
trim_string/whitespace handling used by the newhelper.
Why two implementations?
src/lib/revparse.mbtandsrc/repo_ops/revparse_ops.mbtare bothpublic APIs (
@bitlib.rev_parsevs@bitrepo.rev_parse), used bydifferent downstreams. Consolidating them is out of scope for this
fix.
Test plan
large graft octopus):SKIP → PASS under the strict shim. Other subtests unchanged
(one pre-existing unrelated failure:
rev-list merge^-3 (invalid parent)).git rev-parse --verify b1^30returns b31's hex.https://claude.ai/code/session_01M3TPgeGLDKQxep3AAYpDVs
Generated by Claude Code