| ... | @@ -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 | } |
| 40 | | 39 | |
| 41 | // content should be 40-char sha1 hash | 40 | return ensureObjId(CommitId, h); |
| 42 | std.debug.assert(h.len == 40); | 41 | } |
| 43 | return .{ .id = h[0..40] }; | 42 | |
| | 43 | fn ensureObjId(comptime T: type, input: string) T { |
| | 44 | std.debug.assert(input.len == 40); |
| | 45 | return .{ .id = input[0..40] }; |
| 44 | } | 46 | } |
| 45 | | 47 | |
| 46 | // TODO make this inspect .git/objects | 48 | // TODO make this inspect .git/objects |