| ... | ... | @@ -30,9 +30,16 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !CommitId { |
| 30 | 30 | const h = std.mem.trimRight(u8, try dir.readFileAlloc(alloc, "HEAD", 1024), "\n"); |
| 31 | 31 | |
| 32 | 32 | if (std.mem.startsWith(u8, h, "ref:")) { |
| 33 | | const r = blk: { |
| 33 | blk: { |
| 34 | const reffile = dir.readFileAlloc(alloc, h[5..], 1024) catch |err| switch (err) { |
| 35 | error.FileNotFound => break :blk, |
| 36 | else => |e| return e, |
| 37 | }; |
| 38 | return ensureObjId(CommitId, std.mem.trimRight(u8, reffile, "\n")); |
| 39 | } |
| 40 | blk: { |
| 34 | 41 | const pckedrfs = dir.readFileAlloc(alloc, "packed-refs", 1024 * 1024 * 1024) catch |err| switch (err) { |
| 35 | | error.FileNotFound => try std.fs.cwd().readFileAlloc(alloc, "/dev/null", 1024), |
| 42 | error.FileNotFound => break :blk, |
| 36 | 43 | else => |e| return e, |
| 37 | 44 | }; |
| 38 | 45 | var iter = std.mem.split(u8, pckedrfs, "\n"); |
| ... | ... | @@ -44,11 +51,10 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !CommitId { |
| 44 | 51 | const objid = jter.next().?; |
| 45 | 52 | const ref = jter.next().?; |
| 46 | 53 | std.debug.assert(jter.next() == null); |
| 47 | | if (std.mem.eql(u8, h[5..], ref)) break :blk objid; |
| 54 | if (std.mem.eql(u8, h[5..], ref)) return ensureObjId(CommitId, objid); |
| 48 | 55 | } |
| 49 | | break :blk std.mem.trimRight(u8, try dir.readFileAlloc(alloc, h[5..], 1024), "\n"); |
| 50 | | }; |
| 51 | | return ensureObjId(CommitId, r); |
| 56 | } |
| 57 | unreachable; |
| 52 | 58 | } |
| 53 | 59 | |
| 54 | 60 | return ensureObjId(CommitId, h); |