diff options
| -rw-r--r-- | core/builtins.zig | 2 | ||||
| -rw-r--r-- | core/hunks.zig | 9 | ||||
| -rw-r--r-- | core/jj.zig | 279 | ||||
| -rw-r--r-- | docs/typ/builtins-gui.json | 2 | ||||
| -rw-r--r-- | docs/typ/builtins-tui.json | 2 | ||||
| -rw-r--r-- | docs/typ/cheatsheet.typ | 2 | ||||
| -rw-r--r-- | docs/typ/guide.typ | 57 |
7 files changed, 283 insertions, 70 deletions
diff --git a/core/builtins.zig b/core/builtins.zig index fbb82fc3..7bdb773f 100644 --- a/core/builtins.zig +++ b/core/builtins.zig @@ -1080,7 +1080,7 @@ pub const At = struct { pub const run = @import("jj.zig").word; }; -/// Pin the changes `revset` names (jj) on a file's pane and show them in this view: a lane each after the line number, a line one added whole green, what the file no longer has drawn where it stood (ghost rows: a line taken away whole red, each change's description after its last line); bare, shown here or not (none pinned yet: `@`). +/// Pin the changes `revset` names (jj) on a file's pane and show them in every view of it: a lane each after the line number, a line one added whole green, what the file no longer has as lines of its text where it stood, read-only (a line taken away whole red, each change's description after its last line); bare, shown or not (none pinned yet: `@`). pub const Changes = struct { pub const takes_arg = true; pub const run = @import("jj.zig").changesWord; diff --git a/core/hunks.zig b/core/hunks.zig index e109b788..db2401f6 100644 --- a/core/hunks.zig +++ b/core/hunks.zig @@ -703,7 +703,9 @@ fn trimmedWidth(ctx: *const Ctx, section: []const u8) usize { /// a digit among them), `git show` of it, paged into a +Pager that stacks /// its hunks (ctl.fillPager), run in the pane's git work tree; with a jj /// change (`Diff wrnnmymq [path[:line]]`: jj.diffChange), its patch, header -/// and all, the cursor at that place in it. A plumbing +/// and all, the cursor at that place in it; with any other word that names +/// no file, in a jj repository, the revision jj takes it for (`Diff @-`, a +/// bookmark), the same. A plumbing /// rule's Diff that cannot (no hunk, no work tree) declines, saying /// nothing (Pardes.plumb_declined), and the look looks itself. pub fn word(c: pardes.builtins.Ctx) void { @@ -734,12 +736,15 @@ pub fn word(c: pardes.builtins.Ctx) void { return; } // A jj change (its letters k to z), with a place in its patch to stand at. - if (@import("jj.zig").diffChange(p, c.id, arg)) return; + if (@import("jj.zig").diffChange(p, c.id, arg, false)) return; if (@import("jj.zig").isChangeId(arg[0 .. std.mem.indexOfAny(u8, arg, " \t") orelse arg.len])) return declined(p, c.id, "Diff: no such change"); var buf: [4096]u8 = undefined; const path = if (arg[0] == '/') arg else std.fmt.bufPrint(&buf, "{s}/{s}", .{ std.mem.trimEnd(u8, Pardes.paneDir(c.pane), "/"), arg }) catch arg; const bytes = pardes.filesystem.read(p, path) catch |err| { if (p.plumb_declined != null) return declined(p, c.id, ""); + // No such file: a revision jj takes (`Diff @-`, a bookmark), its + // patch with its header, as a change's. + if (err == error.FileNotFound and @import("jj.zig").diffChange(p, c.id, arg, true)) return; return p.reportError(.at(c.id), path, err); }; defer p.gpa.free(bytes); diff --git a/core/jj.zig b/core/jj.zig index 18926594..2ecd58a7 100644 --- a/core/jj.zig +++ b/core/jj.zig @@ -339,6 +339,9 @@ pub const Line = struct { /// byte ranges of the line). marks: u32 = 0, nmarks: u16 = 0, + /// The pin ahead of the shown revision that takes it away: a line + /// going (`going`). + going: PinIndex = .none, }; /// The lanes a row shows at most (a window's strips the same). @@ -361,6 +364,9 @@ pub const Hunk = struct { pin: u16, /// Its change's place in jj's answer, oldest first. step: u16, + /// Its change is ahead of the shown revision (a descendant): its + /// `removed` text is what it adds (`carriedBack` carries its places). + ahead: bool = false, old_start: u32, old_len: u32, new_start: u32, @@ -400,8 +406,9 @@ pub const Ghost = struct { author: u32 = 0, /// A line taken away whole; a line's old text, the line that took its - /// place right below it; a pin's description. - pub const Kind = enum(u8) { deleted, changed, description }; + /// place right below it; a pin's description; a line a pin ahead of the + /// shown revision will write, after the lines it will take away. + pub const Kind = enum(u8) { deleted, changed, description, added }; }; /// The `Changes` word (builtins.zig registers it): in a file's pane (or a @@ -658,12 +665,15 @@ fn answer(p: ?*Pardes, gpa: std.mem.Allocator, a: *const Ask) pardes.Stream.Batc const set = fileset(gpa, a.path) catch return failed(gpa, a, refusal(gpa, "out of memory").refused); defer gpa.free(set); // The changes, oldest first, each with its diff of the file: one run. - // With them the changes between the first and the shown revision that - // the revset does not pin (marked so), whose hunks move the places of - // the lines the older pins took away. - const query = std.fmt.allocPrint(gpa, "(({s}) | (roots({s})::({s}))) & files({s})", .{ a.revset, a.revset, a.rev, set }) catch return failed(gpa, a, refusal(gpa, "out of memory").refused); + // Of the revset, those behind the shown revision (its ancestors, it + // too) and those ahead of it (its descendants); a sibling of it is + // neither and is left out (its lines are no revision's on its line). + // With them the changes the revset does not pin between the first and + // the shown revision, and between it and those ahead (marked so), + // whose hunks move the places of the pins' lines. + const query = std.fmt.allocPrint(gpa, "((({0s}) & (::({1s}) | ({1s})::)) | (roots({0s})::({1s})) | (({1s})::({0s}))) & files({2s})", .{ a.revset, a.rev, set }) catch return failed(gpa, a, refusal(gpa, "out of memory").refused); defer gpa.free(query); - const template = logTemplate(gpa, a.revset) catch return failed(gpa, a, refusal(gpa, "out of memory").refused); + const template = logTemplate(gpa, a.revset, a.rev) catch return failed(gpa, a, refusal(gpa, "out of memory").refused); defer gpa.free(template); const log_args = [_][]const u8{ "log", "--no-graph", "--reversed", "-r", query, "-T", template, "--git", "--context=0", "--", set }; const logged = switch (runJj(p, gpa, dirOf(a.path), &log_args)) { @@ -941,14 +951,16 @@ fn heatOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, logged: []const u8, var windowed: std.ArrayList(bool) = .empty; var starts: std.ArrayList(usize) = .empty; var it = std.mem.splitScalar(u8, logged, '\n'); + var ahead: std.ArrayList(bool) = .empty; while (it.next()) |l| if (entryOf(l)) |e| { if (windowed.items.len == Hunk.carrier) break; try windowed.append(arena, e.pinned); + try ahead.append(arena, e.ahead); try starts.append(arena, it.index orelse logged.len); }; try starts.append(arena, logged.len); for (starts.items[0 .. starts.items.len - 1], starts.items[1..], 0..) |from, to, i| - try hunksOf(arena, arena, Hunk.carrier, @intCast(i), logged[from..to], text, &.{}, &hunks, &removed, undefined, undefined); + try hunksOf(arena, arena, Hunk.carrier, @intCast(i), ahead.items[i], logged[from..to], text, &.{}, &hunks, &removed, undefined, undefined); const n = lineCount(text); const moved: Moved = .of(was, text); // Each line's innermost declaration (outermost first, so an inner one @@ -966,7 +978,8 @@ fn heatOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, logged: []const u8, const seen = try arena.alloc(u32, decls.len); @memset(seen, none); for (hunks.items) |h| { - if (!windowed.items[h.step] or n == 0) continue; + // A change ahead of the shown revision touched none of its lines. + if (!windowed.items[h.step] or h.ahead or n == 0) continue; const a = carried(hunks.items, h.step, h.new_start -| 1 + @intFromBool(h.new_len == 0), moved) orelse continue; const b = carried(hunks.items, h.step, h.new_start -| 1 + h.new_len, moved) orelse continue; const lo = @min(if (h.new_len == 0) a -| 1 else a, n - 1); @@ -1090,7 +1103,7 @@ fn parse(gpa: std.mem.Allocator, arena: std.mem.Allocator, logged: []const u8, a var whole: std.ArrayList([2][]const u8) = .empty; // Each change jj answered, oldest first: its pin (or `Hunk.carrier`) // and where its diff starts in `logged`; then the end. - const Step = struct { pin: u16, diff: usize }; + const Step = struct { pin: u16, diff: usize, ahead: bool = false }; var steps: std.ArrayList(Step) = .empty; var it = std.mem.splitScalar(u8, logged, '\n'); while (it.next()) |l| if (entryOf(l)) |e| { @@ -1098,7 +1111,7 @@ fn parse(gpa: std.mem.Allocator, arena: std.mem.Allocator, logged: []const u8, a if (steps.items.len == Hunk.carrier) return .{ .refused = try std.fmt.allocPrint(gpa, "more than {d} changes between them touch it", .{Hunk.carrier}) }; if (e.pinned) try pins.append(gpa, e.pin); if (e.pinned) try whole.append(arena, .{ e.author, e.title }); - try steps.append(arena, .{ .pin = if (e.pinned) @intCast(pins.items.len - 1) else Hunk.carrier, .diff = it.index orelse logged.len }); + try steps.append(arena, .{ .pin = if (e.pinned) @intCast(pins.items.len - 1) else Hunk.carrier, .diff = it.index orelse logged.len, .ahead = e.ahead }); }; try steps.append(arena, .{ .pin = Hunk.carrier, .diff = logged.len }); out.pins = try pins.toOwnedSlice(gpa); @@ -1116,9 +1129,10 @@ fn parse(gpa: std.mem.Allocator, arena: std.mem.Allocator, logged: []const u8, a var marks: std.ArrayList([2]u32) = .empty; defer marks.deinit(gpa); var taken: std.ArrayList(Taken) = .empty; - for (steps.items[0 .. steps.items.len - 1], steps.items[1..], 0..) |s, next, i| try hunksOf(gpa, arena, s.pin, @intCast(i), logged[s.diff..next.diff], text, out.lines, &hunks, &removed, &marks, &taken); + for (steps.items[0 .. steps.items.len - 1], steps.items[1..], 0..) |s, next, i| try hunksOf(gpa, arena, s.pin, @intCast(i), s.ahead, logged[s.diff..next.diff], text, out.lines, &hunks, &removed, &marks, &taken); out.hunks = try hunks.toOwnedSlice(gpa); nest(out.lines, out.pins.len); + going(out.lines, out.hunks, moved); out.ghosts = try ghostsOf(gpa, arena, out.pins, whole.items, out.lines, out.hunks, taken.items, &removed, now, moved); out.ghost_text = try removed.toOwnedSlice(gpa); out.marks = try marks.toOwnedSlice(gpa); @@ -1126,25 +1140,35 @@ fn parse(gpa: std.mem.Allocator, arena: std.mem.Allocator, logged: []const u8, a return .{ .read = out }; } -/// `jj log`'s line a change, before its diff: its id, `p` when `revset` -/// pins it (else `c`), its author's time, its author, its description's -/// first line, a tab between. -fn logTemplate(gpa: std.mem.Allocator, revset: []const u8) error{OutOfMemory}![]u8 { +/// `jj log`'s line a change, before its diff: its id, its mark (`p` when +/// `revset` pins it and it is behind the shown revision `rev` or is it, `a` +/// pinned and ahead; `c` and `d` the same for one it does not pin), its +/// author's time, its author, its description's first line, a tab between. +fn logTemplate(gpa: std.mem.Allocator, revset: []const u8, rev: []const u8) error{OutOfMemory}![]u8 { var t: std.ArrayList(u8) = .empty; errdefer t.deinit(gpa); - try t.appendSlice(gpa, "change_id.short(8) ++ \"\\t\" ++ if(self.contained_in(\""); - for (revset) |c| { - if (c == '"' or c == '\\') try t.append(gpa, '\\'); - try t.append(gpa, c); - } - try t.appendSlice(gpa, "\"), \"p\", \"c\") ++ \"\\t\" ++ author.timestamp().utc().format(\"%s\") ++ \"\\t\" ++ author.name() ++ \"\\t\" ++ description.first_line() ++ \"\\n\""); + const Quoted = struct { + fn put(g: std.mem.Allocator, out: *std.ArrayList(u8), text: []const u8) error{OutOfMemory}!void { + for (text) |c| { + if (c == '"' or c == '\\') try out.append(g, '\\'); + try out.append(g, c); + } + } + }; + try t.appendSlice(gpa, "change_id.short(8) ++ \"\\t\" ++ if(self.contained_in(\"::("); + try Quoted.put(gpa, &t, rev); + try t.appendSlice(gpa, ")\"), if(self.contained_in(\""); + try Quoted.put(gpa, &t, revset); + try t.appendSlice(gpa, "\"), \"p\", \"c\"), if(self.contained_in(\""); + try Quoted.put(gpa, &t, revset); + try t.appendSlice(gpa, "\"), \"a\", \"d\")) ++ \"\\t\" ++ author.timestamp().utc().format(\"%s\") ++ \"\\t\" ++ author.name() ++ \"\\t\" ++ description.first_line() ++ \"\\n\""); return t.toOwnedSlice(gpa); } /// A `logTemplate` line, or null for a line of a diff (which starts with /// a blank, a sign, `@`, `\\` or a word and a blank: never eight of jj's /// id letters, k to z, and a tab). -fn entryOf(l: []const u8) ?struct { pin: Pin, pinned: bool, author: []const u8, title: []const u8 } { +fn entryOf(l: []const u8) ?struct { pin: Pin, pinned: bool, ahead: bool, author: []const u8, title: []const u8 } { if (l.len < 11 or l[8] != '\t' or l[10] != '\t') return null; for (l[0..8]) |c| if (c < 'k' or c > 'z') return null; var cols = std.mem.splitScalar(u8, l[11..], '\t'); @@ -1155,7 +1179,7 @@ fn entryOf(l: []const u8) ?struct { pin: Pin, pinned: bool, author: []const u8, const title = cols.rest(); pin.title_len = @intCast(@min(title.len, pin.title.len)); @memcpy(pin.title[0..pin.title_len], title[0..pin.title_len]); - return .{ .pin = pin, .pinned = l[9] == 'p', .author = author, .title = title }; + return .{ .pin = pin, .pinned = l[9] == 'p' or l[9] == 'a', .ahead = l[9] == 'a' or l[9] == 'd', .author = author, .title = title }; } /// Which pin wrote each line of `text` (what the pane shows: `whole` is the @@ -1262,7 +1286,7 @@ const Taken = struct { paired: bool, marks: u32, nmarks: u16, new: u32 = 0, show /// written changed, and their words, is the patch view's alignment /// (hunks.format: its `inferEdits`), read off its rows. A change the /// revset does not pin (`k` is `Hunk.carrier`): its hunks alone. -fn hunksOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, k: u16, step: u16, diffed: []const u8, text: []const u8, lines: []Line, hunks: *std.ArrayList(Hunk), removed: *std.ArrayList(u8), marks: *std.ArrayList([2]u32), taken: *std.ArrayList(Taken)) error{OutOfMemory}!void { +fn hunksOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, k: u16, step: u16, ahead: bool, diffed: []const u8, text: []const u8, lines: []Line, hunks: *std.ArrayList(Hunk), removed: *std.ArrayList(u8), marks: *std.ArrayList([2]u32), taken: *std.ArrayList(Taken)) error{OutOfMemory}!void { const Added = struct { text: []const u8, whole: bool, marks: u32, nmarks: u16, new: u32, shown: ?u32 = null }; var added: std.ArrayList(Added) = .empty; var walk: diff.Walk = .{}; @@ -1272,9 +1296,17 @@ fn hunksOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, k: u16, step: u16, switch (l.kind) { .hunk => { const h = diff.parseHunk(std.mem.trimEnd(u8, raw, "\r")).?; - try hunks.append(gpa, .{ .pin = k, .step = step, .old_start = @intCast(h.old_start), .old_len = @intCast(h.old_count), .new_start = @intCast(h.new_start), .new_len = @intCast(h.new_count), .removed = @intCast(removed.items.len), .removed_len = 0 }); + try hunks.append(gpa, .{ .pin = k, .step = step, .ahead = ahead, .old_start = @intCast(h.old_start), .old_len = @intCast(h.old_count), .new_start = @intCast(h.new_start), .new_len = @intCast(h.new_count), .removed = @intCast(removed.items.len), .removed_len = 0 }); + }, + // A pin ahead of the shown revision: the lines it will write + // are what the text has not. + .added => if (k != Hunk.carrier and ahead) { + const body = std.mem.trimEnd(u8, raw, "\r")[1..]; + try removed.appendSlice(gpa, body); + try removed.append(gpa, '\n'); + hunks.items[hunks.items.len - 1].removed_len += @intCast(body.len + 1); }, - .removed => if (k != Hunk.carrier) { + .removed => if (k != Hunk.carrier and !ahead) { const body = std.mem.trimEnd(u8, raw, "\r")[1..]; try removed.appendSlice(gpa, body); try removed.append(gpa, '\n'); @@ -1283,7 +1315,7 @@ fn hunksOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, k: u16, step: u16, else => {}, } } - if (k == Hunk.carrier) return; + if (k == Hunk.carrier or ahead) return; // The patch view's rows of the same diff: a line it paired is one // changed (its marker has no `ground_line`), its words `ground_emph`. const patch = format: { @@ -1390,14 +1422,40 @@ fn ghostsOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, pins: []const Pin, var made: std.ArrayList(Made) = .empty; var ti: usize = 0; for (hunks) |h| { + // A pin ahead: the lines it will write, after those it will take + // away (or where it writes), where they will stand. + if (h.ahead) { + if (h.pin == Hunk.carrier or h.new_len == 0) continue; + const at = carriedBack(hunks, h.step, if (h.old_len == 0) h.old_start else h.old_start - 1 + h.old_len, moved) orelse continue; + var from: usize = h.removed; + for (0..h.new_len) |n| { + const nl = std.mem.indexOfScalarPos(u8, text.items, from, '\n') orelse text.items.len; + defer from = nl + 1; + try made.append(arena, .{ + .g = .{ .at = at, .pin = h.pin, .kind = .added, .line = h.new_start + @as(u32, @intCast(n)), .text = @intCast(from), .len = @intCast(nl - from) }, + .rank = 1 << 32 | made.items.len << 1, + }); + } + continue; + } if (h.old_len == 0 or h.pin == Hunk.carrier) continue; const run = taken[@min(ti, taken.len)..@min(ti + h.old_len, taken.len)]; ti += h.old_len; // A changed line's old text right above the line; a line taken - // away whole above the next changed one's, or after the run. - var at = carried(hunks, h.step, if (h.new_len > 0) h.new_start - 1 + h.new_len else h.new_start, moved); - var ats: [max_run]?u32 = undefined; + // away whole above the next changed one's; after the last changed + // one, right after its new text; with none changed, before the + // lines written in their place (a diff's order: what went, then + // what came). if (run.len > max_run) continue; + var last: ?usize = null; + for (run, 0..) |t, n| if (t.paired) { + last = n; + }; + var at = if (last) |n| next: { + const shown = run[n].shown orelse carried(hunks, h.step, run[n].new -| 1, moved); + break :next if (shown) |v| v + 1 else null; + } else carried(hunks, h.step, if (h.new_len > 0) h.new_start - 1 else h.new_start, moved); + var ats: [max_run]?u32 = undefined; var k = run.len; while (k > 0) { k -= 1; @@ -1420,7 +1478,7 @@ fn ghostsOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, pins: []const Pin, var i = lines.len; while (i > 0) { i -= 1; - if (@intFromEnum(lines[i].pin) == k) { + if (@intFromEnum(lines[i].pin) == k or @intFromEnum(lines[i].going) == k) { at = @intCast(i + 1); break; } @@ -1434,12 +1492,15 @@ fn ghostsOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, pins: []const Pin, var first: u32 = 0; var end: u32 = 0; var step: u16 = 0; + var ahead = false; for (hunks) |h| if (h.pin == k) { if (first == 0) first = h.new_start; - end = if (h.new_len > 0) h.new_start - 1 + h.new_len else h.new_start; + // A pin ahead: after the lines it takes away, in its parent's. + end = if (h.ahead) h.old_start - 1 + h.old_len + @intFromBool(h.old_len == 0) else if (h.new_len > 0) h.new_start - 1 + h.new_len else h.new_start; step = h.step; + ahead = h.ahead; }; - const place = at orelse carried(hunks, step, end, moved) orelse continue; + const place = at orelse (if (ahead) carriedBack(hunks, step, end, moved) else carried(hunks, step, end, moved)) orelse continue; // After its own ghost rows at its place. for (made.items) |m| if (m.g.pin == k and m.g.at == place) { rank = m.rank | 1; @@ -1475,7 +1536,8 @@ fn carried(hunks: []const Hunk, from: u16, after: u32, moved: Moved) ?u32 { var inside: ?i64 = null; while (i < hunks.len and hunks[i].step == j) : (i += 1) { const h = hunks[i]; - if (j <= from) continue; + // A change ahead of the shown revision moves nothing in it. + if (j <= from or h.ahead) continue; if (h.old_len == 0) { if (h.old_start < pos) shift += h.new_len; } else if (h.old_start + h.old_len - 1 <= pos) { @@ -1487,6 +1549,49 @@ fn carried(hunks: []const Hunk, from: u16, after: u32, moved: Moved) ?u32 { return moved.place(@intCast(std.math.clamp(pos, 0, @as(i64, moved.was)))); } +/// Where the place after line `after` of the revision step `from`'s change +/// (a pin ahead of the shown revision) was made from is in the text: moved +/// back through each change ahead of the shown revision before it, newest +/// first, their hunks turned round; then from jj's lines to the text's +/// (`moved`). +fn carriedBack(hunks: []const Hunk, from: u16, after: u32, moved: Moved) ?u32 { + var pos: i64 = after; + var i = hunks.len; + while (i > 0) { + const j = hunks[i - 1].step; + var lo = i; + while (lo > 0 and hunks[lo - 1].step == j) lo -= 1; + defer i = lo; + if (j >= from or !hunks[lo].ahead) continue; + var shift: i64 = 0; + var inside: ?i64 = null; + for (hunks[lo..i]) |h| { + if (h.new_len == 0) { + if (h.new_start < pos) shift += h.old_len; + } else if (h.new_start + h.new_len - 1 <= pos) { + shift += @as(i64, h.old_len) - h.new_len; + } else if (h.new_start <= pos) inside = @as(i64, h.old_start) - 1 + h.old_len; + } + pos = inside orelse pos + shift; + } + return moved.place(@intCast(std.math.clamp(pos, 0, @as(i64, moved.was)))); +} + +/// The lines of the text a pin ahead of the shown revision takes away, +/// going (`Line.going`), its lane beside them. +fn going(lines: []Line, hunks: []const Hunk, moved: Moved) void { + for (hunks) |h| { + if (!h.ahead or h.pin == Hunk.carrier or h.old_len == 0) continue; + const first = carriedBack(hunks, h.step, h.old_start - 1, moved) orelse continue; + const pin: PinIndex = @enumFromInt(h.pin); + for (lines[@min(first, lines.len)..@min(first + h.old_len, lines.len)]) |*l| { + l.going = pin; + if (std.mem.indexOfScalar(PinIndex, &l.lanes, pin) != null) continue; + if (std.mem.indexOfScalar(PinIndex, &l.lanes, .none)) |free| l.lanes[free] = pin; + } + } +} + /// A pin's description line (PARDES.md: `id title author age`, one blank /// between): its id's first four letters, its whole title (its /// description's first line), its whole author, its age short (`5h`, `2d`, @@ -1574,6 +1679,7 @@ fn inkGhost(p: *Pardes, s: *pardes.Surface, pane: *const Pane, g: Ghost, row: i3 _ = tab; switch (g.kind) { .deleted => s.tint(x, y, w, pardes.colors.Grounds.of(th).del.row, th.lineno), + .added => s.tint(x, y, w, pardes.colors.Grounds.of(th).add.row, null), .changed => { ink.fg(0, said.len, th.lineno); for (marks[g.marks..][0..g.nmarks]) |m| { @@ -1620,7 +1726,8 @@ fn ownerOf(ch: *const Changes, f: *const File.State, row: usize) PinIndex { return if (g.kind == .description) .none else @enumFromInt(g.pin); } const line = File.fileRow(f, row); - return if (line < ch.lines.len) ch.lines[line].pin else .none; + if (line >= ch.lines.len) return .none; + return if (ch.lines[line].going != .none) ch.lines[line].going else ch.lines[line].pin; } /// The line `]g` (`forward`) or `[g` goes to from buffer line `from` of @@ -1687,14 +1794,16 @@ pub fn isChangeId(text: []const u8) bool { /// prints it (its ids, author, dates and whole message above its hunks), /// stacked in its +Diff (one a change: a second goes to it); the cursor on /// the patch's row for `path`'s line `line` (that file's first row -/// without one; none of it: the top). False when it names no change. -pub fn diffChange(p: *Pardes, id: usize, arg: []const u8) bool { +/// without one; none of it: the top). With `any`, `change` is any word jj +/// takes for one revision (`@-`, a bookmark, a commit). False when it +/// names none. +pub fn diffChange(p: *Pardes, id: usize, arg: []const u8, any: bool) bool { var words = std.mem.tokenizeAny(u8, arg, " \t"); const change = words.next() orelse return false; - if (!isChangeId(change)) return false; + if (!any and !isChangeId(change)) return false; const dir = pardes.filesystem.localPath(Pardes.paneDir(p.panes[id].?)) orelse return false; - var buf: [64]u8 = undefined; - const revset = std.fmt.bufPrint(&buf, "change_id({s})", .{change}) catch return false; + var buf: [128]u8 = undefined; + const revset = if (any) change else std.fmt.bufPrint(&buf, "change_id({s})", .{change}) catch return false; const shown = p.tape.site(.jj, p.gpa, runHost, .{ p.gpa, dir, @as([]const []const u8, &.{ "show", "--git", "-r", revset }) }); const bytes = switch (shown) { .refused => |why| { @@ -1939,13 +2048,16 @@ fn paintLanes(p: *Pardes, s: *pardes.Surface, pane: *Pane, r: pardes.Rect, tx: u const first_row = w.at <= 0; inkGhost(p, s, pane, g, w.line, @intCast(@max(0, w.at)), to, w.pad, ch.marks, if (one == null) colours[g.pin % colours.len] else null, tx + gutter, y, tw - gutter); if (g.kind == .description and first_row) points = @enumFromInt(g.pin); - taken = g.kind != .description or takenAbove(ch.ghosts, gi); + taken = g.kind == .deleted or g.kind == .changed or (g.kind == .description and takenAbove(ch.ghosts, gi)); break :ghost ghostLanes(ch, ch.ghosts, gi, first_row); } else line: { const at = File.fileRow(f, row); if (at >= ch.lines.len) continue; const line = ch.lines[at]; if (line.whole and line.pin != .none) s.tint(tx + gutter, y, tw - gutter, ground, null); + // Going: a pin ahead takes it away. + if (line.going != .none) s.tint(tx + gutter, y, tw - gutter, pardes.colors.Grounds.of(p.theme()).del.row, null); + taken = line.going != .none; if (!line.whole and line.nmarks > 0) inkCame(p, s, pane, ch.marks[line.marks..][0..line.nmarks], w.line, vr, tx + gutter, y, tw - gutter); break :line line.lanes; }; @@ -1978,6 +2090,7 @@ fn takenAbove(ghosts: []const Ghost, gi: usize) bool { while (j > 0) { j -= 1; if (ghosts[j].at != ghosts[gi].at) return false; + if (ghosts[j].kind == .added) return false; if (ghosts[j].kind != .description) return true; } return false; @@ -2697,6 +2810,32 @@ test "a Look on a change's id opens its patch, its header and whole message at t } } +test "Diff with a revision jj takes (`@-`, a bookmark) and no file of that name: the revision's patch, its commit's ids, author, date and whole message at its top; a word that names neither is still no such file" { + const gpa = testing.allocator; + var repo = try Ghosts.repo() orelse return error.SkipZigTest; + defer repo.deinit(gpa); + if (!try Repo.run(gpa, repo.dir, &.{ "bookmark", "create", "-r", "@--", "cutmark" })) return error.SkipZigTest; + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 30, .windowed = false }); + defer p.deinit(); + var line: [4200]u8 = undefined; + for ([_]struct { []const u8, []const u8 }{ .{ "@-", "\n mid\n" }, .{ "cutmark", "\n cut\n" } }) |case| { + p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{repo.file}) }); + const from = p.view().active; + p.update(.{ .command = try std.fmt.bufPrint(&line, "Diff {s}", .{case[0]}) }); + const shown = p.panes[p.view().active].?; + try testing.expect(p.view().active != from); + try testing.expectStringStartsWith(shown.file.?.content, "Commit ID: "); + try testing.expect(std.mem.indexOf(u8, shown.file.?.content, "\nAuthor : t <t@t>") != null); + try testing.expect(std.mem.indexOf(u8, shown.file.?.content, case[1]) != null); + try testing.expect(std.mem.indexOf(u8, shown.file.?.content, "a.zig") != null); + } + p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{repo.file}) }); + const id = p.view().active; + p.update(.{ .command = "Diff nosuchword" }); + try testing.expectEqual(id, p.view().active); + try testing.expect(std.mem.indexOf(u8, told(p, id), "nosuchword") != null); +} + test "ghost rows ride with the text: a line deleted above moves them up, a line they stood before deleted puts them before the next; a client replays it equal" { var repo = try Ghosts.repo() orelse return error.SkipZigTest; defer repo.deinit(testing.allocator); @@ -3225,6 +3364,62 @@ test "a session dumped by a build whose layer was a view's bit and no lines (wir } } +test "a line replaced by one too unlike it to be one line changed: what went right above what came, a diff's order, in the file's own pane and from the middle alike" { + const gpa = testing.allocator; + const one = "l1\nl2\nline 10\nl4\n"; + const two = "l1\nl2\nline ten CHANGED by two\nl4\n"; + var repo = try Repo.with(gpa, &.{ .{ one, "one" }, .{ two, "two" }, .{ two ++ "l5\n", "three" } }, null) orelse return error.SkipZigTest; + defer repo.deinit(gpa); + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 30, .windowed = false }); + defer p.deinit(); + var line: [4200]u8 = undefined; + for ([_][]const u8{ "", "@@--" }) |at| { + p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}{s}", .{ repo.file, at }) }); + const pane = p.panes[p.view().active].?; + p.update(.{ .command = "Changes @--" }); + try testing.expectEqualStrings("line 10", File.sourceLine(pane, 2)); + try testing.expectEqualStrings("line ten CHANGED by two", File.sourceLine(pane, 3)); + } +} + +test "from the middle: in a revision's pane a pin behind it shows the lines it took away where they stood (a changed line's old text right above it), and a pin ahead of it shows the lines it will write as the read-only lines where they will stand, the lines it will take away the text's, going" { + const gpa = testing.allocator; + // `two` changes l3 and takes l7 away; `three`, ahead of it, writes a + // line after l1 and changes l5. + const one = "l1\nl2\nl3\nl4\nl5\nl6\nl7\n"; + const two = "l1\nl2\nl3 two\nl4\nl5\nl6\n"; + const three = "l1\nnew three\nl2\nl3 two\nl4\nl5 three\nl6\n"; + var repo = try Repo.with(gpa, &.{ .{ one, "one" }, .{ two, "two" }, .{ three, "three" } }, null) orelse return error.SkipZigTest; + defer repo.deinit(gpa); + for ([_]bool{ false, true }) |windowed| { + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 24, .windowed = windowed }); + defer p.deinit(); + var line: [4200]u8 = undefined; + p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}@@--", .{repo.file}) }); + const id = p.view().active; + const pane = p.panes[id].?; + p.update(.{ .command = "Changes @-- | @-" }); + const ch = answered(p, pane.serial).?; + try testing.expectEqual(@as(usize, 2), ch.pins.len); + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + const said_two = try std.fmt.allocPrint(arena.allocator(), "{s} two t now", .{ch.pins[0].id[0..4]}); + const said_three = try std.fmt.allocPrint(arena.allocator(), "{s} three t now", .{ch.pins[1].id[0..4]}); + const want = [_][]const u8{ "l1", "new three", "l2", "l3", "l3 two", said_two, "l4", "l5", "l5 three", said_three, "l6", "l7" }; + for (want, 0..) |w, row| try testing.expectEqualStrings(w, File.sourceLine(pane, @intCast(row))); + try testing.expectEqualStrings(two, try File.fileText(&pane.file.?, arena.allocator())); + // Drawn: what three will write green across, what it will take + // away red across, what two took away red. + p.sync(); + const s = try p.render(arena.allocator()); + const body = s.region(.body, id).?.rect; + const x = body.x + File.gutterWidth(pane) + 1; + const grounds = pardes.colors.Grounds.of(p.theme()); + for ([_]u16{ 1, 8 }) |row| try testing.expectEqual(pardes.Color{ .rgb = grounds.add.row }, s.at(x, body.y + row).style.bg); + for ([_]u16{ 7, 11 }) |row| try testing.expectEqual(pardes.Color{ .rgb = grounds.del.row }, s.at(x, body.y + row).style.bg); + } +} + test "a client replays the layer's lines and an edit refused among them, and ends equal; a client joined over a pane showing the layer loads its lines" { var repo = try Lines.repo() orelse return error.SkipZigTest; defer repo.deinit(testing.allocator); diff --git a/docs/typ/builtins-gui.json b/docs/typ/builtins-gui.json index aeaf6953..eeb207af 100644 --- a/docs/typ/builtins-gui.json +++ b/docs/typ/builtins-gui.json @@ -10,7 +10,7 @@ {"name": "Callstack", "leader": "SPC l b", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Show outermost callers first, with signatures and call sites (gc)."}, {"name": "CallstackDepth", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": null, "doc": "Caller levels collected by Callstack, 1 through 64; default 8. Bare, it says the current limit."}, {"name": "Changelog", "leader": "SPC h c", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "This build's version and what changed to reach it, printed into an output buffer the same way Config prints the live settings."}, - {"name": "Changes", "leader": "SPC t c", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Pin the changes `revset` names (jj) on a file's pane and show them in this view: a lane each after the line number, a line one added whole green, what the file no longer has drawn where it stood (ghost rows: a line taken away whole red, each change's description after its last line); bare, shown here or not (none pinned yet: `@`)."}, + {"name": "Changes", "leader": "SPC t c", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Pin the changes `revset` names (jj) on a file's pane and show them in every view of it: a lane each after the line number, a line one added whole green, what the file no longer has as lines of its text where it stood, read-only (a line taken away whole red, each change's description after its last line); bare, shown or not (none pinned yet: `@`)."}, {"name": "Churn", "leader": "SPC t u", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Count, for each declaration of a file's pane, the changes in `window` (jj) that touched it, and show it in this view: a heat lane after the line number and a strip by the scroll thumb, the line numbers' grey to the theme's red on a log scale; `window` a revset or a span of time (`3d`, `2w`, `6m`, `1y`); bare, shown here or not (none counted yet: the file's whole history)."}, {"name": "ClipPaste", "leader": "SPC p", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Paste the system clipboard after the selection."}, {"name": "ClipPasteBefore", "leader": "SPC P", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Paste the system clipboard before the selection."}, diff --git a/docs/typ/builtins-tui.json b/docs/typ/builtins-tui.json index 2263df44..a41b4466 100644 --- a/docs/typ/builtins-tui.json +++ b/docs/typ/builtins-tui.json @@ -10,7 +10,7 @@ {"name": "Callstack", "leader": "SPC l b", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Show outermost callers first, with signatures and call sites (gc)."}, {"name": "CallstackDepth", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": null, "doc": "Caller levels collected by Callstack, 1 through 64; default 8. Bare, it says the current limit."}, {"name": "Changelog", "leader": "SPC h c", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "This build's version and what changed to reach it, printed into an output buffer the same way Config prints the live settings."}, - {"name": "Changes", "leader": "SPC t c", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Pin the changes `revset` names (jj) on a file's pane and show them in this view: a lane each after the line number, a line one added whole green, what the file no longer has drawn where it stood (ghost rows: a line taken away whole red, each change's description after its last line); bare, shown here or not (none pinned yet: `@`)."}, + {"name": "Changes", "leader": "SPC t c", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Pin the changes `revset` names (jj) on a file's pane and show them in every view of it: a lane each after the line number, a line one added whole green, what the file no longer has as lines of its text where it stood, read-only (a line taken away whole red, each change's description after its last line); bare, shown or not (none pinned yet: `@`)."}, {"name": "Churn", "leader": "SPC t u", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Count, for each declaration of a file's pane, the changes in `window` (jj) that touched it, and show it in this view: a heat lane after the line number and a strip by the scroll thumb, the line numbers' grey to the theme's red on a log scale; `window` a revset or a span of time (`3d`, `2w`, `6m`, `1y`); bare, shown here or not (none counted yet: the file's whole history)."}, {"name": "ClipPaste", "leader": "SPC p", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Paste the system clipboard after the selection."}, {"name": "ClipPasteBefore", "leader": "SPC P", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Paste the system clipboard before the selection."}, diff --git a/docs/typ/cheatsheet.typ b/docs/typ/cheatsheet.typ index a590e402..782836dc 100644 --- a/docs/typ/cheatsheet.typ +++ b/docs/typ/cheatsheet.typ @@ -119,7 +119,7 @@ Helix-style: motions *select*, then an edit acts on the selection. Mode box: bla == Reviewing diffs `git diff` output is a diff: #btn("B3") on a file line, an `@@` or a line's `+`/`-` jumps there. #doc("tags", section: "reviewing-diffs") -#word("Changes") `revset` on a file's pane: a lane a change (one change: green beside what it wrote, red beside what it took away), an arrow to its description, ghost rows for what it took away, #keys("] g", "[ g") from change to change; #btn("B3") on a change id: its patch, header first; #word("Churn") `3m`: each declaration's changes, grey to red; `a.zig@main:12` is a file at a revision. #doc("guide", section: "changes") +#word("Changes") `revset` on a file's pane (every view of it): a lane a change (one change: green beside what it wrote, red beside what it took away), an arrow to its description, what it took away as lines of the text, read-only (the cursor, a search, a yank, #btn("B2") and #btn("B3") work there; an edit there is refused), #keys("] g", "[ g") from change to change; #btn("B3") on a change id: its patch, header first; #word("Churn") `3m`: each declaration's changes, grey to red; `a.zig@main:12` is a file at a revision. #doc("guide", section: "changes") == Finding things - A query pane under the pane: line 1 the query, its first word the source: `/pat`, `Find name` (fuzzy), `Grep text` (literal), `Recent`, `Panes`, `Symbols`, `All`. #keys("Ctrl-n", "Ctrl-p") step, #key("Enter") lands and keeps the rows, #key("Esc") puts things back. #word("Help"), #word("Tutor"). diff --git a/docs/typ/guide.typ b/docs/typ/guide.typ index 985d324d..bc02298c 100644 --- a/docs/typ/guide.typ +++ b/docs/typ/guide.typ @@ -298,16 +298,16 @@ this view, and on again. = Changes on the source view <changes> -jj's changes drawn on a file's own pane, as layers each view wears or -not: the text stays the text (the patch view, `+Diff`, is unchanged). +jj's changes on a file's own pane, as a layer the pane wears or not: +the file's text stays the file's (the patch view, `+Diff`, is unchanged). Nothing is shown, and nothing asked of jj, until a word is run. #pairs( - [#word("Changes") `revset` (#key("SPC t c"))], [pins the revset's changes that touched the file on its pane (or a revision's) and shows them in this view; one set a pane (another view's revset replaces it there too). Bare: hidden in this view or shown again; with none pinned yet, `@`, the change against its parent], + [#word("Changes") `revset` (#key("SPC t c"))], [pins the revset's changes that touched the file on its pane (or a revision's) and shows them, in every view of the pane: their lines are the pane's text. Bare: hidden or shown again; with none pinned yet, `@`, the change against its parent], [#word("Churn") `window` (#key("SPC t u"))], [counts, for each declaration, the window's changes that touched it, and shows them in this view; the window a revset, or a span of time back from now (`3d`, `2w`, `6m`, `1y`). Bare: hidden or shown again; with none counted yet, the file's whole history], [#keys("] g", "[ g")], [the next and the previous change's first line], [`path@rev`, `path@rev:line`], [the file at a revision (#doc("guide", section: "revision")): a #word("Look") anywhere opens it], - [#word("Diff") `change` `path:line`], [a jj change's patch, its header (ids, author, dates, the whole message) above its hunks, in its own `+Diff`, the cursor on `path`'s line in it; a #word("Look") on a change id (eight of its letters, `k` to `z`, as `jj log` shows them) anywhere opens it at its top], + [#word("Diff") `change` `path:line`], [a jj change's patch, its header (ids, author, dates, the whole message) above its hunks, in its own `+Diff`, the cursor on `path`'s line in it; a #word("Look") on a change id (eight of its letters, `k` to `z`, as `jj log` shows them) anywhere opens it at its top; `Diff @-`, `Diff` a bookmark (a word that names no file): that revision's, the same], ) *Lanes.* Each pinned change gets a lane after the line number, from its @@ -320,22 +320,35 @@ it skipped), oldest first, so they are told apart. At a change's description its lane ends in an arrow to it. A line one added whole is green across the line. -*Ghost rows.* What the file no longer has is drawn where it stood, a row -of its own with no number: a line a change took away whole, red across; -a line a change changed, its old text right above it with the words that -went red, and on the line the words that came green (the patch view's +*Ghost lines.* What the file no longer has is in the pane as lines, +where it stood: a line a change took away whole, red across; a line a +change changed, its old text right above it with the words that went +red, and on the line the words that came green (the patch view's alignment says which lines are one line changed); each change's -description, `id title author age` (`3w`, `4m`), after its last line, in -its lane's colour (one change pinned: its id in the theme's keyword -colour), at one place after that change's own -ghost rows. The cursor steps over a ghost row, and search, selection and -the line numbers do not see it; a #btn("B3") on one looks at the word -there as anywhere, and on a description's id opens that change's patch -at the row for its last line here (`Diff id path:line`). It -moves the rows below down in this view alone. It is one row, cut where -the pane ends (never wrapped); in a narrow pane a description's title is -cut, its author and age kept. A hunk that took away more than 1,024 -lines shows none of them. +description, `id title author age` (`3w`, `4m`), its whole title and its +whole author, after its last line, in its lane's colour (one change +pinned: its id in the theme's keyword colour), at one place after that +change's own ghost lines. They are text, read-only: no line number (the +numbers are the file's, and `:N` is the file's line N), but the cursor +goes onto them, a selection runs through them, `/` finds in them, a text +object and a count work there, a yank takes them, #btn("B2") runs a word +of theirs and #btn("B3") looks at it (on a description's id: that +change's patch at the row for its last line here, `Diff id path:line`). +An edit that would change one (a key typed in it, a `d` or a paste over +it, a `J` into it) is refused whole, and says so on the notice line; the +file is never edited by it. What reads the file reads it without them: a +Save, `body`, `addr` and `dot` over 9P (a place in a ghost line is after +the file line above it), Edit, the language server, the syntax colours, +the dirty mark, the undo. A ghost line wraps as any line does; nothing is +cut. A hunk that took away more than 1,024 lines shows none of them. + +*From the middle.* In a file at a revision (`path@rev`), a pinned change +behind it (the revision or one of its ancestors) shows what it took away +as above; one ahead of it (a descendant) shows the lines it will write +as the ghost lines, green, where they will stand, and the lines it will +take away are the text's own, red across: going. A change that is +neither (a sibling) is not shown: its lines are no revision's on this +one's line. *Churn.* A cell after the line number, from the line numbers' grey to the theme's red on a log scale of the count against the file's hottest @@ -348,11 +361,11 @@ what it had under another name before a move is not counted. jj answers once, when the word is run, on a worker (the editor goes on); its answer is lined up with the pane's text as it is then (lines typed -before jj's last snapshot or while it ran), and the lanes, ghost rows and +before jj's last snapshot or while it ran), and the lanes, ghost lines and counts ride with the lines through the edits made since. A place inside -lines rewritten since jj's snapshot has no ghost row. A change between +lines rewritten since jj's snapshot has no ghost line. A change between two pinned ones that the revset does not pin still moves the older ones' -ghost rows to where they stand. +ghost lines to where they stand. = Call hierarchy <callstack> |
