authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-19 23:00:44 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-19 23:00:44 -07:00
log6c25a13134fd5965aa41ba2447e2ee090e77847a
treea7370445670fba3bd502e09eb3cc21faea39b055
parent6a9f3a0180bf134455a6e7a8fddc320ac2f71799
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

make getCommit return indexes now instead of big struct


1 files changed, 14 insertions(+), 5 deletions(-)

git.zig+14-5
......@@ -61,6 +61,14 @@ 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
6472pub fn version(alloc: std.mem.Allocator) !string {
6573 const result = try std.process.Child.run(.{
6674 .allocator = alloc,
......@@ -1144,24 +1152,25 @@ pub const Repository = struct {
11441152 return (try r.getBlob(arena, .{ .id = id })).?;
11451153 }
11461154
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 } {
11481156 const t = tracer.trace(@src(), " {s}", .{id.id});
11491157 defer t.end();
11501158
1151 if (r.commits.getPtr(id.id)) |val| {
1152 return .{ id, val.* };
1159 if (r.commits.getIndex(id.id)) |idx| {
1160 return .{ id, @enumFromInt(idx) };
11531161 }
11541162 if (try r.getObject(arena, id.id)) |obj| {
11551163 if (obj.type == .commit) {
11561164 const commit = try parseCommit(arena, obj.content);
11571165 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) };
11591168 }
11601169 }
11611170 return null;
11621171 }
11631172
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 {
11651174 return (try r.getCommit(arena, .{ .id = id })).?.@"1";
11661175 }
11671176