diff options
| -rw-r--r-- | core/File.zig | 13 | ||||
| -rw-r--r-- | core/Output.zig | 5 | ||||
| -rw-r--r-- | core/builtins.zig | 11 | ||||
| -rw-r--r-- | core/config.zig | 1 | ||||
| -rw-r--r-- | core/edit.zig | 2 | ||||
| -rw-r--r-- | core/jj.zig | 337 | ||||
| -rw-r--r-- | core/look.zig | 2 | ||||
| -rw-r--r-- | core/panes.zig | 2 | ||||
| -rw-r--r-- | core/root.zig | 1 | ||||
| -rw-r--r-- | core/tape.zig | 3 | ||||
| -rw-r--r-- | docs/typ/builtins-gui.json | 1 | ||||
| -rw-r--r-- | docs/typ/builtins-tui.json | 1 | ||||
| -rw-r--r-- | docs/typ/guide.typ | 10 |
13 files changed, 385 insertions, 4 deletions
diff --git a/core/File.zig b/core/File.zig index 813e172f..01aaeec8 100644 --- a/core/File.zig +++ b/core/File.zig @@ -697,6 +697,9 @@ const swap_min = 64 << 10; /// a new buffer in and gives the old to the journal whole (a swap); an /// undo's swap back hands the buffer it replaces to `kept`. fn edit(p: *Pardes, f: *State, off: usize, len: usize, bytes_in: []const u8, whole: ?[]u8, journaled: bool, kept: ?*[]u8) bool { + // A file at a revision is read-only (jj.zig): a key's splice changes + // nothing (a whole text is the editor's to refuse, edit.zig). + if (whole == null) if (f.output) |o| if (o.from == .revision) return false; const old_len = f.content.len; const new_len = old_len - len + bytes_in.len; const span: Span = .{ .head = off, .tail = old_len - off - len }; @@ -1607,7 +1610,7 @@ pub fn refreshHighlights(p: *Pardes) void { syntax.highlightLocationRows(p.tree_sitter_gpa, f.content, f.location_rows) else syntax.highlightLocations(p.tree_sitter_gpa, f.content, start, end), - else => syntax.highlightFileRange(p.tree_sitter_gpa, f.path, f.content, start, end), + else => syntax.highlightFileRange(p.tree_sitter_gpa, langPath(f), f.content, start, end), }) catch { f.syntax_dirty = false; continue; @@ -1641,7 +1644,13 @@ fn paintAhead(p: *Pardes, pane: *Pane, f: *State) void { const end = @max(start, lineStart(p.gpa, f, f.scroll + (if (seen.dir > 0) 4 * rows else rows) + SYNTAX_CONTEXT_AFTER_ROWS)); // Painted already, as far as that goes. if (f.highlights.len > 0 and start >= f.highlight_start and end <= f.highlight_start + f.highlights.len) return; - Stream.paintAhead(p, pane.serial, f.revision, f.path, f.content, start, end); + Stream.paintAhead(p, pane.serial, f.revision, langPath(f), f.content, start, end); +} + +/// The path a text's language is known by: a file at a revision's +/// (jj.zig) without its `@rev`. +pub fn langPath(f: *const State) []const u8 { + return if (@import("jj.zig").of(f)) |r| r.path else f.path; } pub fn supportsContext(pane: *const Pane) bool { diff --git a/core/Output.zig b/core/Output.zig index c7bfde14..09ec2a51 100644 --- a/core/Output.zig +++ b/core/Output.zig @@ -38,6 +38,8 @@ pub const Origin = union(enum) { /// A query pane's +Preview (Query.zig): a file's text shown, not yet /// its pane; Enter promotes it to one where it stands. preview, + /// A file at a revision (jj.zig), its arg the revision. + revision, }; /// An output's argument is typed in the bounded one-line tag storage. @@ -163,6 +165,7 @@ pub fn traits(o: Origin) Traits { .kind => .{ .name = "", .steps = true, .locations = true }, .unsaved => .{ .name = config.unsaved_buffer, .doc = true }, .preview => .{ .name = config.preview_buffer, .doc = true }, + .revision => .{ .name = "", .doc = true }, // Named for its directory, not a `+` name in it. .dir => .{ .name = "", .doc = true }, .cmd => |b| builtins.registry.outputTraits(b) orelse unreachable, @@ -264,7 +267,7 @@ fn sortResults(arena: std.mem.Allocator, from: Origin, content: []u8, anchor: ?u => {}, else => return anchor, }, - .errors, .kind, .unsaved, .dir, .preview => return anchor, + .errors, .kind, .unsaved, .dir, .preview, .revision => return anchor, } if (content.len == 0) return anchor; const trailing_newline = content[content.len - 1] == '\n'; diff --git a/core/builtins.zig b/core/builtins.zig index b516d543..18b49a41 100644 --- a/core/builtins.zig +++ b/core/builtins.zig @@ -983,6 +983,11 @@ pub const Save = struct { }; const path = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); if (path.len > 0) return exec.saveTo(c.p, c.id, path); + // A file at a revision (jj.zig) is read-only: written elsewhere only. + if (c.pane.file) |*file| if (@import("jj.zig").of(file) != null) { + var said: pardes.Kind.Buf(limits.host_path_cap + 64) = .{}; + return c.p.reportFailure(c.id, said.print("Save: {s} is a revision, read-only (Save <path> writes it)", .{file.path[0..@min(file.path.len, limits.host_path_cap)]})); + }; // A `+` name is a generated pane's (+Tutor), no file of its own: // a bare Save asks for a path, as a +New scratch's does. if (c.pane.file) |file| if (file.output == null and !std.mem.startsWith(u8, std.Io.Dir.path.basename(file.path), "+")) return exec.saveFile(c.p, c.id); @@ -1069,6 +1074,12 @@ pub const Syntax = struct { } }; +/// Show a file as it was at revision `rev` (jj), read-only, beside its pane; in such a pane, that file at another revision in its place, or bare, the file. +pub const At = struct { + pub const takes_arg = true; + pub const run = @import("jj.zig").word; +}; + /// Stack a diff's hunks as a diff viewer shows them, each under its place and the declarations around it, in a +Diff; on a +Diff, show the diff itself as text. `Diff <file>` stacks that diff's, `Diff <revision>` git show's. /// The diff viewer's one registration: its word and traits here, all else /// its own (hunks.zig). diff --git a/core/config.zig b/core/config.zig index 998063cc..361a59ed 100644 --- a/core/config.zig +++ b/core/config.zig @@ -76,6 +76,7 @@ pub const leader_path = paths: { .DelBelow = null, .Filter = null, .Diff = null, + .At = null, .Mode = null, .Togglettymode = null, .Collapse = null, diff --git a/core/edit.zig b/core/edit.zig index 0014f681..7a57fd09 100644 --- a/core/edit.zig +++ b/core/edit.zig @@ -705,6 +705,8 @@ fn setEditTextSpan(e: Editor, t: *Text, new: []u8, known_end: ?modal.Cursor, spa return; } const pane = t.pane() orelse return retireEditText(e, new); + // A file at a revision is read-only (jj.zig). + if (pane.file) |*f| if (f.output) |o| if (o.from == .revision) return retireEditText(e, new); // A live query pane's rows are its line 1's (Query.zig): an edit there // is refused, as a tag's prefix refuses one, and one from line 1 into // them is cut at its end. The rows' metadata stays theirs across an diff --git a/core/jj.zig b/core/jj.zig new file mode 100644 index 00000000..368d03a5 --- /dev/null +++ b/core/jj.zig @@ -0,0 +1,337 @@ +//! A file at a revision, as jj shows it (PARDES.md "Changes on the source +//! view"): the address `path@rev`, with a place `path@rev:line`, which a +//! Look resolves anywhere, and `At <rev>` in a file's pane. +//! +//! What jj says is the session machine's: it is run out of the turn as a +//! site of the step's tape (`Site.jj`), its answer recorded; a replica +//! replays the answer and never runs jj. A revision's pane is an output +//! (`Output.Origin.revision`, its argument the revision), named +//! `path@rev`, coloured as its file (File.langPath), read-only (File.edit +//! refuses its text a change; a bare Save says why). +const std = @import("std"); +const pardes = @import("root.zig"); +const Pardes = pardes.Pardes; +const Pane = pardes.Pane; +const File = pardes.panes.File; +const Output = pardes.panes.Output; +const look = @import("look.zig"); +const layout = @import("layout.zig"); + +/// What jj answered: why not, in its own words (its first line, without +/// `Error: `), or the file's bytes. The caller's, in the allocator the site +/// was given. +pub const Shown = union(enum) { refused: []u8, bytes: []u8 }; + +/// The longest text a revision's pane takes. +const bytes_max = 256 << 20; + +/// `text`, not a file of its own, read as `path@rev`: the text before its +/// first `@` the path, the rest the revision (`main`, `@-`, `main@origin`). +pub fn split(text: []const u8) ?struct { path: []const u8, rev: []const u8 } { + const at = std.mem.indexOfScalar(u8, text, '@') orelse return null; + if (at == 0 or at + 1 == text.len or text[at - 1] == '/') return null; + return .{ .path = text[0..at], .rev = text[at + 1 ..] }; +} + +/// The file at `path` (absolute) at revision `rev`, as jj shows it. +pub fn show(p: *Pardes, path: []const u8, rev: []const u8) Shown { + const set = fileset(p.scratch.allocator(), path) catch return refusal(p.gpa, "out of memory"); + return p.tape.site(.jj, p.gpa, runHost, .{ p.gpa, dirOf(path), @as([]const []const u8, &.{ "file", "show", "-r", rev, "--", set }) }); +} + +fn dirOf(path: []const u8) []const u8 { + return std.Io.Dir.path.dirname(path) orelse "/"; +} + +/// The name of `path` as a fileset of that one file in its directory, +/// taken literally whatever it is called. +fn fileset(arena: std.mem.Allocator, path: []const u8) ![]const u8 { + var set: std.ArrayList(u8) = .empty; + try set.appendSlice(arena, "file:\""); + for (std.Io.Dir.path.basename(path)) |c| { + if (c == '"' or c == '\\') try set.append(arena, '\\'); + try set.append(arena, c); + } + try set.append(arena, '"'); + return set.items; +} + +/// jj with `args`, run in `dir`: what it printed, or its refusal. The +/// working copy is left alone (`--ignore-working-copy`): an editor's read +/// makes no operation, and `@` is the working copy as jj last saw it. +fn runHost(gpa: std.mem.Allocator, dir: []const u8, args: []const []const u8) Shown { + // The tape's io spawns nothing (its allocator fails, its environment is + // empty): one of its own, with this process's environment. + var threaded: std.Io.Threaded = .init_single_threaded; + threaded.allocator = gpa; + threaded.environ = .{ .process_environ = .{ .block = .{ .slice = std.mem.span(std.c.environ) } } }; + threaded.environ_initialized = false; + const io = threaded.io(); + var argv: std.ArrayList([]const u8) = .empty; + defer argv.deinit(gpa); + argv.appendSlice(gpa, &.{ "jj", "--ignore-working-copy", "--color=never", "--no-pager" }) catch return refusal(gpa, "out of memory"); + argv.appendSlice(gpa, args) catch return refusal(gpa, "out of memory"); + // As Stream's children: this thread's mask is the child's. + const none = std.posix.sigemptyset(); + var kept: std.posix.sigset_t = undefined; + std.posix.sigprocmask(std.posix.SIG.SETMASK, &none, &kept); + var child = std.process.spawn(io, .{ .argv = argv.items, .cwd = .{ .path = dir }, .stdin = .ignore, .stdout = .pipe, .stderr = .pipe }) catch |err| { + std.posix.sigprocmask(std.posix.SIG.SETMASK, &kept, null); + return refusal(gpa, if (err == error.FileNotFound) "no jj" else @errorName(err)); + }; + std.posix.sigprocmask(std.posix.SIG.SETMASK, &kept, null); + defer child.kill(io); + // One after the other, on an io with no thread to read both at once: + // jj says a refusal in a line and nothing on stdout. + var out: std.ArrayList(u8) = .empty; + defer out.deinit(gpa); + var err: std.ArrayList(u8) = .empty; + defer err.deinit(gpa); + for ([_]std.Io.File{ child.stdout.?, child.stderr.? }, [_]*std.ArrayList(u8){ &out, &err }, [_]usize{ bytes_max, 64 << 10 }) |from, to, cap| { + var chunk: [64 * 1024]u8 = undefined; + while (to.items.len <= cap) { + const n = from.readStreaming(io, &.{&chunk}) catch break; + if (n == 0) break; + to.appendSlice(gpa, chunk[0..n]) catch return refusal(gpa, "out of memory"); + } + } + const term = child.wait(io) catch |e| return refusal(gpa, @errorName(e)); + if (out.items.len > bytes_max) return refusal(gpa, "too much to show"); + if (term == .exited and term.exited == 0) return .{ .bytes = out.toOwnedSlice(gpa) catch return refusal(gpa, "out of memory") }; + var first = std.mem.trim(u8, err.items[0 .. std.mem.indexOfScalar(u8, err.items, '\n') orelse err.items.len], " \t\r"); + if (std.mem.startsWith(u8, first, "Error: ")) first = first["Error: ".len..]; + return refusal(gpa, if (first.len > 0) first else "jj failed"); +} + +fn refusal(gpa: std.mem.Allocator, why: []const u8) Shown { + return .{ .refused = gpa.dupe(u8, why) catch &.{} }; +} + +/// 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; + if (o.from != .revision) return null; + return .{ .path = f.path[0 .. f.path.len - o.arg().len - 1], .rev = o.arg() }; +} + +/// `path` (absolute) at `rev` in a pane: the one showing it focused, else +/// one made beside pane `near` (or, with `replace`, in its place: it goes), +/// wearing `near`'s layers; its cursor on line `line` (0: the first). Said +/// at `near` when jj refuses. The pane's id. +pub fn open(p: *Pardes, near: usize, path: []const u8, rev: []const u8, at: look.Spot, replace: bool) ?usize { + const name = std.fmt.allocPrint(p.scratch.allocator(), "{s}@{s}", .{ path, rev }) catch return null; + for (p.panes, 0..) |slot, i| if (slot) |shown| if (shown.file) |*f| if (of(f) != null and std.mem.eql(u8, f.path, name)) { + look.focusPaneLine(p, i, at, .center); + return i; + }; + if (rev.len > Output.max_arg) return refused(p, near, "a revision that long"); + const free = p.freeSlot() orelse { + p.reportError(.at(near), "At", error.NoPaneSlots); + return null; + }; + const bytes = switch (show(p, path, rev)) { + .refused => |why| { + defer p.gpa.free(why); + return refused(p, near, why); + }, + .bytes => |b| b, + }; + const pane = Output.open(p, free, std.Io.Dir.path.dirname(path) orelse "/", .revision, rev, bytes) catch |err| { + p.gpa.free(bytes); + p.reportError(.at(near), "At", err); + return null; + }; + const f = &pane.file.?; + const owned = p.gpa.dupe(u8, name) catch { + p.removePane(free, near) catch {}; + return null; + }; + p.gpa.free(f.path); + f.path = owned; + if (p.panes[near]) |from| pane.layers = from.layers; + layout.placeNew(p, near, near, free, .doc); + if (replace) p.removePane(near, free) catch |err| p.reportError(.at(free), "At", err); + layout.compute(p); + // Sized for its place before it is centred there. + p.sync(); + look.focusPaneLine(p, free, at, .center); + return free; +} + +fn refused(p: *Pardes, id: usize, why: []const u8) ?usize { + var line: pardes.Kind.Buf(512) = .{}; + p.reportFailure(id, line.print("At: {s}", .{why[0..@min(why.len, 480)]})); + return null; +} + +/// The `At` word (builtins.zig registers it): in a file's pane, that file +/// at revision `rev` beside it; in a revision's pane, the same file at +/// `rev` in its place, its cursor's line kept; bare there, the file. +pub fn word(c: pardes.builtins.Ctx) void { + const p = c.p; + const f = if (c.pane.file) |*file| file else return p.reportFailure(c.id, "At: only a file's pane takes it"); + const rev = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); + const at: look.Spot = .{ .line = @intCast(@max(0, c.pane.body.cur_row) + 1) }; + if (of(f)) |r| { + if (rev.len == 0) return look.lookAt(p, c.id, r.path); + const path = p.scratch.allocator().dupe(u8, r.path) catch return; + _ = open(p, c.id, path, rev, at, true); + return; + } + if (f.output != null or pardes.filesystem.localPath(f.path) == null) return p.reportFailure(c.id, "At: only a file's pane takes it"); + if (rev.len == 0) return p.reportFailure(c.id, "At: which revision?"); + _ = open(p, c.id, f.path, rev, at, false); +} + +/// A Look at `text` (a path relative to `dir`, then `@rev`) that names no +/// file: a file at a revision, if the path is a file. False when it is not +/// one, for the look to go on. +pub fn looked(p: *Pardes, id: usize, dir: []const u8, text: []const u8, at: look.Spot) bool { + const r = split(text) orelse return false; + const path = std.Io.Dir.path.resolvePosix(p.scratch.allocator(), &.{ dir, r.path }) catch return false; + if (pardes.filesystem.localPath(path) == null or pardes.exec.kindOf(p.tape, path) != .file) return false; + _ = open(p, id, path, r.rev, at, false); + return true; +} + +// ---- tests ---- + +const testing = std.testing; + +test "path@rev splits at its first @: a path before it, a revision after" { + const cases = [_]struct { []const u8, []const u8, []const u8 }{ + .{ "a.zig@main", "a.zig", "main" }, + .{ "core/File.zig@@-", "core/File.zig", "@-" }, + .{ "x.zig@main@origin", "x.zig", "main@origin" }, + }; + for (cases) |c| { + const got = split(c[0]).?; + try testing.expectEqualStrings(c[1], got.path); + try testing.expectEqualStrings(c[2], got.rev); + } + for ([_][]const u8{ "@p12", "a.zig@", "a.zig", "dir/@x" }) |text| try testing.expect(split(text) == null); +} + +/// A jj repository in a test's directory: `a.zig` committed as `one`, then +/// as `two`, and `three` in its working copy, never snapshotted. Null with +/// no jj to run. +const Repo = struct { + tmp: testing.TmpDir, + dir: []const u8, + file: []const u8, + + const one = "const one = 1;\nconst x = 2;\n"; + const two = "const two = 2;\nconst x = 2;\nconst y = 3;\n"; + const three = "const three = 3;\n"; + + fn init(gpa: std.mem.Allocator) !?Repo { + var tmp = testing.tmpDir(.{}); + errdefer tmp.cleanup(); + var buf: [std.Io.Dir.max_path_bytes]u8 = undefined; + const dir = try gpa.dupe(u8, buf[0..try tmp.dir.realPath(testing.io, &buf)]); + errdefer gpa.free(dir); + if (!try run(gpa, dir, &.{ "git", "init" })) return null; + for ([_][]const u8{ one, two }, [_][]const u8{ "one", "two" }) |text, message| { + try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.zig", .data = text }); + if (!try run(gpa, dir, &.{ "commit", "-m", message })) return null; + } + try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.zig", .data = three }); + return .{ .tmp = tmp, .dir = dir, .file = try std.fmt.allocPrint(gpa, "{s}/a.zig", .{dir}) }; + } + + fn run(gpa: std.mem.Allocator, dir: []const u8, args: []const []const u8) !bool { + var argv: std.ArrayList([]const u8) = .empty; + defer argv.deinit(gpa); + try argv.appendSlice(gpa, &.{ "jj", "--config=user.name=t", "--config=user.email=t@t", "--quiet" }); + try argv.appendSlice(gpa, args); + const r = std.process.run(gpa, testing.io, .{ .argv = argv.items, .cwd = .{ .path = dir } }) catch return false; + gpa.free(r.stdout); + gpa.free(r.stderr); + return r.term == .exited and r.term.exited == 0; + } + + fn deinit(r: *Repo, gpa: std.mem.Allocator) void { + gpa.free(r.file); + gpa.free(r.dir); + r.tmp.cleanup(); + } +}; + +fn told(p: *Pardes, id: usize) []const u8 { + const pane = p.panes[id].?; + return pane.msg[0..pane.msg_len]; +} + +test "At shows a file at a revision beside it, read-only, coloured as its file; a Look at path@rev:line goes to it; At in it turns it in place; 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 = 40 }); + defer p.deinit(); + var line: [4200]u8 = undefined; + p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{repo.file}) }); + const file = p.view().active; + try testing.expectEqualStrings(Repo.three, p.panes[file].?.file.?.content); + p.update(.{ .command = "At @-" }); + const shown = p.view().active; + try testing.expect(shown != file); + const pane = p.panes[shown].?; + try testing.expectEqualStrings(Repo.two, pane.file.?.content); + const name = try std.fmt.allocPrint(gpa, "{s}@@-", .{repo.file}); + defer gpa.free(name); + try testing.expectEqualStrings(name, try pardes.tagline.tagPrefix(p, pane)); + try testing.expectEqualStrings(repo.file, File.langPath(&pane.file.?)); + try testing.expect(pane.colorAlgo() == .source); + // Read-only: a key's edit and a whole-text edit (dd) change nothing, and a bare Save says so. + for ("iz") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + for ("dd") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + try testing.expectEqualStrings(Repo.two, pane.file.?.content); + p.update(.{ .command = "Save" }); + try testing.expect(std.mem.indexOf(u8, told(p, shown), "is a revision, read-only") != null); + // From the file's pane, a Look at the address with a line goes there. + p.view().active = file; + p.update(.{ .command = "Look a.zig@@-:3" }); + try testing.expectEqual(shown, p.view().active); + try testing.expectEqual(@as(i32, 2), pane.body.cur_row); + // Turned to another revision in its place: one pane, the older text. + p.update(.{ .command = "At @--" }); + const turned = p.view().active; + try testing.expect(p.panes[shown] == null); + try testing.expectEqualStrings(Repo.one, p.panes[turned].?.file.?.content); + var n: usize = 0; + for (p.panes) |slot| if (slot) |s| if (s.file) |*f| { + n += @intFromBool(of(f) != null); + }; + try testing.expectEqual(@as(usize, 1), n); + // jj's refusals, in its words. + p.update(.{ .command = "At nosuch" }); + try testing.expect(std.mem.indexOf(u8, told(p, turned), "At: Revision `nosuch` doesn't exist") != null); + p.view().active = file; + p.update(.{ .command = "At" }); + try testing.expect(std.mem.indexOf(u8, told(p, file), "At: which revision?") != null); + // Bare in a revision's pane: the file. + p.view().active = turned; + p.update(.{ .command = "At" }); + try testing.expectEqual(file, p.view().active); +} + +test "a client replays the open of a file at a revision and ends equal" { + const gpa = testing.allocator; + var repo = try Repo.init(gpa) orelse return error.SkipZigTest; + defer repo.deinit(gpa); + const R = pardes.replica; + const a = try R.Authority.init(gpa, .{ .cols = 80, .rows = 24 }, .{}, false); + defer a.deinit(); + const r = try R.Replica.init(gpa, 1, try a.unit(0, 0), false); + defer r.deinit(); + var line: [4200]u8 = undefined; + r.confirm(try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}@@-:2", .{repo.file}) })); + r.settle(); + try testing.expect(r.diverged == null); + const id = a.core.view().active; + try testing.expectEqualStrings(Repo.two, a.core.panes[id].?.file.?.content); + try testing.expectEqualStrings(Repo.two, r.core().panes[id].?.file.?.content); + try testing.expectEqual(pardes.tape.digestOf(a.core), pardes.tape.digestOf(r.core())); +} diff --git a/core/look.zig b/core/look.zig index 1d296775..53c26943 100644 --- a/core/look.zig +++ b/core/look.zig @@ -1489,6 +1489,8 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { // What is looked for is the place without its trailing `:`, `@p33:` // and `a.txt:` as much as `a.txt:2:`. const found = resolveLookTarget(p, id, trimmed, &realbuf); + // `path@rev`, `path@rev:12`: no file, a file at a revision (jj.zig). + if (found == .none and @import("jj.zig").looked(p, id, Pardes.paneDir(pane), pl.path, pl.at)) return; // A line past the end of an open pane is a miss (the target's line is // already clamped, so the one written is asked). if (found == .pane and found.pane.id < MAX_PANES) if (p.panes[found.pane.id]) |shown| { diff --git a/core/panes.zig b/core/panes.zig index e8f35de8..2f488482 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -558,7 +558,7 @@ pub const Pane = struct { if (std.mem.endsWith(u8, f.path, ".diff") or std.mem.endsWith(u8, f.path, ".patch") or f.pager_diff) return .diff; if (f.output != null) { // A +Preview is a file's text: coloured as the file. - if (f.output.?.from == .preview) return .source; + if (f.output.?.from == .preview or f.output.?.from == .revision) return .source; const tr = Output.fileTraits(f.output); if (tr.locations) return .locations; if (!tr.saves) return .none; diff --git a/core/root.zig b/core/root.zig index 5300ce93..145122e3 100644 --- a/core/root.zig +++ b/core/root.zig @@ -628,6 +628,7 @@ const machine_lines = [_]struct { []const u8, usize, []const u8 }{ .{ "exec.zig", 3, "kindOf's stat (tape.site(.kind), its io the tape's) and Shell's check (tape.site(.shell))" }, .{ "fs.zig", 38, "the file system behind the tape's sites (open, read, write, stat, mkdir, access; their io the tape's), the process's home (read once at the start, taped), the 9P transport" }, .{ "hunks.zig", 1, "a test helper's file read" }, + .{ "jj.zig", 8, "jj run under tape.site(.jj) on an io of its own (the tape's spawns nothing) with this process's environment, the signal mask cleared as Stream's children's: the session's, a replica replays its answer" }, .{ "look.zig", 6, "openLink's fork (the host's: a view's frontend opens a link) and a remote's error name" }, .{ "memory.zig", 7, "the memory regions themselves (mmap, madvise, their locks)" }, .{ "replica.zig", 73, "the client and session engines: sockets, threads, clocks, the blob cache, traces" }, diff --git a/core/tape.zig b/core/tape.zig index 09985d15..af934b38 100644 --- a/core/tape.zig +++ b/core/tape.zig @@ -112,6 +112,8 @@ pub const Site = enum(u16) { shell, /// The machine's fonts (Font <name>, Fonts): its disk too. fonts, + /// What jj says of a file (jj.zig): a file at a revision. + jj, // Read in place (`value`). clock, wake, @@ -161,6 +163,7 @@ pub const results = .{ ?@import("Store.zig").Record, ?@import("recent.zig").Entry, []const @import("Store.zig").Named, @import("Kind.zig").Outcome, pardes.Term.Prompt, + @import("jj.zig").Shown, }; /// What a host reports to the core as failed (`shell_failed`, `save_failed`, diff --git a/docs/typ/builtins-gui.json b/docs/typ/builtins-gui.json index 16a1aac8..a00b8bdf 100644 --- a/docs/typ/builtins-gui.json +++ b/docs/typ/builtins-gui.json @@ -2,6 +2,7 @@ {"name": "Addon", "leader": null, "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Addons, the libraries that bring kinds of pane: `Addon load <path>`, `Addon unload <name>`, `Addon reload <name>`; bare, the kinds here."}, {"name": "Adopt", "leader": null, "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Take in the shells of a session that died holding them, each as a terminal pane here: the pardes daemon kept their terminals open."}, {"name": "Ascii", "leader": "SPC t a", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "add the printable ASCII bitmaps to the matcher's glyph set"}, + {"name": "At", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Show a file as it was at revision `rev` (jj), read-only, beside its pane; in such a pane, that file at another revision in its place, or bare, the file."}, {"name": "Back", "leader": "SPC j o", "also": ["C-o"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Ctrl-o: one step back into the history."}, {"name": "Build", "leader": "SPC h b", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "This build: its version, commit, jj change and build time (a stamped build's: a release or the ~/.local install), the zig that built it, its optimize mode, target, platform, grammars, whether the addons are compiled in, and its dependencies, printed into an output buffer."}, {"name": "Callees", "leader": "SPC l C", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "List the functions the function under the cursor calls."}, diff --git a/docs/typ/builtins-tui.json b/docs/typ/builtins-tui.json index 39f762f2..1f0cd09d 100644 --- a/docs/typ/builtins-tui.json +++ b/docs/typ/builtins-tui.json @@ -2,6 +2,7 @@ {"name": "Addon", "leader": null, "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Addons, the libraries that bring kinds of pane: `Addon load <path>`, `Addon unload <name>`, `Addon reload <name>`; bare, the kinds here."}, {"name": "Adopt", "leader": null, "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Take in the shells of a session that died holding them, each as a terminal pane here: the pardes daemon kept their terminals open."}, {"name": "Ascii", "leader": "SPC t a", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "add the printable ASCII bitmaps to the matcher's glyph set"}, + {"name": "At", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Show a file as it was at revision `rev` (jj), read-only, beside its pane; in such a pane, that file at another revision in its place, or bare, the file."}, {"name": "Back", "leader": "SPC j o", "also": ["C-o"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Ctrl-o: one step back into the history."}, {"name": "Build", "leader": "SPC h b", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "This build: its version, commit, jj change and build time (a stamped build's: a release or the ~/.local install), the zig that built it, its optimize mode, target, platform, grammars, whether the addons are compiled in, and its dependencies, printed into an output buffer."}, {"name": "Callees", "leader": "SPC l C", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "List the functions the function under the cursor calls."}, diff --git a/docs/typ/guide.typ b/docs/typ/guide.typ index 127b22a9..7699ee52 100644 --- a/docs/typ/guide.typ +++ b/docs/typ/guide.typ @@ -283,6 +283,16 @@ or one above it. #word("Diff") on a `+Diff` shows the diff itself as text (a paged one's `+Pager` is closed once stacked), and on the text stacks it again. += A file at a revision <revision> + +`path@rev` names a file as jj has it at a revision: `a.zig@main`, +`a.zig@@-`, and `a.zig@main:120` at a line. A #word("Look") at one, +anywhere, opens it in a pane of that name, read-only and coloured as the +file. #word("At") with a revision does the same from a file's pane; in a +revision's pane it turns that pane to another revision, and bare it goes +back to the file. What jj refuses (a revision that is not there, a path +the revision has not) is said in jj's words. jj reads the working copy as +it last saw it (`@`): pardes never snapshots it. #word("Syntax") (#key("SPC t h")) turns a text's syntax colours off in this view, and on again. |
