| ... | @@ -12,6 +12,9 @@ pub const Id = *const [40]u8; | ... | @@ -12,6 +12,9 @@ pub const Id = *const [40]u8; |
| 12 | pub const TreeId = struct { | 12 | pub const TreeId = struct { |
| 13 | id: Id, | 13 | id: Id, |
| 14 | | 14 | |
| | 15 | pub const zero: TreeId = .{ .id = "0000000000000000000000000000000000000000" }; |
| | 16 | pub const empty: TreeId = .{ .id = "4b825dc642cb6eb9a060e54bf8d69288fbee4904" }; // echo -n | git hash-object -t tree --stdin |
| | 17 | |
| 15 | pub fn eql(self: TreeId, other: TreeId) bool { | 18 | pub fn eql(self: TreeId, other: TreeId) bool { |
| 16 | return std.mem.eql(u8, self.id, other.id); | 19 | return std.mem.eql(u8, self.id, other.id); |
| 17 | } | 20 | } |
| ... | @@ -20,6 +23,8 @@ pub const TreeId = struct { | ... | @@ -20,6 +23,8 @@ pub const TreeId = struct { |
| 20 | pub const CommitId = struct { | 23 | pub const CommitId = struct { |
| 21 | id: Id, | 24 | id: Id, |
| 22 | | 25 | |
| | 26 | pub const zero: CommitId = .{ .id = "0000000000000000000000000000000000000000" }; |
| | 27 | |
| 23 | pub fn eql(self: CommitId, other: CommitId) bool { | 28 | pub fn eql(self: CommitId, other: CommitId) bool { |
| 24 | return std.mem.eql(u8, self.id, other.id); | 29 | return std.mem.eql(u8, self.id, other.id); |
| 25 | } | 30 | } |
| ... | @@ -28,6 +33,9 @@ pub const CommitId = struct { | ... | @@ -28,6 +33,9 @@ pub const CommitId = struct { |
| 28 | pub const BlobId = struct { | 33 | pub const BlobId = struct { |
| 29 | id: Id, | 34 | id: Id, |
| 30 | | 35 | |
| | 36 | pub const zero: BlobId = .{ .id = "0000000000000000000000000000000000000000" }; |
| | 37 | pub const empty: BlobId = .{ .id = "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391" }; // echo -n | git hash-object -t blob --stdin |
| | 38 | |
| 31 | pub fn eql(self: BlobId, other: BlobId) bool { | 39 | pub fn eql(self: BlobId, other: BlobId) bool { |
| 32 | return std.mem.eql(u8, self.id, other.id); | 40 | return std.mem.eql(u8, self.id, other.id); |
| 33 | } | 41 | } |
| ... | @@ -36,6 +44,8 @@ pub const BlobId = struct { | ... | @@ -36,6 +44,8 @@ pub const BlobId = struct { |
| 36 | pub const TagId = struct { | 44 | pub const TagId = struct { |
| 37 | id: Id, | 45 | id: Id, |
| 38 | | 46 | |
| | 47 | pub const zero: BlobId = .{ .id = "0000000000000000000000000000000000000000" }; |
| | 48 | |
| 39 | pub fn eql(self: TagId, other: TagId) bool { | 49 | pub fn eql(self: TagId, other: TagId) bool { |
| 40 | return std.mem.eql(u8, self.id, other.id); | 50 | return std.mem.eql(u8, self.id, other.id); |
| 41 | } | 51 | } |
| ... | @@ -244,9 +254,7 @@ pub fn getTreeDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, p | ... | @@ -244,9 +254,7 @@ pub fn getTreeDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, p |
| 244 | defer t.end(); | 254 | defer t.end(); |
| 245 | | 255 | |
| 246 | if (parentid == null) { | 256 | if (parentid == null) { |
| 247 | // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1 | 257 | const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .pipe, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "-p", "--raw", "--full-index", TreeId.empty.id, commitid.id }); |
| 248 | // result of `printf | git hash-object -t tree --stdin` | | |
| 249 | const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .pipe, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "-p", "--raw", "--full-index", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id }); | | |
| 250 | std.debug.assert(result.term == .exited and result.term.exited == 0); | 258 | std.debug.assert(result.term == .exited and result.term.exited == 0); |
| 251 | return std.mem.trim(u8, result.stdout, "\n"); | 259 | return std.mem.trim(u8, result.stdout, "\n"); |
| 252 | } | 260 | } |