authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-05-06 16:12:32 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-05-06 16:12:32 -07:00
log0c9973661168106f5ed53a1994da6dfe1e394841
tree9c3a2a8667faecf005f82f3a703148d704201ff8
parentec926ff81334a7a6def0bc99b88301febd2ede7c

getTreeDiff: allow parentid to be optional


1 files changed, 13 insertions(+), 2 deletions(-)

git.zig+13-2
...@@ -299,11 +299,22 @@ pub const Tree = struct {...@@ -299,11 +299,22 @@ pub const Tree = struct {
299299
300// TODO make this inspect .git manually300// TODO make this inspect .git manually
301// TODO make this return a Reader when we implement it ourselves301// TODO make this return a Reader when we implement it ourselves
302pub fn getTreeDiff(alloc: std.mem.Allocator, dir: std.fs.Dir, commitid: CommitId, parentid: CommitId) !string {302pub fn getTreeDiff(alloc: std.mem.Allocator, dir: std.fs.Dir, commitid: CommitId, parentid: ?CommitId) !string {
303 if (parentid == null) {
304 const result = try std.ChildProcess.exec(.{
305 .allocator = alloc,
306 .cwd_dir = dir,
307 // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1
308 // result of `printf | git hash-object -t tree --stdin`
309 .argv = &.{ "git", "diff-tree", "-p", "--raw", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id },
310 .max_output_bytes = 1024 * 1024 * 1024,
311 });
312 return std.mem.trim(u8, result.stdout, "\n");
313 }
303 const result = try std.ChildProcess.exec(.{314 const result = try std.ChildProcess.exec(.{
304 .allocator = alloc,315 .allocator = alloc,
305 .cwd_dir = dir,316 .cwd_dir = dir,
306 .argv = &.{ "git", "diff-tree", "-p", "--raw", parentid.id, commitid.id },317 .argv = &.{ "git", "diff-tree", "-p", "--raw", parentid.?.id, commitid.id },
307 .max_output_bytes = 1024 * 1024 * 1024,318 .max_output_bytes = 1024 * 1024 * 1024,
308 });319 });
309 return std.mem.trim(u8, result.stdout, "\n");320 return std.mem.trim(u8, result.stdout, "\n");