Skip to content

feat: share fetch state across branches in the same local repo#718

Open
matt2e wants to merge 3 commits into
mainfrom
shared-fetch-state
Open

feat: share fetch state across branches in the same local repo#718
matt2e wants to merge 3 commits into
mainfrom
shared-fetch-state

Conversation

@matt2e
Copy link
Copy Markdown
Contributor

@matt2e matt2e commented May 12, 2026

Summary

  • Adds a repo-level fetch cache so that when multiple branches share the same local .git directory, only one network fetch is needed per TTL window
  • New branches that appear after a repo-wide fetch trigger a cheap narrow fetch for just the missing refspecs (without --prune)
  • Fixes needs_fetch to consult the repo-level cache so timeline's two-stream decision stays consistent
  • Fixes a bug where fetched_refspecs was being extended on full fetches instead of reset

Test plan

  • Unit tests for repo_key_from_local_cache_key covering normal paths, Windows paths, same branch/base, non-local keys, and too-few segments
  • CI passes (crates-fmt, crates-test, crates-lint, staged-ci, differ-ci)

🤖 Generated with Claude Code

matt2e and others added 3 commits May 12, 2026 15:25
Add a repo-level fetch cache keyed by repo path so that when multiple
branches share the same local .git directory, a single git fetch
satisfies all of them within the TTL window. Implements "Option C" from
the plan: the repo-level TTL gates the "did we recently talk to the
remote?" decision, while per-branch refspec tracking ensures any new
refspecs get a cheap narrow fetch (without --prune) when the repo is
already fresh. Remote projects continue using per-branch caching
unchanged.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Matt Toohey <contact@matttoohey.com>
Cover normal Unix path, Windows-style path with colons, branch==base
edge case, non-local prefix rejection, and too-few-segments rejection
to lock in the double rsplit_once parsing invariant.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Matt Toohey <contact@matttoohey.com>
On a full fetch (TTL expired, --prune), replace the repo-level
fetched_refspecs set with exactly the needed refspecs rather than
extending the existing set. This prevents unbounded growth from
branches that were opened and later closed. Narrow fetches (within
TTL, filling gaps) continue to extend additively as before.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Matt Toohey <contact@matttoohey.com>
@matt2e matt2e requested review from baxen and wesbillman as code owners May 12, 2026 09:53
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