summaryrefslogtreecommitdiff
path: root/core/hunks.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/hunks.zig')
-rw-r--r--core/hunks.zig49
1 files changed, 48 insertions, 1 deletions
diff --git a/core/hunks.zig b/core/hunks.zig
index bee06cc2..e109b788 100644
--- a/core/hunks.zig
+++ b/core/hunks.zig
@@ -701,7 +701,9 @@ fn trimmedWidth(ctx: *const Ctx, section: []const u8) usize {
/// (a .diff, a .patch: relative to the pane's directory), its hunks
/// stacked so; with a revision (7 to 40 lowercase hex digits, a letter and
/// a digit among them), `git show` of it, paged into a +Pager that stacks
-/// its hunks (ctl.fillPager), run in the pane's git work tree. A plumbing
+/// its hunks (ctl.fillPager), run in the pane's git work tree; with a jj
+/// change (`Diff wrnnmymq [path[:line]]`: jj.diffChange), its patch, header
+/// and all, the cursor at that place in it. A plumbing
/// rule's Diff that cannot (no hunk, no work tree) declines, saying
/// nothing (Pardes.plumb_declined), and the look looks itself.
pub fn word(c: pardes.builtins.Ctx) void {
@@ -731,6 +733,9 @@ pub fn word(c: pardes.builtins.Ctx) void {
if (p.panes[dst]) |cp| cp.command_pages = true;
return;
}
+ // A jj change (its letters k to z), with a place in its patch to stand at.
+ if (@import("jj.zig").diffChange(p, c.id, arg)) return;
+ if (@import("jj.zig").isChangeId(arg[0 .. std.mem.indexOfAny(u8, arg, " \t") orelse arg.len])) return declined(p, c.id, "Diff: no such change");
var buf: [4096]u8 = undefined;
const path = if (arg[0] == '/') arg else std.fmt.bufPrint(&buf, "{s}/{s}", .{ std.mem.trimEnd(u8, Pardes.paneDir(c.pane), "/"), arg }) catch arg;
const bytes = pardes.filesystem.read(p, path) catch |err| {
@@ -1072,6 +1077,48 @@ test "a mailed patch keeps its headers, message and diffstat above its hunks" {
try testing.expectEqualStrings("From 0123 Mon Sep 17 00:00:00 2001\nSubject: [PATCH] change x\n\nWhy it changed.\n---\n x.txt | 2 +-\n\nx.txt:1\n-a\n+b\n", result.content);
}
+test "a log of several changes keeps each one's header and whole message above its own hunks: git log -p, jj show's header" {
+ var t: TestCtx = undefined;
+ t.init();
+ defer t.deinit();
+ const log =
+ \\commit 1111111111111111111111111111111111111111
+ \\Author: A <a@a>
+ \\Date: Mon Nov 23 10:00:00 2026 -0300
+ \\
+ \\ second
+ \\
+ \\ its body, a line
+ \\
+ \\diff --git a/x.txt b/x.txt
+ \\index 1..2 100644
+ \\--- a/x.txt
+ \\+++ b/x.txt
+ \\@@ -1 +1 @@
+ \\-b
+ \\+c
+ \\
+ \\commit 2222222222222222222222222222222222222222
+ \\Author: A <a@a>
+ \\Date: Mon Nov 23 09:00:00 2026 -0300
+ \\
+ \\ first
+ \\
+ \\diff --git a/x.txt b/x.txt
+ \\index 0..1 100644
+ \\--- a/x.txt
+ \\+++ b/x.txt
+ \\@@ -1 +1 @@
+ \\-a
+ \\+b
+ \\
+ ;
+ const result = try paneResult(testing.allocator, try format(&t.ctx, "/pardes-surely-missing-dir", log));
+ defer testing.allocator.free(result.content);
+ defer locations.freeRows(testing.allocator, result.rows);
+ try testing.expectEqualStrings("commit 1111111111111111111111111111111111111111\nAuthor: A <a@a>\nDate: Mon Nov 23 10:00:00 2026 -0300\n\n second\n\n its body, a line\n\nx.txt:1\n-b\n+c\n\ncommit 2222222222222222222222222222222222222222\nAuthor: A <a@a>\nDate: Mon Nov 23 09:00:00 2026 -0300\n\n first\n\nx.txt:1\n-a\n+b\n", result.content);
+}
+
test "a .patch looked at opens its +Diff, and Diff goes to the text and back" {
const p = try Pardes.init(testing.allocator, .{ .tty_only = true });
defer p.deinit();