summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/File.zig118
-rw-r--r--core/dump.zig2
-rw-r--r--core/edit.zig2
-rw-r--r--core/jj.zig54
-rw-r--r--core/look.zig10
-rw-r--r--core/ninep/pane.zig18
-rw-r--r--core/plumbing9
-rw-r--r--core/replica.zig1
8 files changed, 116 insertions, 98 deletions
diff --git a/core/File.zig b/core/File.zig
index d36af5c2..b2df6c0f 100644
--- a/core/File.zig
+++ b/core/File.zig
@@ -199,13 +199,28 @@ pub const State = struct {
/// In its twin group's Follow chain (builtins.Follow), whose panes
/// show the text as consecutive pages (followChain).
follow: bool = false,
- /// Its `Changes` layer's lines while it is shown (`ReadOnly`, jj.zig):
- /// read-only lines of the buffer, in order, gpa-owned (a twin holds its
- /// own copy); none while it is hidden.
- read_only: []ReadOnly = &.{},
- /// Whose layer they are: the serial of the pane whose `Changes` answer
- /// they are the ghosts of, in its order (jj.answered); 0, none shown.
- layer: u32 = 0,
+ /// Its `Changes` layer while it is shown (`Layer`); none while hidden.
+ layer: Layer = .{},
+};
+
+/// A buffer's `Changes` layer (jj.zig): whose, and its lines.
+pub const Layer = struct {
+ /// The serial of the pane whose `Changes` answer its lines are the
+ /// ghosts of, in its order (jj.answered); 0, none shown.
+ owner: u32 = 0,
+ /// Its lines: read-only lines of the buffer, in order, gpa-owned (a
+ /// twin holds its own copy).
+ lines: []ReadOnly = &.{},
+
+ /// By hand, so that a file with no layer shown pays a length test:
+ /// nothing hashed (the walk's two fields cost two small hash updates
+ /// a pane a digest, a client's key 0.1% more). A shown one: its owner,
+ /// its lines.
+ pub fn digest(l: *const Layer, h: *pardes.walk.Hasher) void {
+ if (l.owner == 0 and l.lines.len == 0) return;
+ h.update(std.mem.asBytes(&l.owner));
+ pardes.walk.hash([]ReadOnly, &l.lines, h);
+ }
};
/// A read-only line of a pane's buffer: one of its `Changes` layer's (a
@@ -232,7 +247,7 @@ pub const ReadOnly = struct {
/// the buffer itself while it has none (a file with no layer pays nothing),
/// else a copy in `arena`.
pub fn fileText(f: *const State, arena: std.mem.Allocator) error{OutOfMemory}![]const u8 {
- if (f.read_only.len == 0) return f.content;
+ if (f.layer.lines.len == 0) return f.content;
const out = try arena.alloc(u8, fileLen(f));
var parts: FileParts = .{ .f = f };
var n: usize = 0;
@@ -246,7 +261,7 @@ pub fn fileText(f: *const State, arena: std.mem.Allocator) error{OutOfMemory}![]
/// The file's text's length (`fileText`).
pub fn fileLen(f: *const State) usize {
var n = f.content.len;
- for (f.read_only) |r| n -= r.len;
+ for (f.layer.lines) |r| n -= r.len;
return n;
}
@@ -260,7 +275,7 @@ pub const FileParts = struct {
pub fn next(it: *FileParts) ?[]const u8 {
if (it.done) return null;
- const ro = it.f.read_only;
+ const ro = it.f.layer.lines;
if (it.i == ro.len) {
it.done = true;
return it.f.content[it.at..];
@@ -287,7 +302,7 @@ pub fn fileEql(f: *const State, bytes: []const u8) bool {
/// The file's text hashed (Wyhash, as `std.hash.Wyhash.hash(0, text)`):
/// what the dirty check compares, never a copy.
pub fn fileHash(f: *const State) u64 {
- if (f.read_only.len == 0) return std.hash.Wyhash.hash(0, f.content);
+ if (f.layer.lines.len == 0) return std.hash.Wyhash.hash(0, f.content);
var h = std.hash.Wyhash.init(0);
var parts: FileParts = .{ .f = f };
while (parts.next()) |part| h.update(part);
@@ -299,7 +314,7 @@ pub fn fileHash(f: *const State) u64 {
/// it stands before starts).
pub fn fileOffset(f: *const State, at: usize) usize {
var less: usize = 0;
- for (f.read_only) |r| {
+ for (f.layer.lines) |r| {
if (r.lead) {
if (at <= r.at) break;
if (at <= r.at + r.len) return r.at - less;
@@ -318,7 +333,7 @@ pub fn fileOffset(f: *const State, at: usize) usize {
/// them (a range of the file's lines holds none of the layer's after it).
pub fn bufferOffset(f: *const State, at: usize, end: bool) usize {
var more: usize = 0;
- for (f.read_only) |r| {
+ for (f.layer.lines) |r| {
const place = r.at - more;
if (if (r.lead or end) place >= at else place > at) break;
more += r.len;
@@ -330,7 +345,7 @@ pub fn bufferOffset(f: *const State, at: usize, end: bool) usize {
/// before.
pub fn fileRow(f: *const State, row: usize) usize {
var less: usize = 0;
- for (f.read_only, 0..) |r, k| {
+ for (f.layer.lines, 0..) |r, k| {
const at = r.line + k;
if (at > row) break;
if (at == row) return r.line;
@@ -342,7 +357,7 @@ pub fn fileRow(f: *const State, row: usize) usize {
/// A file row as the buffer's: after the read-only lines standing before it.
pub fn bufferRow(f: *const State, row: usize) usize {
var more: usize = 0;
- for (f.read_only) |r| {
+ for (f.layer.lines) |r| {
if (r.line > row) break;
more += 1;
}
@@ -352,7 +367,7 @@ pub fn bufferRow(f: *const State, row: usize) usize {
/// Which read-only line buffer row `row` is (its place in `read_only`),
/// null for a line of the file.
pub fn readOnlyRow(f: *const State, row: usize) ?usize {
- for (f.read_only, 0..) |r, k| {
+ for (f.layer.lines, 0..) |r, k| {
const at = r.line + k;
if (at == row) return k;
if (at > row) return null;
@@ -366,7 +381,7 @@ pub fn readOnlyRow(f: *const State, row: usize) ?usize {
/// where one starts must leave a line's end before it: a line deleted
/// whole above one is the file's edit; a `J` into one is not).
fn touchesReadOnly(f: *const State, off: usize, len: usize, bytes: []const u8) bool {
- for (f.read_only) |r| {
+ for (f.layer.lines) |r| {
const lo = r.at;
const hi = r.at + r.len;
if (lo > off + len) break;
@@ -557,7 +572,7 @@ pub fn gutterWidth(pane: *const Pane) u16 {
// A query pane's rows carry their own line numbers (Query.zig).
if (pane.query != null) return 0;
// The file's lines: the layer's have no number.
- var lines = (if (file.line_starts.len > 0) file.line_starts.len else lineCount(file.content)) - file.read_only.len;
+ var lines = (if (file.line_starts.len > 0) file.line_starts.len else lineCount(file.content)) - file.layer.lines.len;
var digits: u16 = 1;
while (lines >= 10) : (lines /= 10) digits += 1;
return @max(config.PREFIX_W, digits + 1) + laneCells(pane) + pane.layers.heat;
@@ -813,7 +828,7 @@ pub fn deinit(p: *Pardes, pane: *Pane, file: *State) void {
if (file.line_starts.len > 0 and !index_shared) pardes.memory.freeRaw(p.gpa, indexRoom(file));
if (file.highlights.len > 0) p.tree_sitter_gpa.free(file.highlights);
p.gpa.free(file.pager_spans);
- p.gpa.free(file.read_only);
+ p.gpa.free(file.layer.lines);
locations.freeRows(p.gpa, file.location_rows);
file.context.deinit();
if (file.node_tree) |tree| syntax.freeTree(tree);
@@ -869,7 +884,7 @@ pub fn setRows(p: *Pardes, f: *State, rows: []locations.Row) error{RowsMismatch}
/// caller made anyway, as the text's buffer.
pub fn setContentSpan(p: *Pardes, f: *State, new: []u8, span_in: ?Span) void {
var span = span_in orelse spanOf(f.content, new);
- if (f.read_only.len > 0) span = clearOfReadOnly(f, new, span);
+ if (f.layer.lines.len > 0) span = clearOfReadOnly(f, new, span);
if (edit(p, f, span.head, f.content.len - span.head - span.tail, new[span.head .. new.len - span.tail], new, true, null, .edit)) return;
// Refused (read-only text, said) or no memory: `new` kept until the
// next such, as the editor keeps a text it made (edit.zig
@@ -895,7 +910,7 @@ fn clearOfReadOnly(f: *const State, new: []const u8, span: Span) Span {
// Never back across a read-only line: an edit made on one (a paste
// below it) is no edit of the line above it.
var floor: usize = 0;
- for (f.read_only) |r| {
+ for (f.layer.lines) |r| {
if (r.at + r.len > span.head) break;
floor = r.at + r.len;
}
@@ -928,7 +943,7 @@ pub const How = enum { edit, load, layer };
/// and come back where the file's lines they stood before went (jj.edited
/// carries them).
pub fn load(p: *Pardes, f: *State, new: []u8) void {
- const layer = f.layer;
+ const layer = f.layer.owner;
if (layer != 0) jj.hideLayer(p, f);
defer if (layer != 0) jj.showLayer(p, f, layer);
const span = spanOf(f.content, new);
@@ -938,7 +953,7 @@ pub fn load(p: *Pardes, f: *State, new: []u8) void {
/// `replace` of the file's `len` bytes at `off` (its own offsets, `body`
/// over 9P's), as `load` is a new text: the layer's lines out and back.
pub fn replaceFile(p: *Pardes, f: *State, off: usize, len: usize, bytes: []const u8) bool {
- const layer = f.layer;
+ const layer = f.layer.owner;
if (layer != 0) jj.hideLayer(p, f);
defer if (layer != 0) jj.showLayer(p, f, layer);
return replace(p, f, off, len, bytes);
@@ -1002,14 +1017,14 @@ pub fn relayer(p: *Pardes, f: *State, new: []u8, spans: []ReadOnly, layer: u32)
for (copies[0..ntwins]) |c| p.gpa.free(c);
return false;
}
- p.gpa.free(f.read_only);
- f.read_only = spans;
- f.layer = layer;
+ p.gpa.free(f.layer.lines);
+ f.layer.lines = spans;
+ f.layer.owner = layer;
for (twins[0..ntwins], copies[0..ntwins]) |id, c| {
const tf = &p.panes[id].?.file.?;
- p.gpa.free(tf.read_only);
- tf.read_only = c;
- tf.layer = layer;
+ p.gpa.free(tf.layer.lines);
+ tf.layer.lines = c;
+ tf.layer.owner = layer;
}
for (places.items) |place| {
const pos = positionIn(p.gpa, f, bufferOffset(f, place.at, false));
@@ -1028,7 +1043,7 @@ pub fn relayer(p: *Pardes, f: *State, new: []u8, spans: []ReadOnly, layer: u32)
fn readOnly(f: *const State, off: usize, len: usize, bytes: []const u8, how: How) bool {
if (how == .layer) return false;
if (f.output) |o| if (o.from == .revision) return true;
- return how == .edit and f.read_only.len > 0 and touchesReadOnly(f, off, len, bytes);
+ return how == .edit and f.layer.lines.len > 0 and touchesReadOnly(f, off, len, bytes);
}
/// Said on each pane of `f` (`readOnly`).
@@ -1037,7 +1052,7 @@ fn refuse(p: *Pardes, f: *const State) void {
const pane = slot orelse continue;
if (pane.file) |*state| if (state == f) {
pane.body.refused = true;
- p.setMessage(.at(id), if (f.read_only.len > 0) read_only_said else "a file at a revision is read-only");
+ p.setMessage(.at(id), if (f.layer.lines.len > 0) read_only_said else "a file at a revision is read-only");
};
}
}
@@ -1068,7 +1083,7 @@ fn edit(p: *Pardes, f: *State, off: usize, len: usize, bytes_in: []const u8, who
// edits come with the layer out (undoStep, `load`).
const told = how != .layer;
const file_off = fileOffset(f, off);
- const lines_taken = if (f.read_only.len > 0) std.mem.count(u8, f.content[off..][0..len], "\n") else 0;
+ const lines_taken = if (f.layer.lines.len > 0) std.mem.count(u8, f.content[off..][0..len], "\n") else 0;
const was_clean = f.revision == f.saved_revision;
const old_len = f.content.len;
const new_len = old_len - len + bytes_in.len;
@@ -1082,7 +1097,7 @@ fn edit(p: *Pardes, f: *State, off: usize, len: usize, bytes_in: []const u8, who
const bytes = if (own) p.scratch.allocator().dupe(u8, bytes_in) catch return false else bytes_in;
// The journal keeps the file's text: never a buffer holding the
// layer's lines.
- const swapping = journaled and len >= swap_min and len * 2 >= old_len and f.read_only.len == 0;
+ const swapping = journaled and len >= swap_min and len * 2 >= old_len and f.layer.lines.len == 0;
// A text a join is still sending stays as it is (memory.zig `pin`).
const keep = whole == null and (swapping or pardes.memory.isPinned(f.content));
const fresh: ?[]u8 = whole orelse if (keep) copySpliced(p.gpa, f.content, off, len, bytes) catch return false else null;
@@ -1140,7 +1155,7 @@ fn edit(p: *Pardes, f: *State, off: usize, len: usize, bytes_in: []const u8, who
// copy's tree under it, so that one is left as it is and parsed anew;
// nor with the `Changes` layer's lines in or going (the tree is of the
// file's text, the edit of the buffer's): parsed anew.
- if (f.node_tree) |tree| if (syntax.held_trees == null and f.node_tree_edits == f.revision and told and f.read_only.len == 0) {
+ if (f.node_tree) |tree| if (syntax.held_trees == null and f.node_tree_edits == f.revision and told and f.layer.lines.len == 0) {
syntax.editTree(tree, f.content[0..off], f.content[off..][0..len], bytes);
f.node_tree_edits = f.revision +% 1;
};
@@ -1169,9 +1184,9 @@ fn edit(p: *Pardes, f: *State, off: usize, len: usize, bytes_in: []const u8, who
}
// The read-only lines after the edit move with what it put in and took
// out, and the layer's ghosts with them (none is in it: refused).
- if (told and f.read_only.len > 0) {
+ if (told and f.layer.lines.len > 0) {
const lines_put = std.mem.count(u8, bytes, "\n");
- for (f.read_only) |*r| if (r.at >= off + len) {
+ for (f.layer.lines) |*r| if (r.at >= off + len) {
r.at = r.at - len + bytes.len;
r.line = @intCast(r.line + lines_put - lines_taken);
};
@@ -1210,7 +1225,7 @@ fn edit(p: *Pardes, f: *State, off: usize, len: usize, bytes_in: []const u8, who
if (!told and tf.context.revision == f.revision -% 1) tf.context.revision = f.revision;
// Its copy of the read-only lines, moved as this one's were (the
// layer's own edit sets them after, jj.showLayer).
- if (told and tf.read_only.len == f.read_only.len) @memcpy(tf.read_only, f.read_only);
+ if (told and tf.layer.lines.len == f.layer.lines.len) @memcpy(tf.layer.lines, f.layer.lines);
tf.revision = f.revision;
tf.saved_revision = f.saved_revision;
tf.saved_hash = f.saved_hash;
@@ -1383,13 +1398,12 @@ pub fn zerox(p: *Pardes, from: usize, to: usize) !*Pane {
}
// The layer's lines are the buffer's: a twin shows them too, a copy of
// their places its own.
- const read_only = try p.gpa.dupe(ReadOnly, f.read_only);
+ const read_only = try p.gpa.dupe(ReadOnly, f.layer.lines);
errdefer p.gpa.free(read_only);
const pane = try p.newDocPane(to);
pane.layers.lanes = src.layers.lanes;
pane.file = .{
- .read_only = read_only,
- .layer = f.layer,
+ .layer = .{ .owner = f.layer.owner, .lines = read_only },
.path = path,
.content = f.content,
.cap = f.cap,
@@ -1752,7 +1766,7 @@ pub fn undoStep(p: *Pardes, pane: *Pane, back: bool) error{OutOfMemory}!void {
if (if (back) j.done == 0 else j.done == j.steps.items.len) return;
const at = if (back) j.done - 1 else j.done;
const now = placeOf(pane, f);
- const layer = f.layer;
+ const layer = f.layer.owner;
if (layer != 0) jj.hideLayer(p, f);
defer if (layer != 0) jj.showLayer(p, f, layer);
if (!turn(p, f, at, back)) return error.OutOfMemory;
@@ -1991,7 +2005,7 @@ pub fn refreshHighlights(p: *Pardes) void {
if (!f.tree_context and pane.colorAlgo() == .source) paintAhead(p, pane, f);
continue;
}
- if (f.read_only.len > 0) {
+ if (f.layer.lines.len > 0) {
highlightLayered(p, pane, f);
continue;
}
@@ -2048,7 +2062,7 @@ pub fn refreshHighlights(p: *Pardes) void {
/// the frame, 11-17 ms in ReleaseSafe.
fn paintAhead(p: *Pardes, pane: *Pane, f: *State) void {
// A worker paints the buffer: with the layer's lines in it, never.
- if (f.read_only.len > 0) return;
+ if (f.layer.lines.len > 0) return;
const seen = &p.stream.ahead_seen;
// A view standing still (typing in it) needs nothing ahead: each edit
// is a new revision, and a paint asked at every keystroke was a copy
@@ -2086,7 +2100,7 @@ fn highlightLayered(p: *Pardes, pane: *Pane, f: *State) void {
// The file's bytes between the read-only lines, a stretch at a time.
var from: usize = 0;
var at = start;
- for (f.read_only) |r| {
+ for (f.layer.lines) |r| {
if (r.at + r.len <= start) continue;
if (r.at >= end) break;
const n = @min(r.at -| at, got.len -| from);
@@ -2155,7 +2169,7 @@ pub fn bodyText(tab: u16, arena: std.mem.Allocator, pane: *Pane, f: *State) ![]c
geometry(tab, pane);
const out = try arena.alloc(u8, pane.geometry_len);
const width = wrapWidth(pane, pane.view.wrap);
- const filled = fillBody(tab, out, pane, f, width, false);
+ const filled = if (f.layer.lines.len == 0) fillBody(false, tab, out, pane, f, width, false) else fillBody(true, tab, out, pane, f, width, false);
std.debug.assert(filled == out.len);
return out;
}
@@ -2199,7 +2213,7 @@ fn mapRows(tab: u16, pane: *Pane, f: *State) usize {
pane.body_wrapped = width > 0;
f.tables.ensure(tab, pane.gpa, f);
prepareContextRows(pane, f);
- return fillBody(tab, null, pane, f, width, true);
+ return if (f.layer.lines.len == 0) fillBody(false, tab, null, pane, f, width, true) else fillBody(true, tab, null, pane, f, width, true);
}
/// Everything the geometry is made of, hashed: the text (its revision and
@@ -2227,8 +2241,10 @@ fn geometryKey(pane: *const Pane, f: *const State) u64 {
/// Run the file-body row walk. With no destination it is the exact sizing
/// pass; with one it fills that allocation and records the wrapping map.
/// A read-only line (the `Changes` layer's) is a line as any, wrapped as
-/// any; the numbers are the file's, and it has none.
-fn fillBody(tab: u16, dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool) usize {
+/// any; the numbers are the file's, and it has none (`layered`: a body with
+/// none walks without asking: beside that walk its loop compiled worse, a
+/// row walk of a file with no layer 2% dearer).
+fn fillBody(comptime layered: bool, tab: u16, dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool) usize {
if (record_wrap) pane.wrap_n = 0;
const prefix_width = gutterWidth(pane);
// Where a number ends: a blank, then the heat lane and the lanes after it.
@@ -2276,9 +2292,9 @@ fn fillBody(tab: u16, dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_w
const prefix = out[written..][0..prefix_width];
@memset(prefix, ' ');
// A read-only line has no number; the others, the file's.
- const numbered = f.read_only.len == 0 or readOnlyRow(f, row) == null;
+ const numbered = !layered or readOnlyRow(f, row) == null;
if (at == 0 and prefix.len > 0 and numbered) {
- var lineno = (if (f.read_only.len == 0) row else fileRow(f, row)) + 1;
+ var lineno = (if (layered) fileRow(f, row) else row) + 1;
var digit: usize = number_end;
if (row == end_slot) {
prefix[digit - 1] = '~';
@@ -2340,7 +2356,7 @@ fn fillBody(tab: u16, dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_w
/// lane each of the pane's pinned changes after the line number (the
/// gutter `lanes` cells wider), a line one added whole green across
/// it, a changed line's words, and the ghost lines (the buffer's
-/// read-only lines, `State.read_only`) inked (jj.paint).
+/// read-only lines, `State.layer.lines`) inked (jj.paint).
/// 4. churn (`Churn`): a heat lane after the number and a strip by the
/// scroll thumb.
///
diff --git a/core/dump.zig b/core/dump.zig
index c0a84ffe..29aebce8 100644
--- a/core/dump.zig
+++ b/core/dump.zig
@@ -165,7 +165,7 @@ const Slim = struct {
f.history = &empty;
// Not with the `Changes` layer's lines in it: the disk has the
// file's text, not the buffer.
- if (f.output == null and f.revision == f.saved_revision and f.read_only.len == 0 and filesystem.localPath(f.path) != null) f.content = &.{};
+ if (f.output == null and f.revision == f.saved_revision and f.layer.lines.len == 0 and filesystem.localPath(f.path) != null) f.content = &.{};
return s;
}
diff --git a/core/edit.zig b/core/edit.zig
index 0b08dc9e..3e57927a 100644
--- a/core/edit.zig
+++ b/core/edit.zig
@@ -777,7 +777,7 @@ fn treeIndent(e: Editor, t: *Text, text: []const u8, row: usize, at: usize) Erro
const tree = normal.fileTree(e.p, f) orelse return null;
// The tree is of the file's text, in its lines and offsets (the
// `Changes` layer's lines are none of it).
- if (f.read_only.len == 0) return indents.forNewline(e.scratch, l, tree, text, row, at);
+ if (f.layer.lines.len == 0) return indents.forNewline(e.scratch, l, tree, text, row, at);
return indents.forNewline(e.scratch, l, tree, try panes.File.fileText(f, e.scratch), panes.File.fileRow(f, row), panes.File.fileOffset(f, at));
}
diff --git a/core/jj.zig b/core/jj.zig
index b99419b0..176ead49 100644
--- a/core/jj.zig
+++ b/core/jj.zig
@@ -204,7 +204,7 @@ pub fn looked(p: *Pardes, id: usize, dir: []const u8, text: []const u8, at: look
/// 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. Shown,
-/// its ghosts are lines of the pane's buffer, read-only (File.read_only,
+/// its ghosts are lines of the pane's buffer, read-only (File.layer.lines,
/// `showLayer`), so the layer is the pane's: every view of it shows it or
/// none does. From two jj runs off the loop (`Ask`): the changes
/// with their diffs of the file (`jj log -p --git`, the diffs read with
@@ -264,7 +264,7 @@ pub fn churned(p: *Pardes, serial: u32) ?*Heat {
/// Pane `serial`'s answers let go (the pane's end); a twin showing its
/// layer, its lines out.
pub fn forget(p: *Pardes, serial: u32) void {
- for (p.panes) |slot| if (slot) |pane| if (pane.file) |*f| if (f.layer == serial and pane.serial != serial) {
+ for (p.panes) |slot| if (slot) |pane| if (pane.file) |*f| if (f.layer.owner == serial and pane.serial != serial) {
hideLayer(p, f);
setLanes(p, f, false);
};
@@ -470,7 +470,7 @@ fn pinWord(c: pardes.builtins.Ctx, kind: Ask.Kind) void {
}
/// The layer shown in every view of every pane on `f`'s buffer, or in
-/// none: its lines are the buffer's (File.read_only). A view's lanes take
+/// none: its lines are the buffer's (File.layer.lines). A view's lanes take
/// cells by its frontend (File.Layers.lanes).
fn setLanes(p: *Pardes, f: *const File.State, on: bool) void {
for (p.panes) |slot| {
@@ -958,7 +958,7 @@ pub fn edited(p: *Pardes, f: *const File.State, off: usize, len: usize, bytes: [
// The values are the file's lines': the layer's lines before the edit
// are none of them.
var shown_before: usize = 0;
- for (f.read_only) |r| {
+ for (f.layer.lines) |r| {
if (r.at >= off) break;
shown_before += 1;
}
@@ -970,7 +970,7 @@ pub fn edited(p: *Pardes, f: *const File.State, off: usize, len: usize, bytes: [
const shown = if (p.panes[id].?.file) |*shown| shown else continue;
if (shown.content.ptr != f.content.ptr) continue;
// The layer shown: its ghosts stand where its lines are (`placed`).
- const placed_by_lines = c.serial == f.layer;
+ const placed_by_lines = c.serial == f.layer.owner;
splice(p.gpa, c, f.content, off, len, bytes, shown_before, placed_by_lines) catch {
// No room for it: its values would lie, so it goes; the one
// shown stays (its lines are the buffer's, its places theirs).
@@ -1016,7 +1016,7 @@ fn splice(gpa: std.mem.Allocator, c: *Changes, text: []const u8, off: usize, len
/// A value a line, `values`, spliced as `splice` says, a line put in
/// `none`; null when no line is taken or put. `text` is the buffer, whose
/// `shown_before` lines before the edit are the layer's (none of the
-/// file's: File.read_only).
+/// file's: File.layer.lines).
fn spliceValues(comptime T: type, gpa: std.mem.Allocator, values: *[]T, none: T, text: []const u8, off: usize, len: usize, bytes: []const u8, shown_before: usize) error{OutOfMemory}!?struct { from: usize, take: usize, put: usize } {
const taken = std.mem.count(u8, text[off..][0..len], "\n");
const put = std.mem.count(u8, bytes, "\n");
@@ -1222,9 +1222,9 @@ fn heatOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, logged: []const u8,
/// its place in the file (File.relayer).
pub fn showLayer(p: *Pardes, f: *File.State, owner: u32) void {
const ch = answered(p, owner) orelse return hideLayer(p, f);
- if (f.layer != 0) hideLayer(p, f);
+ if (f.layer.owner != 0) hideLayer(p, f);
// Not out (no memory): nothing more.
- if (f.layer != 0) return;
+ if (f.layer.owner != 0) return;
// The file's text, the layer out.
const text = f.content;
var size = text.len;
@@ -1271,7 +1271,7 @@ pub fn showLayer(p: *Pardes, f: *File.State, owner: u32) void {
/// every view keeps its place in the file: one in a line that leaves goes
/// to the start of the file line it stood before (File.relayer).
pub fn hideLayer(p: *Pardes, f: *File.State) void {
- if (f.layer == 0) return;
+ if (f.layer.owner == 0) return;
const text = File.fileText(f, p.scratch.allocator()) catch return;
const new = pardes.memory.dupeUnfilled(p.gpa, text) catch return;
if (!File.relayer(p, f, new, &.{}, 0)) pardes.memory.freeRaw(p.gpa, new);
@@ -1280,12 +1280,12 @@ pub fn hideLayer(p: *Pardes, f: *File.State) void {
/// A session loaded from a dump that kept a layer shown as a view's bit
/// and no lines (wire 31 and older: the ghost rows were drawn, not the
/// buffer's): each pane whose views showed it, its lines in its buffer
-/// and shown in every view (File.read_only), its places kept in the file.
+/// and shown in every view (File.layer.lines), its places kept in the file.
pub fn loaded(p: *Pardes) void {
for (p.panes) |slot| {
const pane = slot orelse continue;
const f = if (pane.file) |*file| file else continue;
- if (f.layer != 0 or answered(p, pane.serial) == null) continue;
+ if (f.layer.owner != 0 or answered(p, pane.serial) == null) continue;
const shown = pane.layers.lanes > 0 or for (0..pardes.views.max) |k| {
if (k != p.live and p.views[k] != null and pane.pv[k].layers.lanes > 0) break true;
} else false;
@@ -1298,9 +1298,9 @@ pub fn loaded(p: *Pardes) void {
/// After an edit of `f`'s buffer (File.edit): the shown layer's ghosts
/// stand before the file lines their lines stand before.
pub fn placed(p: *Pardes, f: *const File.State) void {
- const ch = answered(p, f.layer) orelse return;
- if (ch.ghosts.len != f.read_only.len) return;
- for (ch.ghosts, f.read_only) |*g, r| g.at = r.line;
+ const ch = answered(p, f.layer.owner) orelse return;
+ if (ch.ghosts.len != f.layer.lines.len) return;
+ for (ch.ghosts, f.layer.lines) |*g, r| g.at = r.line;
}
const Read = union(enum) { refused: []u8, read: Changes };
@@ -2034,7 +2034,7 @@ fn ownerOf(ch: *const Changes, f: *const File.State, row: usize) PinIndex {
pub fn nextChange(p: *Pardes, pane: *const Pane, from: usize, forward: bool) ?usize {
if (pane.layers.lanes == 0) return null;
const f = if (pane.file) |*file| file else return null;
- const ch = answered(p, f.layer) orelse return null;
+ const ch = answered(p, f.layer.owner) orelse return null;
const n = File.lineCount(f.content);
var row = from;
while (true) {
@@ -2057,7 +2057,7 @@ pub fn nextChange(p: *Pardes, pane: *const Pane, from: usize, forward: bool) ?us
pub fn lookGhost(p: *Pardes, id: usize, vr: i32, col: i32) bool {
const pane = p.panes[id].?;
const f = if (pane.file) |*file| file else return false;
- const ch = answered(p, f.layer) orelse return false;
+ const ch = answered(p, f.layer.owner) orelse return false;
const tab = p.settings.tab;
const w = pane.wrapAt(tab, vr);
if (w.line < 0 or w.at != 0) return false;
@@ -2379,7 +2379,7 @@ pub fn railHeat(p: *Pardes, s: *pardes.Surface, pane: *Pane, id: usize, rail: pa
fn paintLanes(p: *Pardes, s: *pardes.Surface, pane: *Pane, r: pardes.Rect, tx: u16, tw: u16, body_h: u16) void {
const f = if (pane.file) |*file| file else return;
- const ch = answered(p, f.layer) orelse return;
+ const ch = answered(p, f.layer.owner) orelse return;
if (ch.lines.len == 0) return;
const tab = p.settings.tab;
var buf: [8][3]u8 = undefined;
@@ -2682,7 +2682,7 @@ test "the layer is the pane's: Changes in one view shows its lines in every view
try testing.expectEqual(before + levels, File.gutterWidth(pane));
const shown = try gpa.dupe(u8, pane.file.?.content);
defer gpa.free(shown);
- try testing.expect(pane.file.?.read_only.len > 0);
+ try testing.expect(pane.file.?.layer.lines.len > 0);
// Shown in the other view too, its lines the same.
p.toView(other);
try testing.expectEqual(levels, pane.layers.lanes);
@@ -2701,7 +2701,7 @@ test "the layer is the pane's: Changes in one view shows its lines in every view
try testing.expectEqual(0, pane.layers.lanes);
try testing.expectEqual(before, File.gutterWidth(pane));
try testing.expectEqualStrings(Repo.two, pane.file.?.content);
- try testing.expectEqual(@as(usize, 0), pane.file.?.read_only.len);
+ try testing.expectEqual(@as(usize, 0), pane.file.?.layer.lines.len);
}
test "a client replays Changes from what the session's jj answered and ends equal" {
@@ -3544,7 +3544,7 @@ test "the node keys and the indent read the file's text: Alt-o and a function's
for ([_]bool{ true, false }) |layer| {
p.view().active = id;
if (!layer) p.update(.{ .command = "Changes" });
- try testing.expectEqual(layer, f.read_only.len > 0);
+ try testing.expectEqual(layer, f.layer.lines.len > 0);
const row: i32 = if (layer) 4 else 2;
for (std.enums.values(Gesture), 0..) |g, k| {
p.view().active = id;
@@ -3566,7 +3566,7 @@ test "the node keys and the indent read the file's text: Alt-o and a function's
for ([_]bool{ false, true }, &opened) |layer, *o| {
p.view().active = id;
if (layer) p.update(.{ .command = "Changes" });
- try testing.expectEqual(layer, f.read_only.len > 0);
+ try testing.expectEqual(layer, f.layer.lines.len > 0);
Lines.at(pane, if (layer) 4 else 2, 4);
Lines.send(p, "ox\x1b");
o.* = try arena.allocator().dupe(u8, try File.fileText(f, arena.allocator()));
@@ -3651,7 +3651,7 @@ test "THE FILE'S TEXT: with the layer's lines in the buffer, every reader of the
const pane = p.panes[id].?;
const f = &pane.file.?;
if (shown) p.update(.{ .command = "Changes @-" });
- try testing.expectEqual(shown, f.read_only.len > 0);
+ try testing.expectEqual(shown, f.layer.lines.len > 0);
// The same edit of a file line, `c2();` (its line 3).
p.update(.{ .command = "Look :3" });
Lines.send(p, ";A // e\x1b");
@@ -3701,11 +3701,11 @@ test "THE FILE'S TEXT: with the layer's lines in the buffer, every reader of the
p.update(.{ .command = "Changes @-" });
got.lines = try keep.dupe(Line, answered(p, pane.serial).?.lines);
if (!shown) p.update(.{ .command = "Changes" });
- try testing.expectEqual(shown, f.read_only.len > 0);
+ try testing.expectEqual(shown, f.layer.lines.len > 0);
// A Get: the file's text from where it was read, the layer kept.
p.update(.{ .command = "Get" });
got.gotten = try keep.dupe(u8, try File.fileText(f, arena.allocator()));
- try testing.expectEqual(shown, f.read_only.len > 0);
+ try testing.expectEqual(shown, f.layer.lines.len > 0);
}
const off, const on = seen;
try testing.expectEqualStrings("fn f() void {\n a();\n c2(); // e\n}\n", off.saved);
@@ -3737,7 +3737,7 @@ test "an edit made while the layer is shown is the file's: journaled in its line
// Undone while shown, redone.
Lines.send(p, "u");
try testing.expectEqualStrings(Lines.cut_text, try File.fileText(f, arena.allocator()));
- try testing.expectEqual(@as(usize, 3), f.read_only.len);
+ try testing.expectEqual(@as(usize, 3), f.layer.lines.len);
try testing.expectEqual(@as(i32, 4), pane.body.cur_row);
Lines.send(p, "U");
try testing.expectEqualStrings(typed, try File.fileText(f, arena.allocator()));
@@ -3816,7 +3816,7 @@ test "a session dumped by a build whose layer was a view's bit and no lines (wir
const back = q.panes[q.view().active].?;
const bf = &back.file.?;
try testing.expectEqualStrings(Lines.cut_text, try File.fileText(bf, q.scratch.allocator()));
- try testing.expectEqual(shown, bf.read_only.len == 3);
+ try testing.expectEqual(shown, bf.layer.lines.len == 3);
try testing.expectEqual(shown, back.layers.lanes > 0);
// The cursor on `c2();` (the file's line 3) as it was.
try testing.expectEqualStrings(" c2();", File.sourceLine(back, back.body.cur_row));
@@ -3902,7 +3902,7 @@ test "a client replays the layer's lines and an edit refused among them, and end
const rf = &r.core().panes[id].?.file.?;
try testing.expectEqualStrings("fn f() void {\n a();\n c2();;\n}\n", try File.fileText(af, a.core.scratch.allocator()));
try testing.expectEqualStrings(af.content, rf.content);
- try testing.expectEqualSlices(File.ReadOnly, af.read_only, rf.read_only);
+ try testing.expectEqualSlices(File.ReadOnly, af.layer.lines, rf.layer.lines);
try testing.expectEqual(pardes.tape.digestOf(a.core), pardes.tape.digestOf(r.core()));
try R.loadsAsSession(a, 2);
}
diff --git a/core/look.zig b/core/look.zig
index 2e3d9e57..b240b6e2 100644
--- a/core/look.zig
+++ b/core/look.zig
@@ -738,7 +738,7 @@ pub fn focusPaneLine(p: *Pardes, id: usize, at_in: Spot, landing: enum { center,
if (at_in.line == 0) return;
// A place's line is the file's: past the `Changes` layer's lines.
var at = at_in;
- if (pane.file) |*f| if (f.read_only.len > 0) {
+ if (pane.file) |*f| if (f.layer.lines.len > 0) {
at.line = @intCast(panes.File.bufferRow(f, at.line - 1) + 1);
if (at.end_line != 0) at.end_line = @intCast(panes.File.bufferRow(f, at.end_line - 1) + 1);
};
@@ -1048,6 +1048,12 @@ fn lookUnresolved(p: *Pardes, id: usize, pane: *Pane, trimmed: []const u8, text:
// 9P is no keyboard input, and searches whatever the key mode.
if (pane.addon != null or (pane.body.mode == .tty and !p.fs.serving)) return;
if (text.len == 0) return;
+ // A jj change id (eight of its letters or more, k to z, as jj log
+ // shows them) in a jj repository: its patch (jj.diffChange); one that
+ // names no change is searched for. Look's own, not a plumbing rule: the
+ // rules are read at a session's first look, a file's open among them,
+ // and that rule cost every open (perf: open +8.8k instructions).
+ if (trimmed.len >= 8 and @import("jj.zig").isChangeId(trimmed) and @import("jj.zig").diffChange(p, id, trimmed, false)) return;
if (pane.file != null) return lookWord(p, id, pane, text);
p.word_look = true;
defer p.word_look = false;
@@ -1400,7 +1406,7 @@ fn settleLine(p: *Pardes, id: usize, path: []const u8, at: Spot, before: usize,
const shown = p.panes[p.view().active] orelse return;
const f = if (shown.file) |*file| file else return;
// N is the file's line N (the `Changes` layer's lines have no number).
- if (at.line > panes.File.nlines(p.gpa, f) - f.read_only.len) {
+ if (at.line > panes.File.nlines(p.gpa, f) - f.layer.lines.len) {
if (opened) |free| p.removePane(free, null) catch |err| p.reportError(.at(id), "look", err);
if (p.panes[before] != null) p.view().active = before;
return missedLine(p, id, path, at.line);
diff --git a/core/ninep/pane.zig b/core/ninep/pane.zig
index 2616c735..093a9223 100644
--- a/core/ninep/pane.zig
+++ b/core/ninep/pane.zig
@@ -150,9 +150,11 @@ pub const State = struct {
/// buffer less its read-only lines, the `Changes` layer's, which are no
/// text of the file's). Every address, `dot` and range over 9P is of this
/// text (`fileDot`); a write to it is the file's (`spliceBody`).
-pub fn bodyOf(p: *Pardes, pane: *const Pane) []const u8 {
- if (pane.file) |*f| return panes.File.fileText(f, p.scratch.allocator()) catch "";
- return "";
+pub inline fn bodyOf(p: *Pardes, pane: *const Pane) []const u8 {
+ const f = if (pane.file) |*file| file else return "";
+ // No layer shown: the buffer is the file's text (a length test).
+ if (f.layer.lines.len == 0) return f.content;
+ return panes.File.fileText(f, p.scratch.allocator()) catch "";
}
/// The buffer the editor edits (with the layer's lines): what the
@@ -165,7 +167,7 @@ fn bufferOf(pane: *const Pane) []const u8 {
/// Whether 9P reads of the pane are a copy of its file's text, not a
/// region of its buffer (`fsPayload` reads the buffer).
fn layered(pane: *const Pane) bool {
- return if (pane.file) |*f| f.read_only.len > 0 else false;
+ return if (pane.file) |*f| f.layer.lines.len > 0 else false;
}
pub fn fileOf(pane: *Pane) ?*panes.File.State {
@@ -301,20 +303,22 @@ pub fn showOffset(tab: u16, pane: *Pane, off: usize) void {
/// `dotOf` in the file's text's offsets, as 9P serves it (`bodyOf`): a dot
/// in a read-only line is after the file line above it.
-pub fn fileDot(pane: *Pane) State.Range {
+pub inline fn fileDot(pane: *Pane) State.Range {
const d = dotOf(pane);
const f = if (pane.file) |*file| file else return d;
+ if (f.layer.lines.len == 0) return d;
return .{ .q0 = clip(panes.File.fileOffset(f, d.q0)), .q1 = clip(panes.File.fileOffset(f, d.q1)) };
}
/// `setDot` from the file's text's offsets (`fileDot`).
-pub fn setFileDot(tab: u16, pane: *Pane, r: State.Range) void {
+pub inline fn setFileDot(tab: u16, pane: *Pane, r: State.Range) void {
const f = if (pane.file) |*file| file else return setDot(tab, pane, r);
+ if (f.layer.lines.len == 0) return setDot(tab, pane, r);
setDot(tab, pane, .{ .q0 = clip(panes.File.bufferOffset(f, r.q0, false)), .q1 = clip(panes.File.bufferOffset(f, r.q1, r.q1 > r.q0)) });
}
/// `showOffset` of a file's text's offset.
-pub fn showFileOffset(tab: u16, pane: *Pane, off: usize) void {
+pub inline fn showFileOffset(tab: u16, pane: *Pane, off: usize) void {
const f = if (pane.file) |*file| file else return showOffset(tab, pane, off);
showOffset(tab, pane, panes.File.bufferOffset(f, off, false));
}
diff --git a/core/plumbing b/core/plumbing
index 7292577f..4e8cd702 100644
--- a/core/plumbing
+++ b/core/plumbing
@@ -43,15 +43,6 @@ data matches '[0-9a-f]*[0-9][0-9a-f]*'
data matches '[0-9a-f]*[a-f][0-9a-f]*'
plumb start Diff $0
-# a jj change id looked at in the editor (eight or more of its letters,
-# k to z, as jj log shows them), in a jj repository: jj show, its header
-# and its hunks, stacked in a +Diff (a word that names no change: Diff
-# declines and the word is searched for)
-type is text
-src is pardes
-data matches '[k-z]{8,32}'
-plumb start Diff $0
-
# a diff paged (git show, git log -p) is shown stacked in a +Diff in
# its +Pager's place
type is text/x-diff
diff --git a/core/replica.zig b/core/replica.zig
index 6c4f0b2c..57dd4eed 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -8398,6 +8398,7 @@ const hand_walked = .{
.{ @import("locations.zig").Row, "a client joined from a dump makes a `/` query's rows as the session does" },
.{ @import("jj.zig").Session, "a client replays Changes from what the session's jj answered and ends equal" },
.{ pardes.panes.File.Layers, "a client replays Changes from what the session's jj answered and ends equal" },
+ .{ pardes.panes.File.Layer, "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" },
};
test "every type the core's walk reaches that hashes or dumps itself by hand has a test joining a client over it (hand_walked)" {