| ... | ... | @@ -84,7 +84,9 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: nfs.Dir) !?CommitId { |
| 84 | 84 | const t = tracer.trace(@src(), "", .{}); |
| 85 | 85 | defer t.end(); |
| 86 | 86 | |
| 87 | | const h = std.mem.trimEnd(u8, try dir.readFileAlloc(alloc, "HEAD", 1024), "\n"); |
| 87 | const headfile = try dir.readFileAlloc(alloc, "HEAD", 1024); |
| 88 | defer alloc.free(headfile); |
| 89 | const h = std.mem.trimEnd(u8, headfile, "\n"); |
| 88 | 90 | |
| 89 | 91 | if (std.mem.startsWith(u8, h, "ref:")) { |
| 90 | 92 | blk: { |
| ... | ... | @@ -95,13 +97,15 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: nfs.Dir) !?CommitId { |
| 95 | 97 | error.ENOENT => break :blk, |
| 96 | 98 | else => |e| return e, |
| 97 | 99 | }; |
| 98 | | return ensureObjId(CommitId, std.mem.trimEnd(u8, reffile, "\n")); |
| 100 | defer alloc.free(reffile); |
| 101 | return ensureObjId(CommitId, try alloc.dupe(u8, std.mem.trimEnd(u8, reffile, "\n"))); |
| 99 | 102 | } |
| 100 | 103 | blk: { |
| 101 | 104 | const pckedrfs = dir.readFileAlloc(alloc, "packed-refs", 1024 * 1024 * 1024) catch |err| switch (err) { |
| 102 | 105 | error.ENOENT => break :blk, |
| 103 | 106 | else => |e| return e, |
| 104 | 107 | }; |
| 108 | defer alloc.free(pckedrfs); |
| 105 | 109 | var iter = std.mem.splitScalar(u8, pckedrfs, '\n'); |
| 106 | 110 | while (iter.next()) |line| { |
| 107 | 111 | if (std.mem.startsWith(u8, line, "#")) continue; |
| ... | ... | @@ -111,13 +115,13 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: nfs.Dir) !?CommitId { |
| 111 | 115 | const objid = jter.next().?; |
| 112 | 116 | const ref = jter.next().?; |
| 113 | 117 | std.debug.assert(jter.next() == null); |
| 114 | | if (std.mem.eql(u8, h[5..], ref)) return ensureObjId(CommitId, objid); |
| 118 | if (std.mem.eql(u8, h[5..], ref)) return ensureObjId(CommitId, try alloc.dupe(u8, objid)); |
| 115 | 119 | } |
| 116 | 120 | } |
| 117 | 121 | return null; |
| 118 | 122 | } |
| 119 | 123 | |
| 120 | | return ensureObjId(CommitId, h); |
| 124 | return ensureObjId(CommitId, try alloc.dupe(u8, h)); |
| 121 | 125 | } |
| 122 | 126 | |
| 123 | 127 | // 40 is length of sha1 hash |