authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-12 00:04:19 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-12 00:04:19 -07:00
log273ab35efde5b9ba792f6a32e17efaa23cca5b74
tree7ec3db394f3b7eb48cb2d9f572bd51d93e3e4d7e
parentce95745420ddca38d636ea152df4698c1cc55c64
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

getGitObject is redundant now


1 files changed, 17 insertions(+), 25 deletions(-)

git.zig+17-25
......@@ -917,20 +917,18 @@ pub const BlameIterator = struct {
917917pub const Repository = struct {
918918 gitdir: nfs.Dir,
919919 gpa: std.mem.Allocator,
920 raw_object_contents: std.StringArrayHashMapUnmanaged(RawObject),
920 unpacked_objects: std.StringArrayHashMapUnmanaged(GitObject),
921921 idx_content: std.StringArrayHashMapUnmanaged([]const u8),
922922 pack_content: std.StringArrayHashMapUnmanaged([]const u8),
923923 commits: std.StringArrayHashMapUnmanaged(Commit),
924924 trees: std.StringArrayHashMapUnmanaged(Tree),
925925 tags: std.StringArrayHashMapUnmanaged(Tag),
926926
927 const RawObject = struct { RefType, []const u8 };
928
929927 pub fn init(gitdir: nfs.Dir, gpa: std.mem.Allocator) Repository {
930928 return .{
931929 .gitdir = gitdir,
932930 .gpa = gpa,
933 .raw_object_contents = .empty,
931 .unpacked_objects = .empty,
934932 .idx_content = .empty,
935933 .pack_content = .empty,
936934 .commits = .empty,
......@@ -940,8 +938,8 @@ pub const Repository = struct {
940938 }
941939
942940 pub fn deinit(r: *Repository) void {
943 for (r.raw_object_contents.values()) |v| r.gpa.free(v[1]);
944 r.raw_object_contents.deinit(r.gpa);
941 for (r.unpacked_objects.values()) |v| r.gpa.free(v.content);
942 r.unpacked_objects.deinit(r.gpa);
945943 for (r.idx_content.values()) |v| nfs.munmap(v);
946944 r.idx_content.deinit(r.gpa);
947945 for (r.pack_content.values()) |v| nfs.munmap(v);
......@@ -952,9 +950,9 @@ pub const Repository = struct {
952950 r.tags.deinit(r.gpa);
953951 }
954952
955 fn getObject(r: *Repository, oid: Id, arena: std.mem.Allocator) !?RawObject {
956 if (r.raw_object_contents.get(oid)) |data| {
957 return data;
953 pub fn getObject(r: *Repository, arena: std.mem.Allocator, oid: Id) !?GitObject {
954 if (r.unpacked_objects.get(oid)) |obj| {
955 return obj;
958956 }
959957 if (oid.len == 40) blk: { //sha1 object
960958 var sub_path: [49:0]u8 = "objects/00/00000000000000000000000000000000000000".*;
......@@ -978,8 +976,9 @@ pub const Repository = struct {
978976 list.replaceRangeAssumeCapacity(0, header.len + 1, "");
979977 const content = try list.toOwnedSlice();
980978 std.debug.assert(content.len == content_len);
981 try r.raw_object_contents.put(r.gpa, oid, .{ _type, content });
982 return .{ _type, content };
979 const obj: GitObject = .{ .type = _type, .content = content };
980 try r.unpacked_objects.put(r.gpa, oid, obj);
981 return obj;
983982 }
984983
985984 // read .idx
......@@ -1043,7 +1042,7 @@ pub const Repository = struct {
10431042 return try r.getPackedObject(oid, pack_index, pack_offset);
10441043 }
10451044
1046 fn getPackedObject(r: *Repository, maybe_oid: ?Id, pack_index: usize, pack_offset: usize) !RawObject {
1045 fn getPackedObject(r: *Repository, maybe_oid: ?Id, pack_index: usize, pack_offset: usize) !GitObject {
10471046 const pack_content = r.pack_content.values()[pack_index];
10481047 if (!std.mem.eql(u8, pack_content[0..4], "PACK")) return error.InvalidGitPack;
10491048 const pack_version = std.mem.readInt(u32, pack_content[4..][0..4], .big);
......@@ -1082,8 +1081,9 @@ pub const Repository = struct {
10821081 try std.compress.flate.inflate.decompress(.zlib, bufr.anyReadable(), list.writer());
10831082 const _type = std.meta.stringToEnum(RefType, @tagName(ty)).?;
10841083 const content = try list.toOwnedSlice();
1085 if (maybe_oid) |oid| try r.raw_object_contents.put(r.gpa, oid, .{ _type, content });
1086 return .{ _type, content };
1084 const obj: GitObject = .{ .type = _type, .content = content };
1085 if (maybe_oid) |oid| try r.unpacked_objects.put(r.gpa, oid, obj);
1086 return obj;
10871087 },
10881088 .ofs_delta => {
10891089 std.log.debug("type={s} size={d}", .{ @tagName(ty), size });
......@@ -1103,14 +1103,6 @@ pub const Repository = struct {
11031103 }
11041104 }
11051105
1106 pub fn getGitObject(r: *Repository, arena: std.mem.Allocator, oid: Id) !?GitObject {
1107 if (try r.getObject(oid, arena)) |data| {
1108 const _type, const content = data;
1109 return .{ .type = _type, .content = content };
1110 }
1111 return null;
1112 }
1113
11141106 const GitObject = struct {
11151107 type: RefType,
11161108 content: []const u8,
......@@ -1120,7 +1112,7 @@ pub const Repository = struct {
11201112 if (r.commits.getPtr(id.id)) |val| {
11211113 return .{ id, val.* };
11221114 }
1123 if (try r.getGitObject(arena, id.id)) |obj| {
1115 if (try r.getObject(arena, id.id)) |obj| {
11241116 if (obj.type == .commit) {
11251117 const commit = try parseCommit(arena, obj.content);
11261118 try r.commits.put(r.gpa, id.id, commit);
......@@ -1134,7 +1126,7 @@ pub const Repository = struct {
11341126 if (r.trees.getPtr(id.id)) |val| {
11351127 return .{ id, val.* };
11361128 }
1137 if (try r.getGitObject(arena, id.id)) |obj| {
1129 if (try r.getObject(arena, id.id)) |obj| {
11381130 if (obj.type == .tree) {
11391131 var children = std.ArrayList(Tree.Object).init(r.gpa);
11401132 errdefer children.deinit();
......@@ -1181,7 +1173,7 @@ pub const Repository = struct {
11811173 if (r.tags.getPtr(id.id)) |val| {
11821174 return .{ id, val.* };
11831175 }
1184 if (try r.getGitObject(arena, id.id)) |obj| {
1176 if (try r.getObject(arena, id.id)) |obj| {
11851177 if (obj.type == .tag) {
11861178 const tag = try parseTag(obj.content);
11871179 try r.tags.put(r.gpa, id.id, tag);