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) {...@@ -61,6 +61,14 @@ 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
64pub fn version(alloc: std.mem.Allocator) !string {72pub fn version(alloc: std.mem.Allocator) !string {
65 const result = try std.process.Child.run(.{73 const result = try std.process.Child.run(.{
66 .allocator = alloc,74 .allocator = alloc,
...@@ -1144,24 +1152,25 @@ pub const Repository = struct {...@@ -1144,24 +1152,25 @@ pub const Repository = struct {
1144 return (try r.getBlob(arena, .{ .id = id })).?;1152 return (try r.getBlob(arena, .{ .id = id })).?;
1145 }1153 }
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 } {
1148 const t = tracer.trace(@src(), " {s}", .{id.id});1156 const t = tracer.trace(@src(), " {s}", .{id.id});
1149 defer t.end();1157 defer t.end();
11501158
1151 if (r.commits.getPtr(id.id)) |val| {1159 if (r.commits.getIndex(id.id)) |idx| {
1152 return .{ id, val.* };1160 return .{ id, @enumFromInt(idx) };
1153 }1161 }
1154 if (try r.getObject(arena, id.id)) |obj| {1162 if (try r.getObject(arena, id.id)) |obj| {
1155 if (obj.type == .commit) {1163 if (obj.type == .commit) {
1156 const commit = try parseCommit(arena, obj.content);1164 const commit = try parseCommit(arena, obj.content);
1157 try r.commits.put(r.gpa, id.id, commit);1165 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) };
1159 }1168 }
1160 }1169 }
1161 return null;1170 return null;
1162 }1171 }
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 {
1165 return (try r.getCommit(arena, .{ .id = id })).?.@"1";1174 return (try r.getCommit(arena, .{ .id = id })).?.@"1";
1166 }1175 }
11671176