| ... | ... | @@ -13,7 +13,21 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !Id { |
| 13 | 13 | const h = std.mem.trimRight(u8, try dir.readFileAlloc(alloc, "HEAD", 1024), "\n"); |
| 14 | 14 | |
| 15 | 15 | 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 | }; |
| 17 | 31 | std.debug.assert(r.len == 40); |
| 18 | 32 | return r[0..40]; |
| 19 | 33 | } |