| ... | @@ -30,9 +30,16 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !CommitId { | ... | @@ -30,9 +30,16 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !CommitId { |
| 30 | const h = std.mem.trimRight(u8, try dir.readFileAlloc(alloc, "HEAD", 1024), "\n"); | 30 | const h = std.mem.trimRight(u8, try dir.readFileAlloc(alloc, "HEAD", 1024), "\n"); |
| 31 | | 31 | |
| 32 | if (std.mem.startsWith(u8, h, "ref:")) { | 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 | const pckedrfs = dir.readFileAlloc(alloc, "packed-refs", 1024 * 1024 * 1024) catch |err| switch (err) { | 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 | else => |e| return e, | 43 | else => |e| return e, |
| 37 | }; | 44 | }; |
| 38 | var iter = std.mem.split(u8, pckedrfs, "\n"); | 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,11 +51,10 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !CommitId { |
| 44 | const objid = jter.next().?; | 51 | const objid = jter.next().?; |
| 45 | const ref = jter.next().?; | 52 | const ref = jter.next().?; |
| 46 | std.debug.assert(jter.next() == null); | 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"); | 56 | } |
| 50 | }; | 57 | unreachable; |
| 51 | return ensureObjId(CommitId, r); | | |
| 52 | } | 58 | } |
| 53 | | 59 | |
| 54 | return ensureObjId(CommitId, h); | 60 | return ensureObjId(CommitId, h); |