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 {...@@ -1111,8 +1111,7 @@ pub const Repository = struct {
1111 i += name_end + 1;1111 i += name_end + 1;
11121112
1113 const oid_raw = obj.content[i..][0..20].*;1113 const oid_raw = obj.content[i..][0..20].*;
1114 const oid_hex = (try arena.alloc(u8, 40))[0..40];1114 const oid_hex = extras.to_hex(oid_raw);
1115 oid_hex.* = extras.to_hex(oid_raw);
1116 i += 20;1115 i += 20;
11171116
1118 var mode_buf: [6]u8 = @splat('0');1117 var mode_buf: [6]u8 = @splat('0');
...@@ -1122,18 +1121,20 @@ pub const Repository = struct {...@@ -1122,18 +1121,20 @@ pub const Repository = struct {
1122 try children.append(r.gpa, .{1121 try children.append(r.gpa, .{
1123 .mode = mode_real,1122 .mode = mode_real,
1124 .name = name,1123 .name = name,
1125 .id = switch (mode_real.type) {1124 .id_bytes = oid_hex,
1126 .file => .{ .blob = .{ .id = oid_hex } },1125 .id = undefined,
1127 .directory => .{ .tree = .{ .id = oid_hex } },
1128 .submodule => .{ .commit = .{ .id = oid_hex } },
1129 .symlink => .{ .blob = .{ .id = oid_hex } },
1130 .none => unreachable,
1131 },
1132 });1126 });
1133 }1127 }
11341128
1135 const children_slice = try children.toOwnedSlice(r.gpa);1129 const children_slice = try children.toOwnedSlice(r.gpa);
1136 errdefer r.gpa.free(children_slice);1130 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 };
1137 const tree: Tree = .{ .children = children_slice };1138 const tree: Tree = .{ .children = children_slice };
1138 try r.trees.put(r.gpa, id.id, tree);1139 try r.trees.put(r.gpa, id.id, tree);
1139 return .{ id, tree };1140 return .{ id, tree };
...@@ -1419,6 +1420,7 @@ pub const Tree = struct {...@@ -1419,6 +1420,7 @@ pub const Tree = struct {
14191420
1420 pub const Object = struct {1421 pub const Object = struct {
1421 mode: Mode,1422 mode: Mode,
1423 id_bytes: [40]u8,
1422 id: AnyId,1424 id: AnyId,
1423 name: [:0]const u8,1425 name: [:0]const u8,
14241426