From 8610e2358d919445eb36f2eba18b4bb307b9202f Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Fri, 12 Jun 2026 21:31:08 -0700 Subject: [PATCH] add more getTreeDiff variations for specific endpoints --- git.zig | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/git.zig b/git.zig index cd130a48073f50da81f27769b928733304da90d9..594ae62b13a9b1bcc76ec8ff64fe569211a30633 100644 --- a/git.zig +++ b/git.zig @@ -261,6 +261,93 @@ pub fn getTreeDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, p return std.mem.trim(u8, result.stdout, "\n"); } +// TODO make this inspect .git manually +pub fn getTreeDiffOnlyRaw(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, parentid: ?CommitId) !string { + const t = tracer.trace(@src(), "", .{}); + defer t.end(); + + if (parentid == null) { + // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1 + // result of `printf | git hash-object -t tree --stdin` + const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .ignore, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "--raw", "-r", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id }); + std.debug.assert(result.term == .exited and result.term.exited == 0); + return std.mem.trim(u8, result.stdout, "\n"); + } + const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .ignore, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "--raw", "-r", parentid.?.id, commitid.id }); + std.debug.assert(result.term == .exited and result.term.exited == 0); + return std.mem.trim(u8, result.stdout, "\n"); +} + +// TODO make this inspect .git manually +pub fn getTreeDiffOnlyStat(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, parentid: ?CommitId) !string { + const t = tracer.trace(@src(), "", .{}); + defer t.end(); + + if (parentid == null) { + // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1 + // result of `printf | git hash-object -t tree --stdin` + const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .ignore, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "--stat", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id }); + std.debug.assert(result.term == .exited and result.term.exited == 0); + return std.mem.trim(u8, result.stdout, "\n"); + } + const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .ignore, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "--stat", parentid.?.id, commitid.id }); + std.debug.assert(result.term == .exited and result.term.exited == 0); + return std.mem.trim(u8, result.stdout, "\n"); +} + +// TODO make this inspect .git manually +pub fn getTreeDiffOnlySummary(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, parentid: ?CommitId) !string { + const t = tracer.trace(@src(), "", .{}); + defer t.end(); + + if (parentid == null) { + // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1 + // result of `printf | git hash-object -t tree --stdin` + const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .ignore, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "--summary", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id }); + std.debug.assert(result.term == .exited and result.term.exited == 0); + return std.mem.trim(u8, result.stdout, "\n"); + } + const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .ignore, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "--summary", parentid.?.id, commitid.id }); + std.debug.assert(result.term == .exited and result.term.exited == 0); + return std.mem.trim(u8, result.stdout, "\n"); +} + +// TODO make this inspect .git manually +pub fn getTreeDiffOnlyDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, parentid: ?CommitId) !string { + const t = tracer.trace(@src(), "", .{}); + defer t.end(); + + if (parentid == null) { + // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1 + // result of `printf | git hash-object -t tree --stdin` + const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .ignore, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "--patch", "--full-index", "--patience", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id }); + if (!(result.term == .exited and result.term.exited == 0)) std.log.err("{s}", .{result.stderr}); + std.debug.assert(result.term == .exited and result.term.exited == 0); + return std.mem.trim(u8, result.stdout, "\n"); + } + const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .ignore, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "--patch", "--full-index", "--patience", parentid.?.id, commitid.id }); + if (!(result.term == .exited and result.term.exited == 0)) std.log.err("{s}", .{result.stderr}); + std.debug.assert(result.term == .exited and result.term.exited == 0); + return std.mem.trim(u8, result.stdout, "\n"); +} + +// TODO make this inspect .git manually +pub fn getFormatPatch(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, parentid: ?CommitId) !string { + const t = tracer.trace(@src(), "", .{}); + defer t.end(); + + if (parentid == null) { + const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .pipe, 1024 * 1024 * 1024, &.{ "git", "format-patch", "--stdout", "--full-index", "--patience", "--root", commitid.id }); + if (!(result.term == .exited and result.term.exited == 0)) std.log.err("{s}", .{result.stderr}); + std.debug.assert(result.term == .exited and result.term.exited == 0); + return std.mem.trim(u8, result.stdout, "\n"); + } + const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .pipe, 1024 * 1024 * 1024, &.{ "git", "format-patch", "--stdout", "--full-index", "--patience", parentid.?.id ++ "..." ++ commitid.id }); + if (!(result.term == .exited and result.term.exited == 0)) std.log.err("{s}", .{result.stderr}); + std.debug.assert(result.term == .exited and result.term.exited == 0); + return std.mem.trim(u8, result.stdout, "\n"); +} + // TODO make this inspect .git manually // TODO make this return a Reader when we implement it ourselves pub fn getTreeDiffPath(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, parentid: ?CommitId, path: []const u8) !string { -- 2.54.0