feat(file_history): add --pin-local for working-tree pinning#158
Merged
dlyongemallo merged 4 commits intomainfrom May 6, 2026
Merged
feat(file_history): add --pin-local for working-tree pinning#158dlyongemallo merged 4 commits intomainfrom
--pin-local for working-tree pinning#158dlyongemallo merged 4 commits intomainfrom
Conversation
Add `Diff2HorPinned` / `Diff2VerPinned`. They declare
`shared_symbols = { 'b' }`, so `FileEntry:destroy` skips window `b`
and the view-owned `vcs.File` survives entry swaps. Dead code until
wired up.
Add `pin_local`, `pinned_path`, `pinned_b_file_for` to `LayoutOpt`. Git/hg `parse_fh_data` (and git's line-trace variant) honour them by setting `revs.b = LOCAL` and resolving the b-side through the view's cache. `FileEntry.with_layout` reuses an explicit `pinned_b_file`.
There was a problem hiding this comment.
Pull request overview
Adds a new pinned working-tree mode for file history (--pin-local / view.file_history.pin_local) so users can browse commit history while keeping the right-hand diff window bound to the live (LOCAL) file, including support for a synthetic “Working tree” top-of-history entry and commit entries that don’t touch the pinned file.
Changes:
- Introduces
pin_localplumbing across FileHistoryView/Panel, adapters (git/hg), and a pair of pinned Diff2 layouts that share the RHSvcs.Fileinstance across entries. - Adds overlay
FileEntrysupport for pinned paths not present in a commit (with adapter probes viafile_exists_at_rev) and fixes navigation/highlight behavior around those overlays. - Expands functional test coverage across layouts, adapters, panel autocmd dispatch, and pinned-mode behaviors.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| lua/diffview/vcs/rev.lua | Documents the pin_local_synthetic rev flag used by pinned layouts for synthetic entries. |
| lua/diffview/vcs/log_entry.lua | Adds lifecycle management for cached pinned-path overlay FileEntrys. |
| lua/diffview/vcs/adapters/null/init.lua | Implements file_exists_at_rev() stub for the null adapter. |
| lua/diffview/vcs/adapters/hg/init.lua | Adds pin-local handling (history scope, synthetic local entry, file existence probe, entry construction changes, completion flag). |
| lua/diffview/vcs/adapters/git/init.lua | Adds pin-local handling (history scope incl. -L, synthetic local entry, file existence probe, entry construction changes, completion flag). |
| lua/diffview/vcs/adapter.lua | Adds new adapter APIs (history_scope, build_local_log_entry, file_exists_at_rev) and central helper build_pin_local_file_entry(). |
| lua/diffview/ui/panel.lua | Fixes autocmd dispatch so buffer-scoped events like CursorMoved reach panel subscribers. |
| lua/diffview/tests/functional/pin_local_spec.lua | New end-to-end functional test suite for pin-local behavior (overlays, navigation, cursor-follow, lifecycle). |
| lua/diffview/tests/functional/panel_spec.lua | Adds tests validating Panel:on_autocmd dispatch for CursorMoved. |
| lua/diffview/tests/functional/layouts_spec.lua | Adds tests for pinned Diff2 layout semantics (should_null, ownership, swap detach behavior, name resolution). |
| lua/diffview/tests/functional/hg_adapter_spec.lua | Adds tests for hg pin-local parsing, history scope, synthetic local entry, and file_exists_at_rev. |
| lua/diffview/tests/functional/git_adapter_spec.lua | Adds tests for git pin-local parsing, history scope (incl. globs/-L), synthetic local entry, and caching behavior. |
| lua/diffview/tests/functional/file_entry_spec.lua | Adds tests for pinned_b_file reuse, missing-local fallbacks, and extra-owned lifecycle. |
| lua/diffview/scene/views/file_history/render.lua | Avoids nil-hash crash for synthetic “Working tree” entries in perf labeling. |
| lua/diffview/scene/views/file_history/listeners.lua | Updates actions to respect pin-local target selection and guard synthetic entries without hashes. |
| lua/diffview/scene/views/file_history/file_history_view.lua | Implements pin-local state, pinned cursor follower, pinned RHS cache, overlay resolution, and swap-detach behavior. |
| lua/diffview/scene/views/file_history/file_history_panel.lua | Wires layout_opt for pin-local, prepends synthetic local entry, supports overlays in lookup/navigation/highlight. |
| lua/diffview/scene/layouts/diff_2_ver_pinned.lua | New vertical pinned Diff2 layout variant (shared_symbols, should_null, swap detach). |
| lua/diffview/scene/layouts/diff_2_hor_pinned.lua | New horizontal pinned Diff2 layout variant (shared_symbols, should_null, swap detach). |
| lua/diffview/scene/layout.lua | Introduces shared_symbols, owned_files() filtering, and detach_files_for_swap() hook. |
| lua/diffview/scene/file_entry.lua | Adds _extra_owned to prevent leaks with shared-symbol fallbacks and supports pinned_b_file reuse rules. |
| lua/diffview/lib.lua | Adds --pin-local flag resolution, adapter support gating (git/hg), and base-flag conflict handling. |
| lua/diffview/config.lua | Adds view.file_history.pin_local config default and registers pinned layout names internally. |
| lua/diffview/actions.lua | Makes cycle_layout/set_layout pin-local aware (pinned/unpinned mapping + overlay handling). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add `VCSAdapter:build_local_log_entry`; git/hg override to produce a `LogEntry` with `revs.a = HEAD`, `revs.b = LOCAL` for every locally modified path. Returns nil on a clean tree or when `HEAD` can't be resolved. b-sides are pulled through the view's `pin_local` cache when set.
cdb3da7 to
6ee0012
Compare
Add `--pin-local` and `view.file_history.pin_local`. `FileHistoryView` owns a `path -> vcs.File` cache shared across pinned entries (entry teardown skips them via `shared_symbols`; the view destroys them in `close()`). A debounced cursor follower updates `pinned_path`; `_resolve_pinned_target` builds overlay `FileEntries` for commits that don't touch it. `cycle_layout` / `set_layout` route through `resolve_pinned_layout` and convert overlays missed by `panel:list_files()`. Reject `--pin-local` with `--base` (would override the fixed RHS).
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.
Closes #142.