authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-14 20:42:28 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-14 20:42:28 -07:00
log853016b13438cbb980a253714c46500ce4696928
treef10486a89d6a006f6c146c3ce24f91eb406b84c6
parent562f0437847c3f643525d07f5a283cf17c415522
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

getTree: remove allocations parsing object id


1 files changed, 11 insertions(+), 9 deletions(-)

git.zig+11-9
......@@ -1111,8 +1111,7 @@ pub const Repository = struct {
11111111 i += name_end + 1;
11121112
11131113 const oid_raw = obj.content[i..][0..20].*;
1114 const oid_hex = (try arena.alloc(u8, 40))[0..40];
1115 oid_hex.* = extras.to_hex(oid_raw);
1114 const oid_hex = extras.to_hex(oid_raw);
11161115 i += 20;
11171116
11181117 var mode_buf: [6]u8 = @splat('0');
......@@ -1122,18 +1121,20 @@ pub const Repository = struct {
11221121 try children.append(r.gpa, .{
11231122 .mode = mode_real,
11241123 .name = name,
1125 .id = switch (mode_real.type) {
1126 .file => .{ .blob = .{ .id = oid_hex } },
1127 .directory => .{ .tree = .{ .id = oid_hex } },
1128 .submodule => .{ .commit = .{ .id = oid_hex } },
1129 .symlink => .{ .blob = .{ .id = oid_hex } },
1130 .none => unreachable,
1131 },
1124 .id_bytes = oid_hex,
1125 .id = undefined,
11321126 });
11331127 }
11341128
11351129 const children_slice = try children.toOwnedSlice(r.gpa);
11361130 errdefer r.gpa.free(children_slice);
1131 for (children_slice) |*item| item.id = switch (item.mode.type) {
1132 .file => .{ .blob = .{ .id = &item.id_bytes } },
1133 .directory => .{ .tree = .{ .id = &item.id_bytes } },
1134 .submodule => .{ .commit = .{ .id = &item.id_bytes } },
1135 .symlink => .{ .blob = .{ .id = &item.id_bytes } },
1136 .none => unreachable,
1137 };
11371138 const tree: Tree = .{ .children = children_slice };
11381139 try r.trees.put(r.gpa, id.id, tree);
11391140 return .{ id, tree };
......@@ -1419,6 +1420,7 @@ pub const Tree = struct {
14191420
14201421 pub const Object = struct {
14211422 mode: Mode,
1423 id_bytes: [40]u8,
14221424 id: AnyId,
14231425 name: [:0]const u8,
14241426