Repository navigation
Conversation
The squash rule merged every point of a branch into every remote ref it compares with. On a kinisi_ros clone that was 824 merges for one row of `dl --ls`, 16 s to 18 s of git, and none of them could pass. Before the merges, one `rev-parse <ref>...<point>` per batch reads each pair's merge bases, and one `diff-tree --stdin` reads the paths each side changed since its base. A pair is not merged when holds_the_change_of must say no: no single merge base, a ref that changed nothing since the base, or a point that changes a path the ref left alone. A path the point added under a directory the ref deleted a file from is left to the merge, because merge.directoryRenames=true can move it. Answers are cached by (point, ref commit) across branches. Any refusal or output in another shape merges every pair, as before. The budget is charged as before, so the answer does not change.
Reviewer's GuideData structuresAdd the Git result types that carry merge-base and changed-path data for squash-pair screening.
APIAdd batched Git interfaces to read symmetric-range merge bases and changed paths before squash merges.
ImplementationParse and validate the batched Git outputs so malformed or incomplete answers cannot incorrectly rule out a pair.
Screen and cache squash pairs before merging, retaining pairs whenever pre-screening cannot prove they will fail and accounting for directory renames.
DocumentationDocument the squash-rule merge reduction and its measured performance improvement.
TestsTest Git invocation, parsers, empty-input behavior, and validation of batched merge-base and changed-path output.
Test squash-pair screening, safe fallbacks, merge budgeting, path and directory-rename behavior, and real-Git results.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report❌ Patch coverage is
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
blooop
left a comment
There was a problem hiding this comment.
This was generated by AI during review.
Review of #721 at b4771fc1, diff against its base fix/ls-unpushed-check-quadratic (merge base 2b8f8036) only.
Safety question
The squash rule guards dl rm and wf reap. A skip in worth_merging can only remove a pair from the merge batch, and the final answer still comes from holds_the_change_of on the pairs that are left, in the same order. So a skip cannot make a false "saved". The worst case for a wrong skip is a missed squash (a false "unsaved"), which is the safe direction. I tried to find even that case:
- No base / two or more bases, and base == ref commit.
holds_the_change_ofreturnsfalsefor each of these before it merges (merge-base --allgives the same bases asrev-parse <ref>...<point>; a base equal to the ref commit impliesother_tree == base_tree). No pair is lost. - The point changes a path the ref left alone. In a merge, a change on one side only comes through as that side has it. Rename detection on the ref side starts and ends only at paths the ref touched, and directory-rename moves only act on paths the point added. The exception keeps those.
- Real git, by hand (git 2.56.1): root-level "directory rename" (the ref moves every top-level file into
sub/and addssub/n.txt; the point addsn.txt). Git does not rename the top-level directory, so the merge keepsn.txtand the tree differs from the ref. The skip is correct. Rename-to-self (t6423 12i shape) givesCONFLICT (implicit dir rename), so the merge fails and the skip is correct. - Real git, randomized: 1,350 random (base, point, ref) repos. Each mixed adds, edits, deletes, file renames, directory renames (also to and from the top level), and mode flips. The ref was often a squash of the point plus more changes.
merge.directoryRenameswas set totrue,conflictorfalse. 689 pairs passed the merge-tree and tree check. The PR's skip predicate (re-implemented fromchanges_a_path_the_ref_kept, with the samediff-tree -r --no-renamesinput) skipped none of them. - Submodules, binary files, case-only renames,
merge.renames=falseand rename limits change no path that the point alone touches. They can only add conflicts, which the skip does not depend on. Ifdiff.ignoreSubmodules=allhides a gitlink, it hides it on both sides, so it can only stop a skip. - A refusal or output that the parser cannot read gives
truefor every pair it did not answer. The cache stores only answers that are sure.
I found no counterexample.
Standards
- Stale doc (minor). The doc comment on
Asked::passed_atstill says "Every point is merged into every remote ref the clone has in oneGit::trees_of_clean_merges". After this PR, only the pairs thatworth_mergingkeeps are merged. Update that sentence. - Duplicated Code (nit).
paths_changedcopies the tempfile-as-stdin block fromtrees_of_clean_merges(NamedTempFile::new().ok().filter(write), thenSpawnSpec ... with_stdin_file). A small helper would hold both. This is not blocking. - Data Clumps (nit).
(String, String)as thecould_passkey, and(&str, &str)as a diff, are positional pairs. The doc comments say which side is which, so this is acceptable. - The names (
worth_merging,changes_a_path_the_ref_kept,directories_above,PairBases,Change) say what they mean. The parsers fail closed (to "merge everything"), and tests cover each malformed shape. - PR body: it gives the why, the evidence, each skip condition and its safety argument, and it matches the code at this head.
- Local checks at
b4771fc1:cargo test --locked --workspacepassed (all 39 test binaries ok).cargo clippy --locked --all-targets -- -D warningspassed.
Spec
No spec available. The PR closes no issue, and its commits reference none. I did not infer requirements from the code.
Verdict
Approve. No finding blocks this PR. The stale passed_at doc is worth a one-line fix before merge, or in a follow-up.
… keeps The comment still said every point is merged into every remote ref.
The squash rule in
dl --ls,dl rmandwf reapnow merges only the pairs that can pass. On a kinisi_ros clone, the rule fell from about 19 s to about 5 s, with the same answer.Stacked on #720 — one copy-rule question per branch. Merge that PR first.
In short
The squash rule finds a branch that GitHub squashed into a remote ref. It asks one question of each pair: does the merge of this point (a commit on the branch) into this ref give the ref's tree?
holds_the_change_ofmakes the final check.Before this PR, the rule merged every point into every ref first, in one
merge-tree --stdinper branch. On a kinisi_ros clone, one--lsrow made 824 merges. Each merge took 20 ms to 240 ms, most of it in rename detection. That was 16 s to 18 s of git, and no pair could pass.Now two cheap git calls come before the merges. They find the pairs where
holds_the_change_ofmust answerfalse, and the rule does not merge those pairs. If either call fails, or prints output in a shape the parser does not know, the rule merges every pair, as before.Evidence
The bench is a
cp -acopy of a real kinisi_ros workspace. It timesaccount_of, the call that runs the squash rule. Release build, same host, same copy:holdsoutput is the same byte for byte in every run: md57277c0862ec816463c716559923ac65c.A debug run with a wrapper that times each git call:
merge-tree --stdincalls that took 16.1 s.merge-tree --stdincalls, 5diff-treecalls that took 1.95 s, 6rev-parsecalls for the bases.What changes
Asked::worth_mergingruns beforetrees_of_clean_merges. It uses two new git calls:Git::merge_bases_of: onerev-parse <ref>...<point>for all pairs in one spawn. For a symmetric range,rev-parseprints the point, the ref's commit, and each merge base with a^before it. These are the bases thatmerge-base --allgives. I checked that the two agree on all 443 different pairs of the bench copy.Git::paths_changed: onediff-tree --stdin -r --no-renames --name-status -z --always. Each input line is<commit> <base>, so git lists the paths that each side changed since the merge base.The rule does not merge a pair when one of these is true:
holds_the_change_ofsaysfalsefor these.holds_the_change_ofsaysfalse.changes_a_path_the_ref_kept). The merge then brings in the point's version of that path, so the merged tree is not the ref's tree.One exception to the path check: a path that the point added, under a directory where the ref deleted a file. With
merge.directoryRenames=true, git can move that file into the renamed directory. The rule leaves that pair to the merge.A cache keyed by (point, ref commit) keeps each answer across branches. Two branches on one commit ask the same pairs. The merge budget (
MERGE_BUDGET) counts every pair, as before, so the same branches fit.Review of the skip conditions
The squash rule stops
dl rmandwf reapfrom deleting commits. So a skipped pair must be a pair that the merge would reject. I checked each condition against git 2.56.1:CONFLICT (implicit dir rename): Existing file/dir at D2/name in the way. The skip is safe there.merge.directoryRenames=truethis merge is clean and passes. The exception above keeps this pair. A real-git test pins it.I removed no skip condition.
Tests
pair_bases_inandpaths_changed_in: parser tests for one, two and no bases, SHA-256 names, paths with a space and a newline, empty diffs, and every malformed shape (each reads as no answer).a_point_that_changes_a_path_the_ref_kept_cannot_pass: the path check, with the directory-rename exception at each depth.the_squash_rule_merges_no_pair_that_cannot_pass: counts merges. Each skip condition makes 0 merges. A refusal or an unreadable answer from either git call makes the 2 merges of before, and clears the commit.real_git_answers_rule_out_pairs_before_any_merge: the parsers against real git output.a_squash_that_renamed_the_directory_the_branch_added_to_is_found: real git,merge.directoryRenames=true.the_squash_rule_makes_no_more_merges_than_its_budget: now also asserts onerev-parseof the bases per merged branch.I removed the directory-rename exception for one run: two tests failed. I turned the skip off for one run: two tests failed.
Local results on this branch:
cargo test --locked --workspace --no-fail-fast: all pass exceptclosing_the_terminal_mid_up_removes_the_token_file_and_kills_the_upindl/tests/interrupt. That test failed only in full-suite runs while the host load average was 20 to 80. It passed 3 of 3 times alone on this branch, and alone on the base branch. It does not touch the squash rule.cargo clippy --locked --all-targets -- -D warnings: pass.cargo fmt --check: pass.prekon the changed files: pass.🤖 Generated with Claude Code
Summary by Sourcery
Pre-filter squash candidates so only pairs that could pass are merged, substantially reducing unsaved-change checks without changing their results.
Bug Fixes:
Enhancements:
Tests: