| ... | ... | @@ -61,14 +61,6 @@ 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 | | |
| 72 | 64 | pub fn version(alloc: std.mem.Allocator) !string { |
| 73 | 65 | const result = try root.child_process.run(alloc, .cwd(), .ignore, .pipe, .pipe, 1024, &.{ "git", "--version" }); |
| 74 | 66 | defer alloc.free(result.stdout); |
| ... | ... | @@ -1058,25 +1050,24 @@ pub const Repository = struct { |
| 1058 | 1050 | return (try r.getBlob(.{ .id = id }, cache_behavior)).?; |
| 1059 | 1051 | } |
| 1060 | 1052 | |
| 1061 | | pub fn getCommit(r: *Repository, id: CommitId) !?struct { CommitId, CommitIdx } { |
| 1053 | pub fn getCommit(r: *Repository, id: CommitId) !?struct { CommitId, Commit } { |
| 1062 | 1054 | const t = tracer.trace(@src(), " {s}", .{id.id}); |
| 1063 | 1055 | defer t.end(); |
| 1064 | 1056 | |
| 1065 | | if (r.commits.getIndex(id.id)) |idx| { |
| 1066 | | return .{ id, @enumFromInt(idx) }; |
| 1057 | if (r.commits.getPtr(id.id)) |val| { |
| 1058 | return .{ id, val.* }; |
| 1067 | 1059 | } |
| 1068 | 1060 | if (try r.getObject(id.id, .cache)) |obj| { |
| 1069 | 1061 | if (obj.type == .commit) { |
| 1070 | 1062 | const commit = try parseCommit(r.gpa, obj.content); |
| 1071 | 1063 | try r.commits.put(r.gpa, id.id, commit); |
| 1072 | | const idx = r.commits.values().len - 1; |
| 1073 | | return .{ id, @enumFromInt(idx) }; |
| 1064 | return .{ id, commit }; |
| 1074 | 1065 | } |
| 1075 | 1066 | } |
| 1076 | 1067 | return null; |
| 1077 | 1068 | } |
| 1078 | 1069 | |
| 1079 | | pub fn getCommitA(r: *Repository, id: Id) !CommitIdx { |
| 1070 | pub fn getCommitA(r: *Repository, id: Id) !Commit { |
| 1080 | 1071 | return (try r.getCommit(.{ .id = id })).?.@"1"; |
| 1081 | 1072 | } |
| 1082 | 1073 | |
| ... | ... | @@ -1240,8 +1231,7 @@ pub const Repository = struct { |
| 1240 | 1231 | |
| 1241 | 1232 | // const start = time.milliTimestamp(); |
| 1242 | 1233 | |
| 1243 | | const base_idx = try r.getCommitA(base_oid.id); |
| 1244 | | const base = base_idx.reify(r); |
| 1234 | const base = try r.getCommitA(base_oid.id); |
| 1245 | 1235 | const base_tree_id = (try traverseTo(r, base.tree, dir_path)).?; |
| 1246 | 1236 | const base_tree = try r.getTreeA(base_tree_id.id, .cache); |
| 1247 | 1237 | const total = base_tree.children.len; |
| ... | ... | @@ -1257,15 +1247,13 @@ pub const Repository = struct { |
| 1257 | 1247 | var searched: usize = 1; |
| 1258 | 1248 | var commit_id_prev = base_oid; |
| 1259 | 1249 | var commit_id = base_oid; |
| 1260 | | var commit_idx = base_idx; |
| 1261 | 1250 | var commit = base; |
| 1262 | 1251 | var tree_id = base_tree_id; |
| 1263 | 1252 | while (true) { |
| 1264 | 1253 | if (commit.parents.len == 0) break; |
| 1265 | | commit_id, commit_idx = (try r.getCommit(commit.parents[0])).?; |
| 1254 | commit_id, commit = (try r.getCommit(commit.parents[0])).?; |
| 1266 | 1255 | searched += 1; |
| 1267 | 1256 | defer commit_id_prev = commit_id; |
| 1268 | | commit = commit_idx.reify(r); |
| 1269 | 1257 | const new_tree_id = try traverseTo(r, commit.tree, dir_path) orelse { |
| 1270 | 1258 | var i: usize = 0; |
| 1271 | 1259 | while (findFirstUnset(set, i)) |j| : (i += 1) { |
| ... | ... | @@ -1509,15 +1497,12 @@ pub const Repository = struct { |
| 1509 | 1497 | } |
| 1510 | 1498 | }; |
| 1511 | 1499 | if (commitid_from == null) { |
| 1512 | | const commitidx = try r.getCommitA(commitid_to.id); |
| 1513 | | const commit = commitidx.reify(r); |
| 1500 | const commit = try r.getCommitA(commitid_to.id); |
| 1514 | 1501 | try A.dir(r, writable, commit.tree.id, null, 0); |
| 1515 | 1502 | return; |
| 1516 | 1503 | } |
| 1517 | | const before_commitidx = try r.getCommitA(commitid_from.?.id); |
| 1518 | | const before_commit = before_commitidx.reify(r); |
| 1519 | | const after_commitidx = try r.getCommitA(commitid_to.id); |
| 1520 | | const after_commit = after_commitidx.reify(r); |
| 1504 | const before_commit = try r.getCommitA(commitid_from.?.id); |
| 1505 | const after_commit = try r.getCommitA(commitid_to.id); |
| 1521 | 1506 | try M.dir(r, writable, before_commit.tree.id, after_commit.tree.id, null); |
| 1522 | 1507 | } |
| 1523 | 1508 | |