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;
1212pub const TreeId = struct {
1313 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
1518 pub fn eql(self: TreeId, other: TreeId) bool {
1619 return std.mem.eql(u8, self.id, other.id);
1720 }
......@@ -20,6 +23,8 @@ pub const TreeId = struct {
2023pub const CommitId = struct {
2124 id: Id,
2225
26 pub const zero: CommitId = .{ .id = "0000000000000000000000000000000000000000" };
27
2328 pub fn eql(self: CommitId, other: CommitId) bool {
2429 return std.mem.eql(u8, self.id, other.id);
2530 }
......@@ -28,6 +33,9 @@ pub const CommitId = struct {
2833pub const BlobId = struct {
2934 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
3139 pub fn eql(self: BlobId, other: BlobId) bool {
3240 return std.mem.eql(u8, self.id, other.id);
3341 }
......@@ -36,6 +44,8 @@ pub const BlobId = struct {
3644pub const TagId = struct {
3745 id: Id,
3846
47 pub const zero: BlobId = .{ .id = "0000000000000000000000000000000000000000" };
48
3949 pub fn eql(self: TagId, other: TagId) bool {
4050 return std.mem.eql(u8, self.id, other.id);
4151 }
......@@ -244,9 +254,7 @@ pub fn getTreeDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, p
244254 defer t.end();
245255
246256 if (parentid == null) {
247 // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1
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 });
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 });
250258 std.debug.assert(result.term == .exited and result.term.exited == 0);
251259 return std.mem.trim(u8, result.stdout, "\n");
252260 }