| ... | ... | @@ -444,6 +444,34 @@ pub fn getTreeDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, p |
| 444 | 444 | return std.mem.trim(u8, result.stdout, "\n"); |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | // TODO make this inspect .git manually |
| 448 | // TODO make this return a Reader when we implement it ourselves |
| 449 | pub 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 | |
| 447 | 475 | pub fn parseTreeDiffMeta(input: string) !TreeDiffMeta { |
| 448 | 476 | const t = tracer.trace(@src(), "", .{}); |
| 449 | 477 | defer t.end(); |