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) {
6161 }
6262};
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
7264pub fn version(alloc: std.mem.Allocator) !string {
7365 const result = try root.child_process.run(alloc, .cwd(), .ignore, .pipe, .pipe, 1024, &.{ "git", "--version" });
7466 defer alloc.free(result.stdout);
......@@ -1058,25 +1050,24 @@ pub const Repository = struct {
10581050 return (try r.getBlob(.{ .id = id }, cache_behavior)).?;
10591051 }
10601052
1061 pub fn getCommit(r: *Repository, id: CommitId) !?struct { CommitId, CommitIdx } {
1053 pub fn getCommit(r: *Repository, id: CommitId) !?struct { CommitId, Commit } {
10621054 const t = tracer.trace(@src(), " {s}", .{id.id});
10631055 defer t.end();
10641056
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.* };
10671059 }
10681060 if (try r.getObject(id.id, .cache)) |obj| {
10691061 if (obj.type == .commit) {
10701062 const commit = try parseCommit(r.gpa, obj.content);
10711063 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 };
10741065 }
10751066 }
10761067 return null;
10771068 }
10781069
1079 pub fn getCommitA(r: *Repository, id: Id) !CommitIdx {
1070 pub fn getCommitA(r: *Repository, id: Id) !Commit {
10801071 return (try r.getCommit(.{ .id = id })).?.@"1";
10811072 }
10821073
......@@ -1240,8 +1231,7 @@ pub const Repository = struct {
12401231
12411232 // const start = time.milliTimestamp();
12421233
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);
12451235 const base_tree_id = (try traverseTo(r, base.tree, dir_path)).?;
12461236 const base_tree = try r.getTreeA(base_tree_id.id, .cache);
12471237 const total = base_tree.children.len;
......@@ -1257,15 +1247,13 @@ pub const Repository = struct {
12571247 var searched: usize = 1;
12581248 var commit_id_prev = base_oid;
12591249 var commit_id = base_oid;
1260 var commit_idx = base_idx;
12611250 var commit = base;
12621251 var tree_id = base_tree_id;
12631252 while (true) {
12641253 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])).?;
12661255 searched += 1;
12671256 defer commit_id_prev = commit_id;
1268 commit = commit_idx.reify(r);
12691257 const new_tree_id = try traverseTo(r, commit.tree, dir_path) orelse {
12701258 var i: usize = 0;
12711259 while (findFirstUnset(set, i)) |j| : (i += 1) {
......@@ -1509,15 +1497,12 @@ pub const Repository = struct {
15091497 }
15101498 };
15111499 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);
15141501 try A.dir(r, writable, commit.tree.id, null, 0);
15151502 return;
15161503 }
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);
15211506 try M.dir(r, writable, before_commit.tree.id, after_commit.tree.id, null);
15221507 }
15231508