| ... | @@ -61,6 +61,14 @@ pub const AnyId = union(RefType) { | ... | @@ -61,6 +61,14 @@ pub const AnyId = union(RefType) { |
| 61 | } | 61 | } |
| 62 | }; | 62 | }; |
| 63 | | 63 | |
| | 64 | pub const CommitIdx = enum(u32) { |
| | 65 | _, |
| | 66 | |
| | 67 | pub fn reify(self: CommitIdx, r: *const Repository) *const Commit { |
| | 68 | return &r.commits.values()[@intFromEnum(self)]; |
| | 69 | } |
| | 70 | }; |
| | 71 | |
| 64 | pub fn version(alloc: std.mem.Allocator) !string { | 72 | pub fn version(alloc: std.mem.Allocator) !string { |
| 65 | const result = try std.process.Child.run(.{ | 73 | const result = try std.process.Child.run(.{ |
| 66 | .allocator = alloc, | 74 | .allocator = alloc, |
| ... | @@ -1144,24 +1152,25 @@ pub const Repository = struct { | ... | @@ -1144,24 +1152,25 @@ pub const Repository = struct { |
| 1144 | return (try r.getBlob(arena, .{ .id = id })).?; | 1152 | return (try r.getBlob(arena, .{ .id = id })).?; |
| 1145 | } | 1153 | } |
| 1146 | | 1154 | |
| 1147 | pub fn getCommit(r: *Repository, arena: std.mem.Allocator, id: CommitId) !?struct { CommitId, Commit } { | 1155 | pub fn getCommit(r: *Repository, arena: std.mem.Allocator, id: CommitId) !?struct { CommitId, CommitIdx } { |
| 1148 | const t = tracer.trace(@src(), " {s}", .{id.id}); | 1156 | const t = tracer.trace(@src(), " {s}", .{id.id}); |
| 1149 | defer t.end(); | 1157 | defer t.end(); |
| 1150 | | 1158 | |
| 1151 | if (r.commits.getPtr(id.id)) |val| { | 1159 | if (r.commits.getIndex(id.id)) |idx| { |
| 1152 | return .{ id, val.* }; | 1160 | return .{ id, @enumFromInt(idx) }; |
| 1153 | } | 1161 | } |
| 1154 | if (try r.getObject(arena, id.id)) |obj| { | 1162 | if (try r.getObject(arena, id.id)) |obj| { |
| 1155 | if (obj.type == .commit) { | 1163 | if (obj.type == .commit) { |
| 1156 | const commit = try parseCommit(arena, obj.content); | 1164 | const commit = try parseCommit(arena, obj.content); |
| 1157 | try r.commits.put(r.gpa, id.id, commit); | 1165 | try r.commits.put(r.gpa, id.id, commit); |
| 1158 | return .{ id, commit }; | 1166 | const idx = r.commits.values().len - 1; |
| | 1167 | return .{ id, @enumFromInt(idx) }; |
| 1159 | } | 1168 | } |
| 1160 | } | 1169 | } |
| 1161 | return null; | 1170 | return null; |
| 1162 | } | 1171 | } |
| 1163 | | 1172 | |
| 1164 | pub fn getCommitA(r: *Repository, arena: std.mem.Allocator, id: Id) !Commit { | 1173 | pub fn getCommitA(r: *Repository, arena: std.mem.Allocator, id: Id) !CommitIdx { |
| 1165 | return (try r.getCommit(arena, .{ .id = id })).?.@"1"; | 1174 | return (try r.getCommit(arena, .{ .id = id })).?.@"1"; |
| 1166 | } | 1175 | } |
| 1167 | | 1176 | |