Skip to content

fix(web): use blame line's path when navigating to commit diff#1178

Merged
brendan-kellam merged 3 commits intomainfrom
brendan/fix-blame-rename-path
May 6, 2026
Merged

fix(web): use blame line's path when navigating to commit diff#1178
brendan-kellam merged 3 commits intomainfrom
brendan/fix-blame-rename-path

Conversation

@brendan-kellam
Copy link
Copy Markdown
Contributor

@brendan-kellam brendan-kellam commented May 6, 2026

Summary

  • When a file has been renamed, blame lines may be attributed to commits where the file existed at a different path. Clicking a commit in the blame gutter previously navigated using the current file path, which could resolve to a file that didn't exist at that commit.
  • Capture the per-commit filename field from git blame --porcelain (emitted only on the first global appearance of each commit) and attach it as path to each blame range.
  • Plumb the blame line's path through LineEntry and onCommitClick so the commit-click handler navigates to the correct historical path.

While doing this I also discovered (and fixed) a parser bug: my first attempt assumed filename was emitted on every group's metadata block, but porcelain only emits the metadata block on the first global appearance of each commit. The fix caches filename per commit hash and looks it up when emitting each range. This was reproducible on lighthouse/test/syncYearlySubscription.test.ts, where commit 4940d85b has groups starting at lines 1 and 8 — line 8's group has no metadata block.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Blame gutter commit navigation now follows the file path as it existed in each commit, fixing navigation after renames so links open the correct historical file version.
  • Documentation
    • Blame range metadata and public API docs updated to include the historical file path for each attribution entry.

When a file has been renamed, blame lines may be attributed to commits
where the file existed at a different path. Previously, clicking a
commit in the blame gutter navigated using the current file path, which
could resolve to a file that didn't exist at that commit.

Capture the per-commit `filename` field from `git blame --porcelain`
(emitted only on the first global appearance of each commit) and attach
it as `path` to each blame range. Plumb it through `LineEntry` so the
commit-click handler navigates to the correct historical path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions

This comment has been minimized.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c3708f33-5b9f-4b69-8272-0e17a0333b5b

📥 Commits

Reviewing files that changed from the base of the PR and between 8dd636f and f24c884.

📒 Files selected for processing (1)
  • docs/api-reference/sourcebot-public.openapi.json

Walkthrough

Blame ranges now include the historical file path (path) from git blame output. The parser emits ranges with path, the blame range schema and OpenAPI are updated, and the UI propagates {hash,path} through blame gutter handlers and navigation callbacks.

Changes

Blame Path Tracking for Historical Navigation

Layer / File(s) Summary
Data Shape
packages/web/src/features/git/schemas.ts, docs/api-reference/sourcebot-public.openapi.json
Added path: string to blame range schema and the public OpenAPI PublicFileBlameResponse.ranges item; path is required and describes the file path at the attributing commit.
Parsing & Range Construction
packages/web/src/features/git/getFileBlameApi.ts
Added filenameByHash tracking while parsing porcelain blame, populate path for emitted ranges, and extend coalescing logic to require equal path when merging adjacent ranges.
UI Rendering & Types
packages/web/src/app/.../blameGutterExtension.ts
Extended LineEntry and blame marker types to include path; updated buildCellDom, BlameMarker signature and equality logic to accept/compare commit objects { hash, path }; line index entries now include path.
Handler Integration
packages/web/src/app/.../pureCodePreviewPanel.tsx
Refactored blame-click handler to accept the composite { hash, path } and navigate using the provided historical path and hash.
Documentation
CHANGELOG.md
Added Fixed entry describing that blame gutter commit navigation now uses historical file paths to navigate correctly after renames.

Sequence Diagram(s)

sequenceDiagram
  participant User as User
  participant UI as Browser UI
  participant Router as Router
  participant API as Server API
  participant Parser as Git Blame Parser
  participant Repo as Git Repo

  User->>UI: Click blame gutter commit
  UI->>Router: onCommitClick({hash, path})
  Router->>API: Request file at commit (path, hash)
  API->>Parser: parseBlame(path, hash)
  Parser->>Repo: git blame --porcelain (path@hash)
  Repo-->>Parser: blame output (includes filename metadata)
  Parser-->>API: ranges with path populated
  API-->>Router: file/commit response
  Router-->>UI: Navigate to file view at commit
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • sourcebot-dev/sourcebot#1160: Modifies blame UI handlers and extends blame click/reblame signatures in parallel with this PR's callback restructuring.
  • sourcebot-dev/sourcebot#1158: Introduced the blame feature that this PR extends by adding historical path tracking to blame ranges and updating parsing, schema, and UI layers.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: fixing blame gutter to use the historical file path when navigating to commits, which aligns with the core problem and solution in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch brendan/fix-blame-rename-path

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

brendan-kellam and others added 2 commits May 5, 2026 20:54
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@brendan-kellam brendan-kellam merged commit fdb05c0 into main May 6, 2026
8 of 9 checks passed
@brendan-kellam brendan-kellam deleted the brendan/fix-blame-rename-path branch May 6, 2026 05:56
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