authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-11 00:40:32 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-11 00:40:32 -07:00
log72921adaa32363c30808cae95593d0e8a7013057
tree61e164c6c6fce4afe88f31fca050bc65b9be344c
parent79aa9f7b0d607c9c5acb6018ca19184ea52add80
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add getTreeDiffPath


1 files changed, 28 insertions(+), 0 deletions(-)

git.zig+28
...@@ -444,6 +444,34 @@ pub fn getTreeDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, p...@@ -444,6 +444,34 @@ pub fn getTreeDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, p
444 return std.mem.trim(u8, result.stdout, "\n");444 return std.mem.trim(u8, result.stdout, "\n");
445}445}
446446
447// TODO make this inspect .git manually
448// TODO make this return a Reader when we implement it ourselves
449pub fn getTreeDiffPath(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, parentid: ?CommitId, path: []const u8) !string {
450 const t = tracer.trace(@src(), "", .{});
451 defer t.end();
452
453 if (parentid == null) {
454 const result = try std.process.Child.run(.{
455 .allocator = alloc,
456 .cwd_dir = dir.to_std(),
457 // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1
458 // result of `printf | git hash-object -t tree --stdin`
459 .argv = &.{ "git", "diff-tree", "-p", "--raw", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id, "--", path },
460 .max_output_bytes = 1024 * 1024 * 1024,
461 });
462 std.debug.assert(result.term == .Exited and result.term.Exited == 0);
463 return std.mem.trim(u8, result.stdout, "\n");
464 }
465 const result = try std.process.Child.run(.{
466 .allocator = alloc,
467 .cwd_dir = dir.to_std(),
468 .argv = &.{ "git", "diff-tree", "-p", "--raw", parentid.?.id, commitid.id, "--", path },
469 .max_output_bytes = 1024 * 1024 * 1024,
470 });
471 std.debug.assert(result.term == .Exited and result.term.Exited == 0);
472 return std.mem.trim(u8, result.stdout, "\n");
473}
474
447pub fn parseTreeDiffMeta(input: string) !TreeDiffMeta {475pub fn parseTreeDiffMeta(input: string) !TreeDiffMeta {
448 const t = tracer.trace(@src(), "", .{});476 const t = tracer.trace(@src(), "", .{});
449 defer t.end();477 defer t.end();