summaryrefslogtreecommitdiff
path: root/src/Output.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Output.zig')
-rw-r--r--src/Output.zig16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/Output.zig b/src/Output.zig
index bb75e29f..0c6fdfc2 100644
--- a/src/Output.zig
+++ b/src/Output.zig
@@ -15,6 +15,7 @@ const look = @import("look.zig");
const locations = @import("locations.zig");
const layout = @import("layout.zig");
const hunks = @import("hunks.zig");
+const diff = @import("diff.zig");
const Pane = panes.Pane;
const File = panes.File;
@@ -439,6 +440,8 @@ pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []con
if (!shared and !std.meta.eql(o.from, from)) continue;
if (!shared and by_arg and !std.mem.eql(u8, o.arg(), arg)) continue;
if (!std.mem.eql(u8, std.Io.Dir.path.dirname(rf.path) orelse "", dir)) continue;
+ if (std.meta.eql(from, Origin{ .cmd = .Diff }) and
+ !std.mem.eql(u8, diff.commitHash(rf.content) orelse "", diff.commitHash(result_content) orelse "")) continue;
o.from = from;
p.fs.refilled = rp.serial;
try setArg(o, arg);
@@ -497,7 +500,18 @@ pub fn openDiff(p: *Pardes, id: usize, path: []const u8, content: []const u8) !u
for (result.rows) |row| has_hunk = has_hunk or row.kind == .match;
if (!has_hunk) return error.NoHunks;
const arg = if (std.mem.eql(u8, root, dir) or path.len > max_arg) std.Io.Dir.path.basename(path) else path;
- return fillRows(p, id, root, .{ .cmd = .Diff }, arg, result.content, result.rows, null);
+ const title = if (diff.commitHash(content)) |hash|
+ try std.fmt.allocPrint(p.gpa, "{s}/{s}-{s}", .{ std.mem.trimEnd(u8, root, "/"), config.diff_buffer, hash[0..@min(hash.len, 12)] })
+ else
+ null;
+ errdefer if (title) |name| p.gpa.free(name);
+ const hid = try fillRows(p, id, root, .{ .cmd = .Diff }, arg, result.content, result.rows, null);
+ if (title) |name| {
+ const f = &p.panes[hid].?.file.?;
+ p.gpa.free(f.path);
+ f.path = name;
+ }
+ return hid;
}
/// Diff on a +Diff: the diff it stacks, as text. A pane holding it