diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-21 14:17:28 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-21 14:58:57 -0300 |
| commit | 8152cf383c8296be29e80175b57e40f8d41049bf (patch) | |
| tree | 98ab59c0122b73ca6490ab4b778bf0fb7f0582d0 /core/jj.zig | |
| parent | dfb051bd798f65c2217eea7f95b03dce292e30bf (diff) | |
| download | pardes-8152cf383c8296be29e80175b57e40f8d41049bf.tar.gz pardes-8152cf383c8296be29e80175b57e40f8d41049bf.zip | |
layers: with `Changes` off nothing is paid (P45): the revset and jj's answers are the session's, a list by pane serial (`Pardes.changes`, `jj.answered`; `jj.forget` at the pane's end), no longer a field of every pane, and a view holds only whether it shows them (`File.Layers.lanes`, the cells their lanes take, hashed with `ink` in one update), so a second view's `Changes other` shows the new set in both and its bare `Changes` hides them in its own alone (bare with none pinned yet is `@`); measured first, per operation against gpu/tree3 (a gui ReleaseFast pardes-perf, perfops's way of counting: reorg/pardes-layers-4/perf): merge50 +0.005% a client key, round 3 +0.110%, a packed one-byte `Layers` +0.391% (a packed field cost the walks more), a plain two-byte one +0.152%, the per-pane field gone +0.118%, the gutter's three reads of the lanes taken out +0.066% with body-appends from +0.189% to -0.004%: what paid was fillBody's line number, formatted for every row of every geometry pass (no `dst`, a hundred a frame) and thrown away, whose row loop moved with any value added to it: it is now written only into a `dst` (client key +0.017%, deep-sel +0.002%, render -0.021%, body-appends -1.555%); and `jj.of` (round 1's) gave a revision's name as a slice of a by-value copy of the pane's Output, dangling once it returned (jj told "Non-UTF-8 argument" for `Changes` in a revision's pane in a window build): the pane's own now; tests: the pinned changes are the pane's, shown in a view by its own bit (a second view's revset shows in both, its bare Changes hides them there alone), the two of a terminal's cells said so (`.windowed = false`); core-test 896/1056 (160 skipped), shell-test 1098/1101 (3 skipped), gui unit-test 1695/1699 (4 skipped); the frame and perf gate against tree3 (gpu/l4-g0): 77/77 frames, 0 differ, perfab corpus2x +0.005% (noise 0.058%), perfops 121 counts within 0.1% (largest terminal on all +0.082%)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/jj.zig')
| -rw-r--r-- | core/jj.zig | 141 |
1 files changed, 102 insertions, 39 deletions
diff --git a/core/jj.zig b/core/jj.zig index ebd2ea27..b4d119e8 100644 --- a/core/jj.zig +++ b/core/jj.zig @@ -111,7 +111,8 @@ fn refusal(gpa: std.mem.Allocator, why: []const u8) Shown { /// A revision's pane: the file it is of (its name without `@rev`) and the /// revision. Null for any other pane. pub fn of(f: *const File.State) ?struct { path: []const u8, rev: []const u8 } { - const o = f.output orelse return null; + // The pane's own, not a copy: the revision is a slice of it. + const o = if (f.output) |*o| o else return null; if (o.from != .revision) return null; return .{ .path = f.path[0 .. f.path.len - o.arg().len - 1], .rev = o.arg() }; } @@ -199,15 +200,19 @@ pub fn looked(p: *Pardes, id: usize, dir: []const u8, text: []const u8, at: look // ---- `Changes [revset]` (PARDES.md: pinned changes as lanes): what jj // answers for it, kept as flat arrays in the pane ---- -/// What jj answered for a pane's `Changes`: the pane's replicated state (a -/// client never runs jj; one that joins late has it in the dump), drawn by -/// a view that pins the same revset (File.Layers). Two jj runs, each a +/// What jj answered for a pane's `Changes`: replicated state, the session's +/// (`Pardes.changes`, by the pane's serial: a client never runs jj; one that +/// joins late has it in the dump), its revset with it, drawn by each view that shows them (File.Layers.lanes: +/// a view holds that bit, not the revset; one set a pane, so a view's +/// `Changes other` replaces what every view shows). Two jj runs, each a /// site of the step's tape: the changes with their diffs of the file /// (`jj log -p --git`, the diffs read with diff.zig's walk), and who wrote /// each line of the shown revision (`jj file annotate`). pub const Changes = struct { pub const replica = .{ .len = .{.{ "revset", "revset_len" }} }; - revset: [File.Layers.revset_max]u8 = undefined, + /// The pane's (its serial). + serial: u32, + revset: [revset_max]u8 = undefined, revset_len: u8 = 0, /// The revset's changes that touch the file, oldest first. pins: []Pin = &.{}, @@ -223,14 +228,31 @@ pub const Changes = struct { gpa.free(c.lines); gpa.free(c.hunks); gpa.free(c.removed); - c.* = .{}; + c.* = .{ .serial = c.serial }; } pub fn pinned(c: *const Changes) []const u8 { return c.revset[0..c.revset_len]; } + + pub const revset_max = 64; }; +/// What jj answered for pane `serial`'s `Changes` (`Pardes.changes`), if anything. +pub fn answered(p: *Pardes, serial: u32) ?*Changes { + for (p.changes.items) |*c| if (c.serial == serial) return c; + return null; +} + +/// Pane `serial`'s answers let go (the pane's end). +pub fn forget(p: *Pardes, serial: u32) void { + for (p.changes.items, 0..) |*c, i| if (c.serial == serial) { + c.deinit(p.gpa); + _ = p.changes.swapRemove(i); + return; + }; +} + /// A pinned change, as `jj log` says it. pub const Pin = struct { pub const replica = .{ .len = .{ .{ "author", "author_len" }, .{ "title", "title_len" } } }; @@ -280,21 +302,27 @@ pub const Hunk = struct { }; /// The `Changes` word (builtins.zig registers it): in a file's pane (or a -/// revision's), the changes `revset` names (bare: `@`, the change against -/// its parent) pinned in this view; bare again, unpinned; another revset -/// replaces them. What jj refuses is said in its words. +/// revision's), the changes `revset` names pinned on the pane and shown in +/// this view; another revset replaces them (in every view that shows +/// them). Bare: shown in this view or not, the pane's pinned ones (none +/// yet: `@`, the change against its parent). What jj refuses is said in +/// its words. pub fn changesWord(c: pardes.builtins.Ctx) void { const p = c.p; const pane = c.pane; const f = if (pane.file) |*file| file else return p.reportFailure(c.id, "Changes: only a file's pane takes it"); const arg = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); - if (arg.len == 0 and pane.layers.revset_len > 0) { - pane.layers.revset_len = 0; + if (arg.len == 0 and pane.layers.lanes > 0) { pane.layers.lanes = 0; return; } + const cells: u8 = if (p.view().frontend.windowed) 2 else levels; + if (arg.len == 0 and answered(p, pane.serial) != null) { + pane.layers.lanes = cells; + return; + } const revset = if (arg.len == 0) "@" else arg; - if (revset.len > File.Layers.revset_max) return p.reportFailure(c.id, "Changes: a revset that long"); + if (revset.len > Changes.revset_max) return p.reportFailure(c.id, "Changes: a revset that long"); const shown: struct { path: []const u8, rev: []const u8 } = if (of(f)) |r| .{ .path = r.path, .rev = r.rev } else if (f.output == null and pardes.filesystem.localPath(f.path) != null) @@ -315,16 +343,15 @@ pub fn changesWord(c: pardes.builtins.Ctx) void { } @memcpy(changes.revset[0..revset.len], revset); changes.revset_len = @intCast(revset.len); - const kept = pane.changes orelse p.gpa.create(Changes) catch { + changes.serial = pane.serial; + if (answered(p, pane.serial)) |kept| { + kept.deinit(p.gpa); + kept.* = changes.*; + } else p.changes.append(p.gpa, changes.*) catch { changes.deinit(p.gpa); return p.reportFailure(c.id, "Changes: out of memory"); }; - if (pane.changes != null) kept.deinit(p.gpa); - kept.* = changes.*; - pane.changes = kept; - @memcpy(pane.layers.revset[0..revset.len], revset); - pane.layers.revset_len = @intCast(revset.len); - pane.layers.lanes = if (p.view().frontend.windowed) 2 else levels; + pane.layers.lanes = cells; }, } } @@ -339,7 +366,7 @@ fn read(p: *Pardes, path: []const u8, rev: []const u8, revset: []const u8, text: const arena = p.scratch.allocator(); const set = try fileset(arena, path); const dir = dirOf(path); - var out: Changes = .{}; + var out: Changes = .{ .serial = 0 }; var kept = false; defer if (!kept) out.deinit(gpa); // The changes, oldest first, each with its diff of the file: one run. @@ -568,16 +595,16 @@ fn hueApart(a: [3]u8, b: [3]u8) f32 { return @min(d, 360 - d); } -/// The changes a view pins, on its body's rows (body_layer.zig, while -/// File.Layers pins any): in the gutter's lane cells after the number a +/// The pane's pinned changes as a view shows them, on its body's rows (body_layer.zig, while +/// File.Layers.lanes is set): in the gutter's lane cells after the number a /// lane each pin whose block runs down the row, at its level, a glyph in a /// terminal, a strip of pixels in a window (Surface.lanes); and a line a /// pin added whole green across it, as a diff's added line. Not yet: the /// ghost rows (what the shown revision has not: removed lines, each pin's /// description), a changed line's words. pub fn paint(p: *Pardes, s: *pardes.Surface, pane: *Pane, r: pardes.Rect, tx: u16, tw: u16, body_h: u16) void { - const ch = pane.changes orelse return; - if (ch.lines.len == 0 or !std.mem.eql(u8, ch.pinned(), pane.layers.pinned())) return; + const ch = answered(p, pane.serial) orelse return; + if (ch.lines.len == 0) return; var buf: [8][3]u8 = undefined; const colours = laneColours(p.theme(), &buf); if (colours.len == 0) return; @@ -759,11 +786,11 @@ test "a client replays the open of a file at a revision and ends equal" { try testing.expectEqual(pardes.tape.digestOf(a.core), pardes.tape.digestOf(r.core())); } -test "Changes pins a revset's changes in this view: who wrote each line, which it added whole, each one's hunks and what they took away; bare again unpins; jj's refusals are said" { +test "Changes pins a revset's changes on the pane, shown in this view: who wrote each line, which it added whole, each one's hunks and what they took away; bare hides and shows them; jj's refusals are said" { const gpa = testing.allocator; var repo = try Repo.init(gpa) orelse return error.SkipZigTest; defer repo.deinit(gpa); - const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30, .windowed = false }); defer p.deinit(); var line: [4200]u8 = undefined; p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}@@-", .{repo.file}) }); @@ -771,8 +798,8 @@ test "Changes pins a revset's changes in this view: who wrote each line, which i const pane = p.panes[id].?; try testing.expectEqualStrings(Repo.two, pane.file.?.content); p.update(.{ .command = "Changes @--::@-" }); - try testing.expectEqualStrings("@--::@-", pane.layers.pinned()); - const ch = pane.changes.?; + try testing.expectEqual(levels, pane.layers.lanes); + const ch = answered(p, pane.serial).?; try testing.expectEqualStrings("@--::@-", ch.pinned()); try testing.expectEqual(@as(usize, 2), ch.pins.len); for (ch.pins, [_][]const u8{ "one", "two" }) |pin, title| { @@ -796,18 +823,53 @@ test "Changes pins a revset's changes in this view: who wrote each line, which i }; try testing.expectEqualSlices(Hunk, &hunks, ch.hunks); try testing.expectEqualStrings("const one = 1;\n", ch.removed); - // Bare: unpinned in this view; what jj said is kept for another view. + // Bare: not shown in this view; what jj said is kept on the pane. p.update(.{ .command = "Changes" }); - try testing.expectEqual(@as(u8, 0), pane.layers.revset_len); + try testing.expectEqual(0, pane.layers.lanes); try testing.expectEqual(@as(usize, 2), ch.pins.len); - // Bare again: `@`, the working copy's change, which (never snapshotted) touches nothing. + // Bare again: the pane's, shown again (jj not asked). p.update(.{ .command = "Changes" }); - try testing.expect(std.mem.indexOf(u8, told(p, id), "Changes: no change of `@` touches a.zig") != null); - try testing.expectEqual(@as(u8, 0), pane.layers.revset_len); - // jj's refusal, in its words. + try testing.expectEqual(levels, pane.layers.lanes); + try testing.expectEqual(ch, answered(p, pane.serial).?); + // jj's refusal, in its words; what was shown stays. p.update(.{ .command = "Changes nosuch" }); try testing.expect(std.mem.indexOf(u8, told(p, id), "Changes: Revision `nosuch` doesn't exist") != null); - try testing.expectEqual(@as(u8, 0), pane.layers.revset_len); + try testing.expectEqualStrings("@--::@-", answered(p, pane.serial).?.pinned()); + // `@`, the working copy's change, which (never snapshotted) touches nothing. + p.update(.{ .command = "Changes @" }); + try testing.expect(std.mem.indexOf(u8, told(p, id), "Changes: no change of `@` touches a.zig") != null); +} + +test "the pinned changes are the pane's, shown in a view by its own bit: another view's Changes shows its set in both, and its bare Changes hides them there alone" { + const gpa = testing.allocator; + var repo = try Repo.init(gpa) orelse return error.SkipZigTest; + defer repo.deinit(gpa); + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30, .windowed = false }); + defer p.deinit(); + var line: [4200]u8 = undefined; + p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}@@-", .{repo.file}) }); + const pane = p.panes[p.view().active].?; + const before = File.gutterWidth(pane); + const other = p.openView().?; + p.update(.{ .command = "Changes @--::@-" }); + try testing.expectEqual(before + levels, File.gutterWidth(pane)); + // A view of its own: nothing shown there until it asks. + p.toView(other); + try testing.expectEqual(0, pane.layers.lanes); + try testing.expectEqual(before, File.gutterWidth(pane)); + p.update(.{ .command = "Changes @-" }); + try testing.expectEqualStrings("@-", answered(p, pane.serial).?.pinned()); + try testing.expectEqual(@as(usize, 1), answered(p, pane.serial).?.pins.len); + // The first view shows the new set, not nothing. + p.toView(.at(0)); + try testing.expectEqual(levels, pane.layers.lanes); + // Hidden in the other view alone. + p.toView(other); + p.update(.{ .command = "Changes" }); + try testing.expectEqual(0, pane.layers.lanes); + p.toView(.at(0)); + try testing.expectEqual(levels, pane.layers.lanes); + try testing.expectEqual(before + levels, File.gutterWidth(pane)); } test "a client replays Changes from what the session's jj answered and ends equal" { @@ -825,9 +887,10 @@ test "a client replays Changes from what the session's jj answered and ends equa r.settle(); try testing.expect(r.diverged == null); const id = a.core.view().active; - try testing.expectEqual(@as(usize, 2), a.core.panes[id].?.changes.?.pins.len); - try testing.expectEqualSlices(Line, a.core.panes[id].?.changes.?.lines, r.core().panes[id].?.changes.?.lines); - try testing.expectEqualStrings("@--::@-", r.core().panes[id].?.layers.pinned()); + try testing.expectEqual(@as(usize, 2), answered(a.core, a.core.panes[id].?.serial).?.pins.len); + try testing.expectEqualSlices(Line, answered(a.core, a.core.panes[id].?.serial).?.lines, answered(r.core(), r.core().panes[id].?.serial).?.lines); + try testing.expectEqualStrings("@--::@-", answered(r.core(), r.core().panes[id].?.serial).?.pinned()); + try testing.expect(r.core().panes[id].?.layers.lanes > 0); try testing.expectEqual(pardes.tape.digestOf(a.core), pardes.tape.digestOf(r.core())); } @@ -849,7 +912,7 @@ test "Changes draws a lane a pinned change after the line number, nested ones a const pane = p.panes[id].?; const before = File.gutterWidth(pane); p.update(.{ .command = "Changes ::@" }); - try testing.expectEqual(@as(usize, 3), pane.changes.?.pins.len); + try testing.expectEqual(@as(usize, 3), answered(p, pane.serial).?.pins.len); const cells: u16 = if (windowed) 2 else levels; try testing.expectEqual(before + cells, File.gutterWidth(pane)); p.sync(); |
