M4.6: Git log and file history

- crates/vcs log.rs: Repo::log (topological, all refs, paging, literal
  message/author filters, a path's history with --follow), show_commit
  (message and files against the first parent, renames) and show_at
  (a file at any commit); parsers property-tested.
- Engine git.log, git.showCommit, git.showAt in cmd/git_log.rs through
  the step-1 hook.
- Log tab in the bottom panel: graph lanes carried across pages, ref
  badges, filters, lazy paging, keyboard; commit details whose files open
  a read-only diff at that commit in M4.3's viewer.
- vcs.showLog and vcs.showHistory (menu, tree context menu, active
  editor tab), no default shortcuts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-28 18:00:24 +01:00
parent b814c49733
commit a8531825a3
27 changed files with 3349 additions and 16 deletions

View file

@ -627,6 +627,29 @@ Watched directories: the VFS watcher is non-recursive, so `project.children` wat
- **Look:** both sides use the Lutra editor theme and the file's language; changed lines are tinted with `color-mix` of `--lt-vcs-deleted` (left) and `--lt-vcs-added` (right) into `--lt-editor-bg`, changed words more strongly, a change bar in each gutter, unchanged stretches over 8 lines collapse to a row (3 lines of context). No colour outside the tokens.
- **Tests:** `ui/tests/vcs/DiffView.test.ts` (21 Vitest tests against a fake engine: params and `git.show` parsing, EOL normalisation, index and HEAD sides, one tab per side, the palette without a path, bad params and no file as toasts, disabled without a project, edits on the right reaching `buffer.edit`, engine changes reaching the right side, the left side refresh on `gitChanged`, closing with the buffer, binary / too large / git error / deleted / new file, switching between diff and file tabs, next/previous change with wrap-around, the tree context menu by right click and by Shift+F10 with Escape).
### History (M4.6)
- **Backend (`crates/vcs/src/log.rs`, appended to `Repo`):**
- `log(LogQuery {skip, limit ≤ 500, path?, query?, author?})`: `git log --topo-order` (children before parents, so the UI can draw lanes) over `--branches --remotes --tags HEAD`; with a path, HEAD's history of that path, with `--follow` when it is a file. Text and author filters are literal and case-insensitive (`--fixed-strings --regexp-ignore-case`). In a repository whose root lies above the project, only commits touching the project. A repository without commits has an empty log.
- Format: `%x1e` before each record, NUL between hash, parents, author, email, strict ISO date, subject and decorations (`%D`); malformed records are skipped.
- `show_commit(hash)`: 4–64 hex digits only. Reads the full message (`show -s`) and the files against the first parent (`diff-tree --no-commit-id -r -z -M --name-status`, `--root` for a root commit), at most 10,000 inside the project, with `truncated`.
- `show_at(path, rev)`: `rev:path` through `cat-file --batch-check`, then the blob, with the same binary, size and BOM rules as `show`. A revision starting with `-`, holding `:` or control characters is refused; a missing path or revision is empty contents.
- The parsers are property-tested with random bytes.
- **Shared hook for new git commands (wave 2/3):** `Repo::run`, `check_name` and `SMALL_CAP` are `pub(crate)`. In `cmd/git.rs`, `Op::Custom {mutates, run}` and `start_with(state, id, mutates, run)` run a closure from another module exactly like the built-in commands: a pending outcome, git and the repository cached, and `gitChanged` after a change. `rel_path` resolves path params. M4.6's commands live in `crates/engine/src/cmd/git_log.rs`.
- **Commands** (read-only, pending, no `gitChanged`):
- `git.log {skip?, limit? (1–500, 100), path?, query?, author?}` → `{commits: [{hash, parents, author, email, date, subject, refs}]}`.
- `git.showCommit {hash}` → `{hash, parents, author, email, date, message, files: [{path, status, origPath?}], truncated}`. `email` and `truncated` are additions to the C6 contract.
- `git.showAt {path, rev}` → `{text|null, binary, tooLarge}` (the shape of `git.show`).
- A bad limit, hash, revision or path is `invalid_params`; an unknown commit is `failed` with git's message.
- **Log tab** (`ui/src/components/vcs/log/`): `log.ts` is the store, `graph.ts` the lane layout, `LogToolWindow.vue` the window. It is a tab of the bottom panel, opened by the UI commands `vcs.showLog` (menu Git › Log) and `vcs.showHistory {path?}` (menu Git › Show History, the project tree's context menu; without a path, the active editor tab's file). Neither has a default shortcut.
- **List:** pages of 100 through `runWaiting`. The next page loads when the list scrolls within 30 rows of its end, or when the keyboard selection gets there. One load at a time, a generation counter drops stale answers, at most 50,000 commits. Rows show the graph, ref badges (HEAD, branch, remote, tag; `<remote>/HEAD` left out), the subject, the author and the local date. Up/Down/Page/Home/End move the selection.
- **Graph:** one column per waiting lane. A commit takes the leftmost lane waiting for it, and the other lanes waiting for it join it. Its first parent continues in its column, and further parents join an existing lane or take the first free one. Lanes left after a page carry into the next, so rows already drawn never change. At most 24 columns, coloured from theme tokens only. With a text or author filter there is no graph (the parents are not listed), only dots.
- **Filters:** message and author fields apply 300 ms after typing or on Enter. A "History of <path>" chip clears the path filter. `gitChanged` reloads only when HEAD or the branch moved (a commit or a checkout), not on staging. A project open or close clears the tab.
- **Details:** the selected commit's short hash, author, email, date, full message and changed files (state colours, "from <old path>" for renames). Enter or a double-click on a file opens its diff at that commit.
- **Diff at a commit (in M4.3's viewer):** `useDiffStore().openAtCommit(path, {hash, parent, origPath, deleted})` opens a "Diff: <name> (<short hash>)" tab. The left side is `git.showAt` of the old path at the first parent (empty for a root commit or an added file), the right side `git.showAt` at the commit (empty for a deleted file). Both sides are read-only texts with normalised line breaks; nothing is re-read on `gitChanged`, and no buffer is opened.
- **Checked in the app** (debug build with the bundled UI, Windows 11, git 2.47.1, control port 7946, a demo repository with a feature branch merged with `--no-ff`, a rename, a tag and an unmerged branch; screenshots only, no input): `git.log` 75–79 ms over the control channel; `vcs.showLog` showed the lanes branching at the merge and joining at the fork point, the badges (HEAD, main, feature, hotfix, v1.0) and the first commit's details; `vcs.showHistory {path: "Renamed.php"}` showed its three commits back to the import as `Old.php`, without the other branch. The diff at a commit needs a double-click, so it is covered by Vitest only.
- **Tests:** `crates/vcs/tests/log.rs` (5 tests against real temp repositories: empty repository, paging, merge parents and refs, tags, literal text filter, author filter, history across a rename, a folder's history, commit details and a root commit, contents at a commit and its parent, bad input, a project inside a repository); unit and property tests in `log.rs`; `crates/engine/tests/git_log.rs` (the command shapes, paging, filters, an absolute path, bad params, no `gitChanged`); Vitest `ui/tests/vcs/Log.test.ts` (21 tests: lanes for linear and merged histories, across pages and capped, parsers, badges, paging, filters with stale answers, reloads on `gitChanged`, errors, details, the window's rows, keyboard, filters and chip, the diff at a commit with both sides read-only, commands and the tree menu).
### Branches (M4.5)
- **Where:** `ui/src/components/vcs/branches/`: `branches.ts` is the Pinia store, `BranchStatusItem.vue` the status-bar item (one line in `StatusBar.vue`, after H3's progress item), `BranchPopup.vue` the popup. The item supplies the UI commands, so they exist wherever the status bar is.
@ -654,6 +677,7 @@ Watched directories: the VFS watcher is non-recursive, so `project.children` wat
| Date | Change | Summary |
|---|---|---|
| 2026-10-28 | minor | M4.6: history backend (`git.log`, `git.showCommit`, `git.showAt`), the shared hook for new git commands, the Log tab, diffs at a commit |
| 2026-10-27 | minor | F3: `lutra_proc::spawn_suspended` (Phpactor) and `adopt` (ConPTY shell in a job), cancel superseded completions, syntax proptests compare leaf kinds |
| 2026-10-27 | minor | C6 F1: remote branch checkout without a configured remote (`--no-track`), `git.lastMessage` and the Amend prefill, one shared git status store |
| 2026-10-27 | minor | F2: `ui.screenshot` through WebView2 `CapturePreview` without focus; region fallback elsewhere; `--control` windows open unfocused |