| ... | @@ -126,14 +126,14 @@ pub fn ensureObjId(comptime T: type, input: string) T { | ... | @@ -126,14 +126,14 @@ pub fn ensureObjId(comptime T: type, input: string) T { |
| 126 | // TODO make this return a Reader when we implement it ourselves | 126 | // TODO make this return a Reader when we implement it ourselves |
| 127 | // https://git-scm.com/book/en/v2/Git-Internals-Git-Objects | 127 | // https://git-scm.com/book/en/v2/Git-Internals-Git-Objects |
| 128 | // https://git-scm.com/book/en/v2/Git-Internals-Packfiles | 128 | // https://git-scm.com/book/en/v2/Git-Internals-Packfiles |
| 129 | pub fn getObjectContent(alloc: std.mem.Allocator, dir: nfs.Dir, obj: Id) !string { | 129 | pub fn getObjectContent(alloc: std.mem.Allocator, dir: nfs.Dir, oid: Id) !string { |
| 130 | const t = tracer.trace(@src(), " {s}", .{obj}); | 130 | const t = tracer.trace(@src(), " {s}", .{oid}); |
| 131 | defer t.end(); | 131 | defer t.end(); |
| 132 | | 132 | |
| 133 | const result = try std.process.Child.run(.{ | 133 | const result = try std.process.Child.run(.{ |
| 134 | .allocator = alloc, | 134 | .allocator = alloc, |
| 135 | .cwd_dir = dir.to_std(), | 135 | .cwd_dir = dir.to_std(), |
| 136 | .argv = &.{ "git", "cat-file", "-p", obj }, | 136 | .argv = &.{ "git", "cat-file", "-p", oid }, |
| 137 | .max_output_bytes = 1024 * 1024 * 1024, | 137 | .max_output_bytes = 1024 * 1024 * 1024, |
| 138 | }); | 138 | }); |
| 139 | extras.assertLog(result.term == .Exited and result.term.Exited == 0, "{s}", .{result.stderr}); | 139 | extras.assertLog(result.term == .Exited and result.term.Exited == 0, "{s}", .{result.stderr}); |
| ... | @@ -143,14 +143,14 @@ pub fn getObjectContent(alloc: std.mem.Allocator, dir: nfs.Dir, obj: Id) !string | ... | @@ -143,14 +143,14 @@ pub fn getObjectContent(alloc: std.mem.Allocator, dir: nfs.Dir, obj: Id) !string |
| 143 | // TODO make this inspect .git/objects manually | 143 | // TODO make this inspect .git/objects manually |
| 144 | // https://git-scm.com/book/en/v2/Git-Internals-Git-Objects | 144 | // https://git-scm.com/book/en/v2/Git-Internals-Git-Objects |
| 145 | // https://git-scm.com/book/en/v2/Git-Internals-Packfiles | 145 | // https://git-scm.com/book/en/v2/Git-Internals-Packfiles |
| 146 | pub fn getObjectSize(alloc: std.mem.Allocator, dir: nfs.Dir, obj: Id) !u64 { | 146 | pub fn getObjectSize(alloc: std.mem.Allocator, dir: nfs.Dir, oid: Id) !u64 { |
| 147 | const t = tracer.trace(@src(), " {s}", .{obj}); | 147 | const t = tracer.trace(@src(), " {s}", .{oid}); |
| 148 | defer t.end(); | 148 | defer t.end(); |
| 149 | | 149 | |
| 150 | const result = try std.process.Child.run(.{ | 150 | const result = try std.process.Child.run(.{ |
| 151 | .allocator = alloc, | 151 | .allocator = alloc, |
| 152 | .cwd_dir = dir.to_std(), | 152 | .cwd_dir = dir.to_std(), |
| 153 | .argv = &.{ "git", "cat-file", "-s", obj }, | 153 | .argv = &.{ "git", "cat-file", "-s", oid }, |
| 154 | }); | 154 | }); |
| 155 | extras.assertLog(result.term == .Exited and result.term.Exited == 0, "{s}", .{result.stderr}); | 155 | extras.assertLog(result.term == .Exited and result.term.Exited == 0, "{s}", .{result.stderr}); |
| 156 | return try extras.parseDigits(u64, std.mem.trimRight(u8, result.stdout, "\n"), 10); | 156 | return try extras.parseDigits(u64, std.mem.trimRight(u8, result.stdout, "\n"), 10); |
| ... | @@ -159,14 +159,14 @@ pub fn getObjectSize(alloc: std.mem.Allocator, dir: nfs.Dir, obj: Id) !u64 { | ... | @@ -159,14 +159,14 @@ pub fn getObjectSize(alloc: std.mem.Allocator, dir: nfs.Dir, obj: Id) !u64 { |
| 159 | // TODO make this inspect .git manually | 159 | // TODO make this inspect .git manually |
| 160 | // https://git-scm.com/book/en/v2/Git-Internals-Git-Objects | 160 | // https://git-scm.com/book/en/v2/Git-Internals-Git-Objects |
| 161 | // https://git-scm.com/book/en/v2/Git-Internals-Packfiles | 161 | // https://git-scm.com/book/en/v2/Git-Internals-Packfiles |
| 162 | pub fn isType(alloc: std.mem.Allocator, dir: nfs.Dir, maybeobj: Id, typ: RefType) !bool { | 162 | pub fn isType(alloc: std.mem.Allocator, dir: nfs.Dir, maybeoid: Id, typ: RefType) !bool { |
| 163 | const t = tracer.trace(@src(), " {s} = {s} ?", .{ maybeobj, @tagName(typ) }); | 163 | const t = tracer.trace(@src(), " {s} = {s} ?", .{ maybeoid, @tagName(typ) }); |
| 164 | defer t.end(); | 164 | defer t.end(); |
| 165 | | 165 | |
| 166 | const result = try std.process.Child.run(.{ | 166 | const result = try std.process.Child.run(.{ |
| 167 | .allocator = alloc, | 167 | .allocator = alloc, |
| 168 | .cwd_dir = dir.to_std(), | 168 | .cwd_dir = dir.to_std(), |
| 169 | .argv = &.{ "git", "cat-file", "-t", maybeobj }, | 169 | .argv = &.{ "git", "cat-file", "-t", maybeoid }, |
| 170 | }); | 170 | }); |
| 171 | std.debug.assert(result.term == .Exited and result.term.Exited == 0); | 171 | std.debug.assert(result.term == .Exited and result.term.Exited == 0); |
| 172 | const output = std.mem.trimRight(u8, result.stdout, "\n"); | 172 | const output = std.mem.trimRight(u8, result.stdout, "\n"); |
| ... | @@ -176,14 +176,14 @@ pub fn isType(alloc: std.mem.Allocator, dir: nfs.Dir, maybeobj: Id, typ: RefType | ... | @@ -176,14 +176,14 @@ pub fn isType(alloc: std.mem.Allocator, dir: nfs.Dir, maybeobj: Id, typ: RefType |
| 176 | // TODO make this inspect .git manually | 176 | // TODO make this inspect .git manually |
| 177 | // https://git-scm.com/book/en/v2/Git-Internals-Git-Objects | 177 | // https://git-scm.com/book/en/v2/Git-Internals-Git-Objects |
| 178 | // https://git-scm.com/book/en/v2/Git-Internals-Packfiles | 178 | // https://git-scm.com/book/en/v2/Git-Internals-Packfiles |
| 179 | pub fn getType(alloc: std.mem.Allocator, dir: nfs.Dir, obj: Id) !RefType { | 179 | pub fn getType(alloc: std.mem.Allocator, dir: nfs.Dir, oid: Id) !RefType { |
| 180 | const t = tracer.trace(@src(), " {s}", .{obj}); | 180 | const t = tracer.trace(@src(), " {s}", .{oid}); |
| 181 | defer t.end(); | 181 | defer t.end(); |
| 182 | | 182 | |
| 183 | const result = try std.process.Child.run(.{ | 183 | const result = try std.process.Child.run(.{ |
| 184 | .allocator = alloc, | 184 | .allocator = alloc, |
| 185 | .cwd_dir = dir.to_std(), | 185 | .cwd_dir = dir.to_std(), |
| 186 | .argv = &.{ "git", "cat-file", "-t", obj }, | 186 | .argv = &.{ "git", "cat-file", "-t", oid }, |
| 187 | }); | 187 | }); |
| 188 | std.debug.assert(result.term == .Exited and result.term.Exited == 0); | 188 | std.debug.assert(result.term == .Exited and result.term.Exited == 0); |
| 189 | const output = std.mem.trimRight(u8, result.stdout, "\n"); | 189 | const output = std.mem.trimRight(u8, result.stdout, "\n"); |
| ... | @@ -1010,14 +1010,14 @@ pub const Repository = struct { | ... | @@ -1010,14 +1010,14 @@ pub const Repository = struct { |
| 1010 | r.tags.deinit(r.gpa); | 1010 | r.tags.deinit(r.gpa); |
| 1011 | } | 1011 | } |
| 1012 | | 1012 | |
| 1013 | fn getObject(r: *Repository, obj: Id, arena: std.mem.Allocator) !?RawObject { | 1013 | fn getObject(r: *Repository, oid: Id, arena: std.mem.Allocator) !?RawObject { |
| 1014 | if (r.raw_object_contents.get(obj)) |data| { | 1014 | if (r.raw_object_contents.get(oid)) |data| { |
| 1015 | return data; | 1015 | return data; |
| 1016 | } | 1016 | } |
| 1017 | if (obj.len == 40) blk: { //sha1 object | 1017 | if (oid.len == 40) blk: { //sha1 object |
| 1018 | var sub_path: [49:0]u8 = "objects/00/00000000000000000000000000000000000000".*; | 1018 | var sub_path: [49:0]u8 = "objects/00/00000000000000000000000000000000000000".*; |
| 1019 | @memcpy(sub_path[8..][0..2], obj[0..2]); | 1019 | @memcpy(sub_path[8..][0..2], oid[0..2]); |
| 1020 | @memcpy(sub_path[11..], obj[2..]); | 1020 | @memcpy(sub_path[11..], oid[2..]); |
| 1021 | const objfile = r.gitdir.openFile(&sub_path, .{}) catch |err| switch (err) { | 1021 | const objfile = r.gitdir.openFile(&sub_path, .{}) catch |err| switch (err) { |
| 1022 | error.ENOENT => break :blk, | 1022 | error.ENOENT => break :blk, |
| 1023 | else => |e| return e, | 1023 | else => |e| return e, |
| ... | @@ -1036,7 +1036,7 @@ pub const Repository = struct { | ... | @@ -1036,7 +1036,7 @@ pub const Repository = struct { |
| 1036 | list.replaceRangeAssumeCapacity(0, header.len + 1, ""); | 1036 | list.replaceRangeAssumeCapacity(0, header.len + 1, ""); |
| 1037 | const content = try list.toOwnedSlice(); | 1037 | const content = try list.toOwnedSlice(); |
| 1038 | std.debug.assert(content.len == content_len); | 1038 | std.debug.assert(content.len == content_len); |
| 1039 | try r.raw_object_contents.put(r.gpa, obj, .{ _type, content }); | 1039 | try r.raw_object_contents.put(r.gpa, oid, .{ _type, content }); |
| 1040 | return .{ _type, content }; | 1040 | return .{ _type, content }; |
| 1041 | } | 1041 | } |
| 1042 | | 1042 | |
| ... | @@ -1072,7 +1072,7 @@ pub const Repository = struct { | ... | @@ -1072,7 +1072,7 @@ pub const Repository = struct { |
| 1072 | for (0..object_count) |i| { | 1072 | for (0..object_count) |i| { |
| 1073 | const object_id = &extras.to_hex(name_bytes[i * 20 ..][0..20].*); | 1073 | const object_id = &extras.to_hex(name_bytes[i * 20 ..][0..20].*); |
| 1074 | const pack_offset = std.mem.readInt(u32, offset_bytes[i * 4 ..][0..4], .big); | 1074 | const pack_offset = std.mem.readInt(u32, offset_bytes[i * 4 ..][0..4], .big); |
| 1075 | if (std.mem.eql(u8, object_id, obj)) { | 1075 | if (std.mem.eql(u8, object_id, oid)) { |
| 1076 | std.log.debug("found {s} in {s} at offset {d}", .{ obj, idx_path, pack_offset }); | 1076 | std.log.debug("found {s} in {s} at offset {d}", .{ obj, idx_path, pack_offset }); |
| 1077 | const pack_index = r.pack_content.getIndex(idx_path) orelse clk: { | 1077 | const pack_index = r.pack_content.getIndex(idx_path) orelse clk: { |
| 1078 | var pack_path: [128]u8 = @splat(0); | 1078 | var pack_path: [128]u8 = @splat(0); |
| ... | @@ -1098,10 +1098,10 @@ pub const Repository = struct { | ... | @@ -1098,10 +1098,10 @@ pub const Repository = struct { |
| 1098 | // parse .pack | 1098 | // parse .pack |
| 1099 | std.log.warn("pack_index={d} pack_offset={d}", .{ pack_index, pack_offset }); | 1099 | std.log.warn("pack_index={d} pack_offset={d}", .{ pack_index, pack_offset }); |
| 1100 | | 1100 | |
| 1101 | return try r.getPackedObject(obj, pack_index, pack_offset); | 1101 | return try r.getPackedObject(oid, pack_index, pack_offset); |
| 1102 | } | 1102 | } |
| 1103 | | 1103 | |
| 1104 | fn getPackedObject(r: *Repository, maybe_obj: ?Id, pack_index: usize, pack_offset: usize) !RawObject { | 1104 | fn getPackedObject(r: *Repository, maybe_oid: ?Id, pack_index: usize, pack_offset: usize) !RawObject { |
| 1105 | const pack_content = r.pack_content.values()[pack_index]; | 1105 | const pack_content = r.pack_content.values()[pack_index]; |
| 1106 | if (!std.mem.eql(u8, pack_content[0..4], "PACK")) return error.InvalidGitPack; | 1106 | if (!std.mem.eql(u8, pack_content[0..4], "PACK")) return error.InvalidGitPack; |
| 1107 | const pack_version = std.mem.readInt(u32, pack_content[4..][0..4], .big); | 1107 | const pack_version = std.mem.readInt(u32, pack_content[4..][0..4], .big); |
| ... | @@ -1140,7 +1140,7 @@ pub const Repository = struct { | ... | @@ -1140,7 +1140,7 @@ pub const Repository = struct { |
| 1140 | try std.compress.flate.inflate.decompress(.zlib, bufr.anyReadable(), list.writer()); | 1140 | try std.compress.flate.inflate.decompress(.zlib, bufr.anyReadable(), list.writer()); |
| 1141 | const _type = std.meta.stringToEnum(RefType, @tagName(ty)).?; | 1141 | const _type = std.meta.stringToEnum(RefType, @tagName(ty)).?; |
| 1142 | const content = try list.toOwnedSlice(); | 1142 | const content = try list.toOwnedSlice(); |
| 1143 | if (maybe_obj) |obj| try r.raw_object_contents.put(r.gpa, obj, .{ _type, content }); | 1143 | if (maybe_oid) |oid| try r.raw_object_contents.put(r.gpa, oid, .{ _type, content }); |
| 1144 | return .{ _type, content }; | 1144 | return .{ _type, content }; |
| 1145 | }, | 1145 | }, |
| 1146 | .ofs_delta => { | 1146 | .ofs_delta => { |
| ... | @@ -1161,8 +1161,8 @@ pub const Repository = struct { | ... | @@ -1161,8 +1161,8 @@ pub const Repository = struct { |
| 1161 | } | 1161 | } |
| 1162 | } | 1162 | } |
| 1163 | | 1163 | |
| 1164 | pub fn getGitObject(r: *Repository, arena: std.mem.Allocator, obj: Id) !?GitObject { | 1164 | pub fn getGitObject(r: *Repository, arena: std.mem.Allocator, oid: Id) !?GitObject { |
| 1165 | if (try r.getObject(obj, arena)) |data| { | 1165 | if (try r.getObject(oid, arena)) |data| { |
| 1166 | const _type, const content = data; | 1166 | const _type, const content = data; |
| 1167 | return .{ .type = _type, .content = content }; | 1167 | return .{ .type = _type, .content = content }; |
| 1168 | } | 1168 | } |