diff options
| -rw-r--r-- | src/Output.zig | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/src/Output.zig b/src/Output.zig index d4be640c..5bad7ab7 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -414,17 +414,19 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: [] result_rows = formatted.rows; anchor = formatted.anchor; } - _ = try fillRows(p, id, dir, from, arg, result_content, result_rows, anchor); + _ = try fillRows(p, id, dir, from, null, arg, result_content, result_rows, anchor); } /// Rows already laid out (`content`, `rows` its metadata, both taken /// when it succeeds, the caller's still when it fails) into the pane they -/// belong in: the one a run of `from` with `arg` in `dir` showed last, +/// belong in: the one named `name` (null: its origin's own name, as `open` +/// gives it) that a run of `from` with `arg` in `dir` showed last, /// refilled, else a new one placed by pane `id`. Its id. -pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []const u8, result_content: []u8, result_rows: []locations.Row, anchor: ?usize) !usize { +pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, name: ?[]const u8, arg: []const u8, result_content: []u8, result_rows: []locations.Row, anchor: ?usize) !usize { const pane = p.panes[id] orelse return error.MissingPane; if (arg.len > max_arg) return error.ArgumentTooLong; const by_arg = std.meta.activeTag(from) != .query; + const own = name orelse if (from == .kind) arg else traits(from).name; for (p.panes, 0..) |slot, i| { const rp = slot orelse continue; const rf = if (rp.file) |*f| f else continue; @@ -440,8 +442,7 @@ 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; + if (!std.mem.eql(u8, std.Io.Dir.path.basename(rf.path), std.Io.Dir.path.basename(own))) continue; o.from = from; p.fs.refilled = rp.serial; try setArg(o, arg); @@ -470,7 +471,13 @@ pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []con return i; } const free = p.freeSlot() orelse return error.NoPaneSlots; + const path = if (name) |named| try std.fmt.allocPrint(p.gpa, "{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), named }) else null; + errdefer if (path) |owned| p.gpa.free(owned); const np = try open(p, free, dir, from, arg, result_content); + if (path) |owned| { + p.gpa.free(np.file.?.path); + np.file.?.path = owned; + } np.file.?.location_rows = result_rows; layout.placeNew(p, id, id, free, .doc); p.view().active = id; @@ -486,8 +493,10 @@ pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []con /// diff viewer shows it (hunks.zig), in a +Diff where its files are found /// (hunks.sourceRoot), placed by pane `id`, refilled when it is there. Its /// arg names the diff (its base name, or its whole path when the +Diff -/// stands elsewhere), for Diff to go back to it. The +Diff's id; -/// NoHunks when there is none in it. +/// stands elsewhere), for Diff to go back to it; a commit's (`git show`, a +/// mailed patch) is named for it too, `+Diff-<12 hex>`, so each commit +/// keeps a +Diff of its own. The +Diff's id; NoHunks when there is none in +/// it. pub fn openDiff(p: *Pardes, id: usize, path: []const u8, content: []const u8) !usize { const dir = std.Io.Dir.path.dirname(path) orelse p.sessionDir(); // Each file read is a site of the step's tape (fs.zig): a replica @@ -525,18 +534,12 @@ 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; - 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)] }) + var name_buf: [config.diff_buffer.len + 13]u8 = undefined; + const name = if (diff.commitHash(content)) |hash| + std.fmt.bufPrint(&name_buf, "{s}-{s}", .{ config.diff_buffer, hash[0..@min(hash.len, 12)] }) catch unreachable 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; + return fillRows(p, id, root, .{ .cmd = .Diff }, name, arg, result.content, result.rows, null); } /// Diff on a +Diff: the diff it stacks, as text. A pane holding it |
