authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-24 15:16:38 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-24 15:16:38 -07:00
log565f5b3eeb02a756be48690138ad8e83c06ff186
treed1dfed43e2c4c923b9fd8c8744f6ae535550cb29
parentc0da28486e36527301620e49c0c85a1aec11dcdd
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

back out of the CommitIdx abstraction, makes using CacheBehavior impossible


1 files changed, 10 insertions(+), 25 deletions(-)

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