feat(clones): git-ast clones — structural clone detection (identity index, first slice) - #45
Merged
Merged
Conversation
tree-sitter 0.22 → 0.26.10 tree-sitter-rust 0.21 → 0.24.2 tree-sitter-html 0.20 → 0.23.2 Both grammar call sites updated: language() fn → LANGUAGE.into(), which is the canonical API since the 0.23 grammar series. All 97 unit tests and 5 cucumber tests pass unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ntity index First concrete step of prx-nf1f (identity-index). The subtree_hashes and shape_hash produced by inspect are computed per-file and then discarded. This commit accumulates them across a file set and surfaces equivalence classes — definitions with identical bodies under the canonical form, regardless of declared name. Design: - src/clones.rs: find_clones(&[(&str, &[Def])]) → Vec<CloneGroup>, keyed by shape_hash (BTreeMap for deterministic output). Groups with >1 occurrence are structural clones; single occurrences are filtered out. - Exact by construction: equal shape_hash ⟹ same canonical body. No threshold, no heuristics — that layer (MinHash+LSH over subtree_hashes) is explicitly deferred to the research note. - Routes by file extension (html/htm → html::inspect, else printer::inspect) matching the existing inspect/match/blame dispatch. CLI: git-ast clones FILE... Output: shape_hash N×kind\n file name\n per occurrence, one block per group. 11 new unit tests (108 total), all passing. Smoke-tested against the repo's own source (no false clones) and against two files with a known shared body (correctly groups 3 occurrences under one shape hash). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
bdelanghe
force-pushed
the
feat/identity-index-clones
branch
from
June 29, 2026 17:12
e4fa22d to
15d5784
Compare
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
src/clones.rswithfind_clones()— groupsDefs byshape_hashacross files, surfaces groups with >1 occurrence as structural clonesgit-ast clones FILE...verb wired intomain.rswith extension-based dispatch (mirrorsinspect)prx-nf1f(identity index): thesubtree_hashes/shape_hashcomputed per-file are now accumulated rather than discardedWhy this is the right first slice:
The
shape_hashis already an exact equivalence-class key by construction — equal hash ⟹ same canonical body. No threshold, no heuristics. The identity-index research note calls the occurrence map "trivial"; this PR makes it real, in memory, over a provided file set. The fuzzy/near-clone layer (MinHash + LSH oversubtree_hashes) is explicitly deferred.Example output:
Groups are sorted by
shape_hash(BTreeMap), occurrences in file-then-definition order.Test plan
printer::inspectPR checklist
find_clonesis pure post-processing;inspectdispatch is one patternsrc/clones.rs,src/lib.rs,src/main.rs🤖 Generated with Claude Code