From 0af2b218d5efc4c7a60e25ffde8a048db4b45a77 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Wed, 3 May 2023 02:49:30 -0700 Subject: [PATCH] getHEAD: return a CommitId instead of just Id now --- git.zig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git.zig b/git.zig index a90db90640b71610bb19b8cf85526e7e1f907660..38d16044095ed8d5bacc36642050f6a081071319 100644 --- a/git.zig +++ b/git.zig @@ -11,7 +11,7 @@ pub const BlobId = struct { id: Id }; /// Returns the result of running `git rev-parse HEAD` /// dir must already be pointing at the .git folder // TODO this doesnt handle when there are 0 commits -pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !Id { +pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !CommitId { const h = std.mem.trimRight(u8, try dir.readFileAlloc(alloc, "HEAD", 1024), "\n"); if (std.mem.startsWith(u8, h, "ref:")) { @@ -34,12 +34,12 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !Id { break :blk std.mem.trimRight(u8, try dir.readFileAlloc(alloc, h[5..], 1024), "\n"); }; std.debug.assert(r.len == 40); - return r[0..40]; + return .{ .id = r[0..40] }; } // content should be 40-char sha1 hash std.debug.assert(h.len == 40); - return h[0..40]; + return .{ .id = h[0..40] }; } // TODO make this inspect .git/objects -- 2.54.0