Repository navigation
fix(gitindex): honor ignore files and branch membership in delta builds - #36
Merged
Merged
Conversation
…to another branch A document carries every branch that has its blob at its path. When a delta build saw a file added on a branch, it indexed a new document for that branch alone and left the older shards untouched. If another branch already had the same file, the index ended up with two documents for it, each on a subset of the branches. A search that required both branches missed the file, and a search that excluded one of them still found it. A delta build now handles an added file the way it handles a modified or deleted one: it indexes the file's current version from every branch and tombstones the path in the older shards. It skips the tombstone when the file is new to its branch and no other branch has it, since no older shard has that path. The delta tests now compare each delta build with a clean normal build of the same commits, including the branches of every document. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…uild indexes A normal build leaves out the files that a branch's .sourcegraph/ignore matches. A delta build never read the ignore file. It only fell back to a normal build when the ignore file itself changed. So when a tracked file under an ignored path was added or modified, the delta build indexed it and its contents became searchable. A delta build now reads the ignore file at each branch's current commit. It skips a change to a path that the changed branch ignores, and it leaves a branch off a document when that branch ignores the path. A change to the ignore file still falls back to a normal build, because it can add or remove files that the diff doesn't mention. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A delta build diffs every branch against its last indexed commit. When several branches picked up the same commit, each branch's diff reported the same paths. For each report, the build looked the path up on every branch and added those branches to the document again. So the work grew with the square of the number of branches, and a document listed the same branch many times. Modified and deleted files already behaved this way. The two previous commits made added files do it too. The step that removed the repeated branches never took effect, because it wrote to a copy of the document. Documents are ranked by how many branches they list, so a file on two branches could rank above an otherwise identical file on three. A delta build now collects the changed paths from all the diffs first. It takes a branch's version of a path from that branch's diff, and looks the path up only on the branches that didn't change it. Those lookups read each directory once and share it between branches. A branch is added to a document once. A path is tombstoned if any branch had the file at its last indexed commit, whichever branch comes first. A file that is new to every branch that has it gets no tombstone. The build reads file modes from the diff instead of loading both versions of each file. Two things follow. A file that a submodule replaces, or the reverse, is now handled. Before, the change was skipped. And a change to a file whose content the clone doesn't have (a clone with a blob size filter) no longer makes the delta build fall back to a normal build. 64 branches fast-forwarding to a commit with 1,000 new files took 62s and 307 MiB before this commit. It now takes 0.46s and 110 MiB. The same with 1,000 modified files went from 67s to 0.40s. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.
Part of SOU-2867
Summary
Fixes four problems with delta builds (
zoekt-git-index -delta). The first three left the index returning different results from a full build of the same commits. Sourcebot is about to turn delta builds on, so these need to land first..sourcegraph/ignoreexcludes was indexed when it was added or modified, even though the ignore file had not changed.mainarrived onrelease(for example by a fast-forward), the index held two documents for it, one per branch.branch:main branch:releasemissed the file, andbranch:main -branch:releasefound it.Cause
All four are in
prepareDeltaBuildingitindex/index.go, which diffs each branch's last indexed commit against its current one.Fix
Effect on when a delta build can run
There is no new fallback to a full build.
.sourcegraph/ignoreitself still falls back, because changed rules can add or remove files that the diff doesn't mention. The error text is unchanged, since callers match on it.--filter=blob:limit=...), a change to such a file used to fail the diff withobject not found, and the build fell back. The delta build now runs and returns the same results as a full build.Performance
Wall time and peak memory of one delta build that changes 1,000 files. The repository has 3,700 files and is packed. Each figure is the median of two to six runs on one laptop, except the 67 s run, which ran once.
mainThe two "adds" rows with one branch are the only place this PR does more work than
main. To keep one document per file, an added path has to be looked up on the other branches. That costs about 0.4 µs per path and branch.If you measured an earlier revision of this PR (
5634b7f): it had the square-of-branches cost for added files too (62 s and 307 MiB in the first row). The third commit removes it.Tests
TestIndexDeltaBasicnow builds a clean full index after every delta step and compares the documents and their branches with the delta index. It also checks that no document lists a branch twice, which fails onmain. New cases cover the ignore rules, a file reaching a second branch, and a file that is deleted on one branch and added on another in the same build, in both branch orders.go test ./...passes.zoekt-git-indexandzoektbinaries, on this branch and with these commits applied onto feat(index): support more than 64 branches per repository #35's head (8b64c6f):5634b7fthe order was reversed.main.Notes for reviewers
main. feat(index): support more than 64 branches per repository #35 doesn't touchgitindex/, and these commits apply onto it cleanly.🤖 Generated with Claude Code
Note
Medium Risk
Changes core delta indexing logic that must stay equivalent to full builds for search correctness; large refactor with broad test coverage but high impact on incremental indexing.
Overview
Delta git indexing (
prepareDeltaBuild) is reworked so incremental builds match full indexes and scale when many branches move together.Per-branch
.sourcegraph/ignoreis loaded at each branch’s tip and applied when selecting paths to index (changes to the ignore file itself still force a full build). Changed paths are aggregated across branch diffs and handled once: branches that changed a path use the diff version; unchanged branches get the current tree entry via a sharedtreeFilescache. Documents list each branch at most once, and paths that existed in older shards are tombstoned so shared multi-branch blobs stay consistent. File vs non-file changes use diff tree modes (isIndexedFile) instead of loading both blob sides.Tests add multi-branch and ignore scenarios, assert no duplicate branch labels on documents, and compare every delta step to a clean normal build (including branch membership).
Reviewed by Cursor Bugbot for commit 36e5276. Bugbot is set up for automated code reviews on this repo. Configure here.