authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-05-04 13:55:57 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-05-04 13:55:57 -07:00
log8b1baaec1950e8f8da2035a843190b7d8fad3df7
tree1f5f81b9af0469810921bfd7cafb81e98fcbc09c
parentec216906732801283caa4c7a1ba97068b6c26a06

add ensureObjId


1 files changed, 7 insertions(+), 5 deletions(-)

git.zig+7-5
...@@ -34,13 +34,15 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !CommitId {...@@ -34,13 +34,15 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !CommitId {
34 }34 }
35 break :blk std.mem.trimRight(u8, try dir.readFileAlloc(alloc, h[5..], 1024), "\n");35 break :blk std.mem.trimRight(u8, try dir.readFileAlloc(alloc, h[5..], 1024), "\n");
36 };36 };
37 std.debug.assert(r.len == 40);37 return ensureObjId(CommitId, r);
38 return .{ .id = r[0..40] };
39 }38 }
4039
41 // content should be 40-char sha1 hash40 return ensureObjId(CommitId, h);
42 std.debug.assert(h.len == 40);41}
43 return .{ .id = h[0..40] };42
43fn ensureObjId(comptime T: type, input: string) T {
44 std.debug.assert(input.len == 40);
45 return .{ .id = input[0..40] };
44}46}
4547
46// TODO make this inspect .git/objects48// TODO make this inspect .git/objects