authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-04-27 19:09:19 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-04-27 19:09:19 -07:00
log42c40db3e8b670ea2fc8a6c30ec461eb697fb306
tree9b42a6ce4299440c47cb8da4fbb487e885673a84
parent7906b39ca320577f1579bf63b5095a33fbaedc4f

getHEAD: checked packed-refs file for commits too


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

git.zig+15-1
......@@ -13,7 +13,21 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !Id {
1313 const h = std.mem.trimRight(u8, try dir.readFileAlloc(alloc, "HEAD", 1024), "\n");
1414
1515 if (std.mem.startsWith(u8, h, "ref:")) {
16 const r = std.mem.trimRight(u8, try dir.readFileAlloc(alloc, h[5..], 1024), "\n");
16 const r = blk: {
17 const pckedrfs = try dir.readFileAlloc(alloc, "packed-refs", 1024 * 1024);
18 var iter = std.mem.split(u8, pckedrfs, "\n");
19 while (iter.next()) |line| {
20 if (std.mem.startsWith(u8, line, "#")) continue;
21 if (std.mem.startsWith(u8, line, "^")) continue;
22 if (line.len == 0) continue;
23 var jter = std.mem.split(u8, line, " ");
24 const objid = jter.next().?;
25 const ref = jter.next().?;
26 std.debug.assert(jter.next() == null);
27 if (std.mem.eql(u8, h[5..], ref)) break :blk objid;
28 }
29 break :blk std.mem.trimRight(u8, try dir.readFileAlloc(alloc, h[5..], 1024), "\n");
30 };
1731 std.debug.assert(r.len == 40);
1832 return r[0..40];
1933 }