authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-05-03 02:49:30 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-05-03 02:49:30 -07:00
log0af2b218d5efc4c7a60e25ffde8a048db4b45a77
tree8b5fdc1a2b32d39bbd0d39bcc8e7e497961eedf6
parent7063aab5c007b0e8b76f8b97ac1430b5da9c0684

getHEAD: return a CommitId instead of just Id now


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

git.zig+3-3
...@@ -11,7 +11,7 @@ pub const BlobId = struct { id: Id };...@@ -11,7 +11,7 @@ pub const BlobId = struct { id: Id };
11/// Returns the result of running `git rev-parse HEAD`11/// Returns the result of running `git rev-parse HEAD`
12/// dir must already be pointing at the .git folder12/// dir must already be pointing at the .git folder
13// TODO this doesnt handle when there are 0 commits13// TODO this doesnt handle when there are 0 commits
14pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !Id {14pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !CommitId {
15 const h = std.mem.trimRight(u8, try dir.readFileAlloc(alloc, "HEAD", 1024), "\n");15 const h = std.mem.trimRight(u8, try dir.readFileAlloc(alloc, "HEAD", 1024), "\n");
1616
17 if (std.mem.startsWith(u8, h, "ref:")) {17 if (std.mem.startsWith(u8, h, "ref:")) {
...@@ -34,12 +34,12 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !Id {...@@ -34,12 +34,12 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !Id {
34 break :blk std.mem.trimRight(u8, try dir.readFileAlloc(alloc, h[5..], 1024), "\n");34 break :blk std.mem.trimRight(u8, try dir.readFileAlloc(alloc, h[5..], 1024), "\n");
35 };35 };
36 std.debug.assert(r.len == 40);36 std.debug.assert(r.len == 40);
37 return r[0..40];37 return .{ .id = r[0..40] };
38 }38 }
3939
40 // content should be 40-char sha1 hash40 // content should be 40-char sha1 hash
41 std.debug.assert(h.len == 40);41 std.debug.assert(h.len == 40);
42 return h[0..40];42 return .{ .id = h[0..40] };
43}43}
4444
45// TODO make this inspect .git/objects45// TODO make this inspect .git/objects