diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-23 15:40:56 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-23 15:42:33 -0300 |
| commit | fa3550eedec44e624384b478fc19a40d94fb7a82 (patch) | |
| tree | ed82b63f8d66e0311df9635e556c1c14cfdbc551 /core/jj.zig | |
| parent | 68b696ead861bb416c339f624bea82ed478bb2dd (diff) | |
| download | pardes-fa3550eedec44e624384b478fc19a40d94fb7a82.tar.gz pardes-fa3550eedec44e624384b478fc19a40d94fb7a82.zip | |
changes layer: a pinned change that is neither behind nor ahead of the revision shown (a sibling) draws nothing and the notice line says so in words, `Changes: wlrmpstu is not on @'s line` (the coordinator's ruling of round 8's question (b), said to the user): round 8 left a sibling out of jj's query, so a revset of siblings alone said "no change of `...` touches a.zig" and one beside others went unsaid; now the query takes the whole revset (with the unpinned changes between, as before) and `logTemplate` marks a change neither behind nor ahead `s` (`entryOf`'s `aside`); `parse` keeps its step (its diff's bounds) but reads none of its hunks (it moves no place on the shown line), Churn counts it as a change ahead (none of the shown lines), and `pinAnswer` says the siblings' ids (`asideSaid`, from jj's answer: no new state, nothing replicated) as the notice with what is drawn, or as the refusal when nothing else is pinned; the guide's *From the middle* says so; THE FAILING TEST FIRST (core/jj.zig "a pinned change neither behind nor ahead of the shown revision (a sibling) draws nothing ..."): `two` and `sib` children of `one`, the working copy on `sib`: `Changes ~::@` (two alone) said "no change of `~::@` touches a.zig" on the round's base; now `Changes: <id> is not on @'s line`, nothing pinned, no lanes; `Changes ~::@ | @-`: `sib` drawn, `two` named; core-test filtered on jj (Debug tui) 56/56
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 | 100 |
1 files changed, 82 insertions, 18 deletions
diff --git a/core/jj.zig b/core/jj.zig index 78c0e857..b99419b0 100644 --- a/core/jj.zig +++ b/core/jj.zig @@ -707,13 +707,13 @@ 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. - // 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); + // The revset's, each marked behind the shown revision (its ancestors, + // it too), ahead of it (its descendants) or neither (a sibling: its + // lines are no revision's on its line, drawn nowhere and named in + // words, `pinAnswer`). 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}) | (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, a.rev) catch return failed(gpa, a, refusal(gpa, "out of memory").refused); defer gpa.free(template); @@ -1054,9 +1054,13 @@ fn pinAnswer(p: *Pardes, id: usize, b: *const pardes.Stream.Batch, revset: []con return p.reportFailure(id, line.print("{s}: {s}", .{ name, why[0..@min(why.len, 480)] })); }, .read => |*changes| { + // The revset's changes neither behind nor ahead: said, not drawn. + var aside_said: pardes.Kind.Buf(512) = .{}; + const aside = asideSaid(b.rows, if (of(f)) |r| r.rev else "@", &aside_said); if (changes.pins.len == 0) { changes.deinit(p.gpa); const shown = std.Io.Dir.path.basename(if (of(f)) |r| r.path else f.path); + if (aside.len > 0) return p.reportFailure(id, aside); if (kind == .compare) return p.reportFailure(id, line.print("{s}: no difference in {s} between `{s}`", .{ name, shown, revset })); return p.reportFailure(id, line.print("{s}: no change of `{s}` touches {s}", .{ name, revset, shown })); } @@ -1072,12 +1076,28 @@ fn pinAnswer(p: *Pardes, id: usize, b: *const pardes.Stream.Batch, revset: []con changes.deinit(p.gpa); return p.reportFailure(id, line.print("{s}: out of memory", .{name})); }; - p.setStatus(.at(id), ""); + p.setStatus(.at(id), aside); if (pane.layers.lanes > 0) showLayer(p, f, pane.serial); }, } } +/// The changes jj's log `logged` marks neither behind nor ahead of the +/// shown revision `rev` (`logTemplate`'s `s`: a sibling), in words: +/// `Changes: <id> is not on <rev>'s line`; "" for none. +fn asideSaid(logged: []const u8, rev: []const u8, said: *pardes.Kind.Buf(512)) []const u8 { + var ids: [256]u8 = undefined; + var w: std.Io.Writer = .fixed(&ids); + var n: usize = 0; + var it = std.mem.splitScalar(u8, logged, '\n'); + while (it.next()) |l| if (entryOf(l)) |e| if (e.aside) { + w.print("{s}{s}", .{ if (n == 0) "" else ", ", &e.pin.id }) catch break; + n += 1; + }; + if (n == 0) return ""; + return said.print("Changes: {s} {s} not on {s}'s line", .{ w.buffered(), if (n == 1) "is" else "are", rev }); +} + /// jj's answer `b` for a `Churn` of `window` on pane `id`, kept raw /// until the text's declarations are there (a worker's parse, /// Stream.parseFor: a big file's parse is seconds in a Debug build, never @@ -1151,7 +1171,8 @@ fn heatOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, logged: []const u8, 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); + // A sibling of the shown revision, as one ahead: none of its lines. + try ahead.append(arena, e.ahead or e.aside); try starts.append(arena, it.index orelse logged.len); }; try starts.append(arena, logged.len); @@ -1300,7 +1321,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, ahead: bool = false }; + const Step = struct { pin: u16, diff: usize, ahead: bool = false, aside: bool = false }; var steps: std.ArrayList(Step) = .empty; var it = std.mem.splitScalar(u8, logged, '\n'); while (it.next()) |l| if (entryOf(l)) |e| { @@ -1308,7 +1329,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, .ahead = e.ahead }); + 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, .aside = e.aside }); }; try steps.append(arena, .{ .pin = Hunk.carrier, .diff = logged.len }); out.pins = try pins.toOwnedSlice(gpa); @@ -1326,7 +1347,8 @@ 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), s.ahead, logged[s.diff..next.diff], text, out.lines, &hunks, &removed, &marks, &taken); + // A sibling's (`aside`) none: it moves no place on the shown line. + for (steps.items[0 .. steps.items.len - 1], steps.items[1..], 0..) |s, next, i| if (!s.aside) 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); @@ -1339,8 +1361,9 @@ fn parse(gpa: std.mem.Allocator, arena: std.mem.Allocator, logged: []const u8, a /// `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. +/// pinned and ahead; `c` and `d` the same for one it does not pin; `s` one +/// neither behind nor ahead, a sibling), 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); @@ -1356,16 +1379,18 @@ fn logTemplate(gpa: std.mem.Allocator, revset: []const u8, rev: []const u8) erro 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 t.appendSlice(gpa, "\"), \"p\", \"c\"), 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, "\"), \"a\", \"d\")) ++ \"\\t\" ++ author.timestamp().utc().format(\"%s\") ++ \"\\t\" ++ author.name() ++ \"\\t\" ++ description.first_line() ++ \"\\n\""); + try t.appendSlice(gpa, "\"), \"a\", \"d\"), \"s\")) ++ \"\\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, ahead: bool, author: []const u8, title: []const u8 } { +fn entryOf(l: []const u8) ?struct { pin: Pin, pinned: bool, ahead: bool, aside: 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'); @@ -1376,7 +1401,7 @@ fn entryOf(l: []const u8) ?struct { pin: Pin, pinned: bool, ahead: bool, author: 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' or l[9] == 'a', .ahead = l[9] == 'a' or l[9] == 'd', .author = author, .title = title }; + return .{ .pin = pin, .pinned = l[9] == 'p' or l[9] == 'a', .ahead = l[9] == 'a' or l[9] == 'd', .aside = l[9] == 's', .author = author, .title = title }; } /// Which pin wrote each line of `text` (what the pane shows: `whole` is the @@ -3551,6 +3576,45 @@ test "the node keys and the indent read the file's text: Alt-o and a function's try testing.expectEqualStrings(opened[0], opened[1]); } +test "a pinned change neither behind nor ahead of the shown revision (a sibling) draws nothing, and the notice line says so in words: alone, nothing pinned; beside one behind, that one drawn" { + const gpa = testing.allocator; + // `two` and `sib` both children of `one`: the working copy on `sib`. + var repo = try Repo.with(gpa, &.{ .{ Repo.one, "one" }, .{ Repo.two, "two" } }, null) orelse return error.SkipZigTest; + defer repo.deinit(gpa); + if (!try Repo.run(gpa, repo.dir, &.{ "new", "@--" })) return error.SkipZigTest; + try repo.tmp.dir.writeFile(testing.io, .{ .sub_path = "a.zig", .data = Repo.three }); + if (!try Repo.run(gpa, repo.dir, &.{ "commit", "-m", "sib" })) return error.SkipZigTest; + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); + 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].?; + try testing.expectEqualStrings(Repo.three, pane.file.?.content); + const Said = struct { + fn aside(said: []const u8) bool { + const want = " is not on @'s line"; + if (!std.mem.startsWith(u8, said, "Changes: ") or !std.mem.endsWith(u8, said, want)) return false; + const named = said["Changes: ".len .. said.len - want.len]; + return named.len == 8 and isChangeId(named); + } + }; + // `two` alone: nothing drawn, and why. + p.update(.{ .command = "Changes ~::@" }); + errdefer std.debug.print("told: {s}\n", .{told(p, id)}); + try testing.expect(Said.aside(told(p, id))); + try testing.expect(answered(p, pane.serial) == null); + try testing.expectEqual(0, pane.layers.lanes); + try testing.expectEqualStrings(Repo.three, pane.file.?.content); + // `two` with `sib` (behind): `sib` drawn, `two` named. + p.update(.{ .command = "Changes ~::@ | @-" }); + try testing.expect(Said.aside(told(p, id))); + const ch = answered(p, pane.serial).?; + try testing.expectEqual(@as(usize, 1), ch.pins.len); + try testing.expectEqualStrings("sib", ch.pins[0].title[0..ch.pins[0].title_len]); + try testing.expect(pane.layers.lanes > 0); +} + test "THE FILE'S TEXT: with the layer's lines in the buffer, every reader of the file reads what it reads with them out, byte for byte: a Save, a Save to another name, Edit's w, body over 9P, the dirty check, a reread from the disk, a Get, jj's lines asked again, the context declarations, the colours of the file's lines, the language server's text and the place it is asked at" { const gpa = testing.allocator; var repo = try Lines.repo() orelse return error.SkipZigTest; |
