summaryrefslogtreecommitdiff
path: root/src/diff.zig
Commit message (Collapse)AuthorAge
* A diff line looks up the path and line it names, as any look doesGabriel Schneider30 hours
| | | | | | | | | | | | | | | | | | | | | | | | The look on a diff line was its own resolver: a walk up to .git/.jj from the diff's directory, its own "no such file here" and "deleted by this diff". A review tool's cached patch, in no repository, missed every file though the session's terminals sat in the checkout. Now a diff line only expands and transforms. Its expansion (what the hover shows) is the whole line for a header, a `@@` line, or a hunk line pointed at on its prefix, and its text is the look address the line names (look.diffAddress): `path` for `diff --git`/`---`/`+++`, `path:c` for `@@ -a,b +c,d @@`, `path:N` for a hunk line's new line (a removed line's, the new line now where it was). That text goes through the regular look exactly as if selected by hand: same resolution, placement and errors. A 9P look of a whole diff line takes the same transform. Kept: the line classification, hunk arithmetic, git prefix stripping and timestamp cutting (diff.zig). Gone: the repo-root walk, its messages, Target.old_side and deletesAhead, and the click's row stash (Pardes.diff_look). A test compares a B3 on a cached patch's line with a look of the hand-selected `entry/src/entry.rs:2` in the same session. Co-Authored-By: Claude Opus 5.5 <[email protected]>
* A diff look names a file as the repository does: git's side prefix dropped ↵Gabriel Schneider30 hours
| | | | | | | | | | | | | | | | | | by git's rules, a plain diff's names as written In a git section (one with a `diff --git` line) the one-letter side prefix git writes, `a/`/`b/` or with diff.mnemonicPrefix `c/`, `i/`, `w/`, `o/`, is dropped from its paths only when both paths of that line carry one, different ones: `--no-prefix` writes none, so its `a/x a/x` is a real directory `a` and is kept. A plain `diff -u` never strips: its names are used as written, past the timestamp. `/dev/null` stays itself. The walker does this once (diff.Walk.side, diff.gitHeader), so the path a look resolves, and the one a miss says, are the repository's name: `Look: src/x.zig: no such file here`, `Look: lib/old.zig: deleted by this diff`. The look no longer tries a stripped name beside the written one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
* Every line of a diff section that deletes its file looks for a file "deleted ↵Gabriel Schneider30 hours
| | | | | | | | | | | | | by this diff", the diff --git and --- lines too In a section that deletes its file, a look at a removed or hunk line said "<file>: deleted by this diff". The `diff --git` and `---` lines said "no such file here", because they come before the `+++ /dev/null` (or `deleted file mode`) that says so, and the walk had not reached it yet. They now look ahead within the section, so every line gives the one message. Co-Authored-By: Claude Opus 5.5 <[email protected]>
* diff -u in a command pane names its files though the terminal turned the tab ↵Gabriel Schneider30 hours
| | | | | | | | | | | | | | | | before each timestamp into blanks A `---`/`+++` path was cut at the tab before diff -u's timestamp. Run in a command pane, the terminal had turned that tab into blanks, so the name took the timestamp with it and a look at a changed line opened nothing. The name is now also cut where blanks run up to a timestamp, either GNU diff's `2026-09-30 10:00:00...` or ctime's `Wed Sep 30 10:00:00 2026`. One blank is enough, since a tab can expand to a single blank, and the stamp is strict, so a name with blanks and no stamp after them stays whole. Tested on the parsed text and, in fs.py, on real `diff -u` output in a command pane, where a look at `+TWO` opens the new file. Co-Authored-By: Claude Opus 5.5 <[email protected]>
* A right click on a diff line opens the place it names: its file, the hunk's ↵Gabriel Schneider30 hours
| | | | | | | | | | | | | | | | | | | | | | | new line, the line itself In a diff pane (a .diff/.patch file, or a command pane's diff output), the look's own expansion, which its hover shows, takes a whole line for a `diff --git`, `---`, `+++` or `@@` line wherever the pointer is on it, markers included, and for a hunk line when the pointer is on its `+`, `-` or space. Then the look opens the file (a/ b/ dropped, timestamps cut) at the line from the hunk header and the lines above it: `@@` the hunk's first new line, context and added lines their own, a removed line the new line now where it was. `diff --git` and `+++` open the new file; `---` the old one, unless the `+++` under it names another. On a hunk line's code the expansion is its words, the prefix never one of them, and looks as ever. Other panes are untouched. Paths resolve in the repository (walking up to `.git` or `.jj` from the diff's directory, or a command pane's), then that directory. A file not here opens nothing and says `Look: b/x: no such file here`, or `deleted by this diff`. A 9P look writing a whole line of the diff does the same. Co-Authored-By: Claude Opus 5.5 <[email protected]>
* A diff reads as the code it changes: hunks in their file's language, added ↵Gabriel Schneider30 hours
and removed rows tinted A .diff or .patch pane, and a command pane whose output is a diff (`git diff`, `git show`, `diff -u`; told by a `diff --git` line, or `---`/`+++` with a `@@` under them, in its first rows), colour each hunk's code in the language of the file its section names (`+++ b/<path>`, `--- a/<path>` for a deleted file), with tree-sitter, as highlightLocations does for results. src/diff.zig walks a unified diff by its `@@` counts, so a removed line that reads `--- x` is no header. Each side of a hunk is parsed as one text (context and removed lines the old side, context and added lines the new), so a string or comment across lines colours as it does in the file; a side no line takes its colours from is not parsed. A section's hunks share a parse, in pieces of about 40 lines (a hunk past 80 is cut), only those in view, and each piece's colours are kept by its bytes, so scrolling back and a terminal's every repaint parse nothing again. Added and removed lines carry a flag in their style byte; the painter tints their rows to the pane's edge, a little way from the page toward the theme's ANSI green or red, and draws the prefix in that hue pushed to read on it. A file in no known language keeps the old line colours. A command pane is read once its command has finished: its rows are copied once (File.DiffOutput, dropped when the pane runs again), so no frame dumps the scrollback, and painted over what git printed. A running command is shown as it prints. Co-Authored-By: Claude Opus 5.5 <[email protected]>