authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-04-27 19:09:53 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-04-27 19:09:53 -07:00
log77c15ef110976fb3da134b8187877d8ab7fcd975
treeed2082849a4651cfb6cbe4f6a0eeabb976aba51c
parent42c40db3e8b670ea2fc8a6c30ec461eb697fb306

getHEAD: use empty file if packed-refs isnt there


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

git.zig+4-1
...@@ -14,7 +14,10 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !Id {...@@ -14,7 +14,10 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !Id {
1414
15 if (std.mem.startsWith(u8, h, "ref:")) {15 if (std.mem.startsWith(u8, h, "ref:")) {
16 const r = blk: {16 const r = blk: {
17 const pckedrfs = try dir.readFileAlloc(alloc, "packed-refs", 1024 * 1024);17 const pckedrfs = dir.readFileAlloc(alloc, "packed-refs", 1024 * 1024) catch |err| switch (err) {
18 error.FileNotFound => try std.fs.cwd().readFileAlloc(alloc, "/dev/null", 1024),
19 else => |e| return e,
20 };
18 var iter = std.mem.split(u8, pckedrfs, "\n");21 var iter = std.mem.split(u8, pckedrfs, "\n");
19 while (iter.next()) |line| {22 while (iter.next()) |line| {
20 if (std.mem.startsWith(u8, line, "#")) continue;23 if (std.mem.startsWith(u8, line, "#")) continue;