Skip to content

feat(file_history): add --pin-local for working-tree pinning#158

Merged
dlyongemallo merged 4 commits intomainfrom
pin_local
May 6, 2026
Merged

feat(file_history): add --pin-local for working-tree pinning#158
dlyongemallo merged 4 commits intomainfrom
pin_local

Conversation

@dlyongemallo
Copy link
Copy Markdown
Owner

@dlyongemallo dlyongemallo commented May 6, 2026

Closes #142.

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`.
Copilot AI review requested due to automatic review settings May 6, 2026 07:40
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_local plumbing across FileHistoryView/Panel, adapters (git/hg), and a pair of pinned Diff2 layouts that share the RHS vcs.File instance across entries.
  • Adds overlay FileEntry support for pinned paths not present in a commit (with adapter probes via file_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.

Comment thread lua/diffview/config.lua
Comment thread lua/diffview/scene/views/file_history/file_history_view.lua
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.
@dlyongemallo dlyongemallo force-pushed the pin_local branch 2 times, most recently from cdb3da7 to 6ee0012 Compare May 6, 2026 08:29
@dlyongemallo dlyongemallo requested a review from Copilot May 6, 2026 08:29
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 26 out of 26 changed files in this pull request and generated 2 comments.

Comment thread doc/diffview.txt Outdated
Comment thread lua/diffview/config.lua Outdated
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).
@dlyongemallo dlyongemallo merged commit df1828f into main May 6, 2026
7 checks passed
@dlyongemallo dlyongemallo deleted the pin_local branch May 6, 2026 08:48
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.

feature request: add an optional synthetic commit in the file history view

2 participants