authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-07-30 14:43:31-07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-07-30 14:43:31-07:00
log496cd1145d8e39867c5c567236a4263134213d5c
tree520c3fc1667c9453ce34eb5fc64a982614fdaa27
parentda1afe5cb1aedd3131710e5aefc866f0e14ca05b
signature Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add some Id decl literals


1 files changed, 11 insertions(+), 3 deletions(-)

git.zig+11-3
...@@ -12,6 +12,9 @@ pub const Id = *const [40]u8;...@@ -12,6 +12,9 @@ pub const Id = *const [40]u8;
12pub const TreeId = struct {12pub const TreeId = struct {
13 id: Id,13 id: Id,
1414
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 {
20pub const CommitId = struct {23pub const CommitId = struct {
21 id: Id,24 id: Id,
2225
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 {
28pub const BlobId = struct {33pub const BlobId = struct {
29 id: Id,34 id: Id,
3035
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 {
36pub const TagId = struct {44pub const TagId = struct {
37 id: Id,45 id: Id,
3846
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();
245255
246 if (parentid == null) {256 if (parentid == null) {
247 // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1257 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 }