| ... | @@ -951,6 +951,9 @@ pub const Repository = struct { | ... | @@ -951,6 +951,9 @@ pub const Repository = struct { |
| 951 | } | 951 | } |
| 952 | | 952 | |
| 953 | pub fn getObject(r: *Repository, arena: std.mem.Allocator, oid: Id) !?GitObject { | 953 | pub fn getObject(r: *Repository, arena: std.mem.Allocator, oid: Id) !?GitObject { |
| | 954 | const t = tracer.trace(@src(), " {s}", .{oid}); |
| | 955 | defer t.end(); |
| | 956 | |
| 954 | if (r.unpacked_objects.get(oid)) |obj| { | 957 | if (r.unpacked_objects.get(oid)) |obj| { |
| 955 | return obj; | 958 | return obj; |
| 956 | } | 959 | } |
| ... | @@ -1043,6 +1046,9 @@ pub const Repository = struct { | ... | @@ -1043,6 +1046,9 @@ pub const Repository = struct { |
| 1043 | } | 1046 | } |
| 1044 | | 1047 | |
| 1045 | fn getPackedObject(r: *Repository, maybe_oid: ?Id, pack_index: usize, pack_offset: usize) !GitObject { | 1048 | fn getPackedObject(r: *Repository, maybe_oid: ?Id, pack_index: usize, pack_offset: usize) !GitObject { |
| | 1049 | const t = tracer.trace(@src(), " {?s} {d} {d}", .{ maybe_oid, pack_index, pack_offset }); |
| | 1050 | defer t.end(); |
| | 1051 | |
| 1046 | const pack_content = r.pack_content.values()[pack_index]; | 1052 | const pack_content = r.pack_content.values()[pack_index]; |
| 1047 | if (!std.mem.eql(u8, pack_content[0..4], "PACK")) return error.InvalidGitPack; | 1053 | if (!std.mem.eql(u8, pack_content[0..4], "PACK")) return error.InvalidGitPack; |
| 1048 | const pack_version = std.mem.readInt(u32, pack_content[4..][0..4], .big); | 1054 | const pack_version = std.mem.readInt(u32, pack_content[4..][0..4], .big); |
| ... | @@ -1180,6 +1186,9 @@ pub const Repository = struct { | ... | @@ -1180,6 +1186,9 @@ pub const Repository = struct { |
| 1180 | }; | 1186 | }; |
| 1181 | | 1187 | |
| 1182 | pub fn getCommit(r: *Repository, arena: std.mem.Allocator, id: CommitId) !?struct { CommitId, Commit } { | 1188 | pub fn getCommit(r: *Repository, arena: std.mem.Allocator, id: CommitId) !?struct { CommitId, Commit } { |
| | 1189 | const t = tracer.trace(@src(), " {s}", .{id.id}); |
| | 1190 | defer t.end(); |
| | 1191 | |
| 1183 | if (r.commits.getPtr(id.id)) |val| { | 1192 | if (r.commits.getPtr(id.id)) |val| { |
| 1184 | return .{ id, val.* }; | 1193 | return .{ id, val.* }; |
| 1185 | } | 1194 | } |
| ... | @@ -1194,6 +1203,9 @@ pub const Repository = struct { | ... | @@ -1194,6 +1203,9 @@ pub const Repository = struct { |
| 1194 | } | 1203 | } |
| 1195 | | 1204 | |
| 1196 | pub fn getTree(r: *Repository, arena: std.mem.Allocator, id: TreeId) !?struct { TreeId, Tree } { | 1205 | pub fn getTree(r: *Repository, arena: std.mem.Allocator, id: TreeId) !?struct { TreeId, Tree } { |
| | 1206 | const t = tracer.trace(@src(), " {s}", .{id.id}); |
| | 1207 | defer t.end(); |
| | 1208 | |
| 1197 | if (r.trees.getPtr(id.id)) |val| { | 1209 | if (r.trees.getPtr(id.id)) |val| { |
| 1198 | return .{ id, val.* }; | 1210 | return .{ id, val.* }; |
| 1199 | } | 1211 | } |
| ... | @@ -1241,6 +1253,9 @@ pub const Repository = struct { | ... | @@ -1241,6 +1253,9 @@ pub const Repository = struct { |
| 1241 | } | 1253 | } |
| 1242 | | 1254 | |
| 1243 | pub fn getTag(r: *Repository, arena: std.mem.Allocator, id: TagId) !?struct { TagId, Tag } { | 1255 | pub fn getTag(r: *Repository, arena: std.mem.Allocator, id: TagId) !?struct { TagId, Tag } { |
| | 1256 | const t = tracer.trace(@src(), " {s}", .{id.id}); |
| | 1257 | defer t.end(); |
| | 1258 | |
| 1244 | if (r.tags.getPtr(id.id)) |val| { | 1259 | if (r.tags.getPtr(id.id)) |val| { |
| 1245 | return .{ id, val.* }; | 1260 | return .{ id, val.* }; |
| 1246 | } | 1261 | } |
| ... | @@ -1255,14 +1270,23 @@ pub const Repository = struct { | ... | @@ -1255,14 +1270,23 @@ pub const Repository = struct { |
| 1255 | } | 1270 | } |
| 1256 | | 1271 | |
| 1257 | pub fn getHeads(r: *Repository, arena: std.mem.Allocator) ![]Ref { | 1272 | pub fn getHeads(r: *Repository, arena: std.mem.Allocator) ![]Ref { |
| | 1273 | const t = tracer.trace(@src(), "", .{}); |
| | 1274 | defer t.end(); |
| | 1275 | |
| 1258 | return r.getRefs(arena, "heads"); | 1276 | return r.getRefs(arena, "heads"); |
| 1259 | } | 1277 | } |
| 1260 | | 1278 | |
| 1261 | pub fn getTags(r: *Repository, arena: std.mem.Allocator) ![]Ref { | 1279 | pub fn getTags(r: *Repository, arena: std.mem.Allocator) ![]Ref { |
| | 1280 | const t = tracer.trace(@src(), "", .{}); |
| | 1281 | defer t.end(); |
| | 1282 | |
| 1262 | return r.getRefs(arena, "tags"); | 1283 | return r.getRefs(arena, "tags"); |
| 1263 | } | 1284 | } |
| 1264 | | 1285 | |
| 1265 | pub fn getRefs(r: *Repository, arena: std.mem.Allocator, comptime kind: [:0]const u8) ![]Ref { | 1286 | pub fn getRefs(r: *Repository, arena: std.mem.Allocator, comptime kind: [:0]const u8) ![]Ref { |
| | 1287 | const t = tracer.trace(@src(), "", .{}); |
| | 1288 | defer t.end(); |
| | 1289 | |
| 1266 | var map: std.StringArrayHashMapUnmanaged(Id) = .empty; | 1290 | var map: std.StringArrayHashMapUnmanaged(Id) = .empty; |
| 1267 | try r.addPackedRefs(&map, arena, kind); | 1291 | try r.addPackedRefs(&map, arena, kind); |
| 1268 | try r.addDirRefs(&map, arena, kind); | 1292 | try r.addDirRefs(&map, arena, kind); |
| ... | @@ -1273,6 +1297,9 @@ pub const Repository = struct { | ... | @@ -1273,6 +1297,9 @@ pub const Repository = struct { |
| 1273 | } | 1297 | } |
| 1274 | | 1298 | |
| 1275 | fn addPackedRefs(r: *Repository, map: *std.StringArrayHashMapUnmanaged(Id), arena: std.mem.Allocator, comptime kind: [:0]const u8) !void { | 1299 | fn addPackedRefs(r: *Repository, map: *std.StringArrayHashMapUnmanaged(Id), arena: std.mem.Allocator, comptime kind: [:0]const u8) !void { |
| | 1300 | const t = tracer.trace(@src(), "", .{}); |
| | 1301 | defer t.end(); |
| | 1302 | |
| 1276 | var file = try r.gitdir.openFile("packed-refs", .{}); | 1303 | var file = try r.gitdir.openFile("packed-refs", .{}); |
| 1277 | defer file.close(); | 1304 | defer file.close(); |
| 1278 | const content = try file.mmap(); | 1305 | const content = try file.mmap(); |
| ... | @@ -1292,6 +1319,9 @@ pub const Repository = struct { | ... | @@ -1292,6 +1319,9 @@ pub const Repository = struct { |
| 1292 | } | 1319 | } |
| 1293 | | 1320 | |
| 1294 | fn addDirRefs(r: *Repository, map: *std.StringArrayHashMapUnmanaged(Id), arena: std.mem.Allocator, comptime kind: [:0]const u8) !void { | 1321 | fn addDirRefs(r: *Repository, map: *std.StringArrayHashMapUnmanaged(Id), arena: std.mem.Allocator, comptime kind: [:0]const u8) !void { |
| | 1322 | const t = tracer.trace(@src(), "", .{}); |
| | 1323 | defer t.end(); |
| | 1324 | |
| 1295 | var dir = try r.gitdir.openDir("refs/" ++ kind, .{}); | 1325 | var dir = try r.gitdir.openDir("refs/" ++ kind, .{}); |
| 1296 | defer dir.close(); | 1326 | defer dir.close(); |
| 1297 | var walker = try dir.walk(arena); | 1327 | var walker = try dir.walk(arena); |