| ... | ... | @@ -1314,11 +1314,12 @@ pub const Repository = struct { |
| 1314 | 1314 | } |
| 1315 | 1315 | } |
| 1316 | 1316 | |
| 1317 | | pub fn getTreeCommits(r: *Repository, arena: std.mem.Allocator, base_oid: CommitId, dir_path: []const u8) ![]const CommitId { |
| 1317 | pub fn getTreeCommits(r: *Repository, arena: std.mem.Allocator, base_oid: CommitId, dir_path: []const u8, timeout_ms: u64) ![]const CommitId { |
| 1318 | 1318 | const t = tracer.trace(@src(), "", .{}); |
| 1319 | 1319 | defer t.end(); |
| 1320 | 1320 | |
| 1321 | | // const start = time.milliTimestamp(); |
| 1321 | const start = time.milliTimestamp(); |
| 1322 | var timeout_ended = false; |
| 1322 | 1323 | |
| 1323 | 1324 | const base = try r.getCommitA(base_oid.id, .no_cache); |
| 1324 | 1325 | const base_tree_id, const base_tree_id_parent = try traverseTo(r, base.tree, dir_path); |
| ... | ... | @@ -1329,7 +1330,7 @@ pub const Repository = struct { |
| 1329 | 1330 | var found: usize = 0; |
| 1330 | 1331 | var result: std.StringArrayHashMapUnmanaged(CommitId) = .empty; |
| 1331 | 1332 | defer result.deinit(r.gpa); |
| 1332 | | for (base_tree.children) |obj| try result.put(r.gpa, obj.name, undefined); |
| 1333 | for (base_tree.children) |obj| try result.put(r.gpa, obj.name, .zero); |
| 1333 | 1334 | |
| 1334 | 1335 | var set: std.bit_set.DynamicBitSetUnmanaged = try .initEmpty(r.gpa, total); |
| 1335 | 1336 | defer set.deinit(r.gpa); |
| ... | ... | @@ -1350,6 +1351,10 @@ pub const Repository = struct { |
| 1350 | 1351 | }) { |
| 1351 | 1352 | searched += 1; |
| 1352 | 1353 | if (commit.parents.len == 0) break; |
| 1354 | if (timeout_ms > 0 and time.milliTimestamp() - start > timeout_ms) { |
| 1355 | timeout_ended = true; |
| 1356 | break; |
| 1357 | } |
| 1353 | 1358 | const new_tree_id, const new_tree_id_parent = try traverseTo(r, commit.tree, dir_path); |
| 1354 | 1359 | defer if (new_tree_id_parent) |p| p.destroy(r); |
| 1355 | 1360 | if (new_tree_id == null) { |
| ... | ... | @@ -1393,11 +1398,11 @@ pub const Repository = struct { |
| 1393 | 1398 | break; |
| 1394 | 1399 | } |
| 1395 | 1400 | } |
| 1396 | | for (0..total, result.values()) |i, *v| { |
| 1401 | if (!timeout_ended) for (0..total, result.values()) |i, *v| { |
| 1397 | 1402 | if (!set.isSet(i)) { |
| 1398 | 1403 | v.* = commit_id; |
| 1399 | 1404 | } |
| 1400 | | } |
| 1405 | }; |
| 1401 | 1406 | |
| 1402 | 1407 | // const end = time.milliTimestamp(); |
| 1403 | 1408 | // std.log.debug("found {d} in {d}ms", .{ total, end - start }); |