| ... | ... | @@ -980,6 +980,7 @@ pub const Repository = struct { |
| 980 | 980 | pack_content: std.StringArrayHashMapUnmanaged([]const u8), |
| 981 | 981 | commits: std.StringArrayHashMapUnmanaged(Commit), |
| 982 | 982 | trees: std.StringArrayHashMapUnmanaged(Tree), |
| 983 | tags: std.StringArrayHashMapUnmanaged(Tag), |
| 983 | 984 | |
| 984 | 985 | pub fn init(gitdir: nfs.Dir, gpa: std.mem.Allocator) Repository { |
| 985 | 986 | return .{ |
| ... | ... | @@ -990,6 +991,7 @@ pub const Repository = struct { |
| 990 | 991 | .pack_content = .empty, |
| 991 | 992 | .commits = .empty, |
| 992 | 993 | .trees = .empty, |
| 994 | .tags = .empty, |
| 993 | 995 | }; |
| 994 | 996 | } |
| 995 | 997 | |
| ... | ... | @@ -1003,6 +1005,7 @@ pub const Repository = struct { |
| 1003 | 1005 | r.commits.deinit(r.gpa); |
| 1004 | 1006 | for (r.trees.values()) |v| r.gpa.free(v.children); |
| 1005 | 1007 | r.trees.deinit(r.gpa); |
| 1008 | r.tags.deinit(r.gpa); |
| 1006 | 1009 | } |
| 1007 | 1010 | |
| 1008 | 1011 | fn getObject(r: *Repository, obj: Id, arena: std.mem.Allocator) !?[]const u8 { |
| ... | ... | @@ -1142,7 +1145,7 @@ pub const Repository = struct { |
| 1142 | 1145 | return null; |
| 1143 | 1146 | } |
| 1144 | 1147 | |
| 1145 | | fn getGitObject(r: *Repository, obj: Id, arena: std.mem.Allocator) !?GitObject { |
| 1148 | pub fn getGitObject(r: *Repository, obj: Id, arena: std.mem.Allocator) !?GitObject { |
| 1146 | 1149 | if (try r.getObject(obj, arena)) |data| { |
| 1147 | 1150 | const header = data[0..std.mem.indexOfScalar(u8, data, 0).?]; |
| 1148 | 1151 | const _type = header[0..std.mem.indexOfScalar(u8, header, ' ').?]; |
| ... | ... | @@ -1221,4 +1224,18 @@ pub const Repository = struct { |
| 1221 | 1224 | } |
| 1222 | 1225 | return null; |
| 1223 | 1226 | } |
| 1227 | |
| 1228 | pub fn getTag(r: *Repository, arena: std.mem.Allocator, id: TagId) !?struct { TagId, Tag } { |
| 1229 | if (r.tags.getPtr(id.id)) |val| { |
| 1230 | return .{ id, val.* }; |
| 1231 | } |
| 1232 | if (try r.getGitObject(id.id, arena)) |obj| { |
| 1233 | if (obj.type == .tag) { |
| 1234 | const tag = try parseTag(obj.content); |
| 1235 | try r.tags.put(r.gpa, id.id, tag); |
| 1236 | return .{ id, tag }; |
| 1237 | } |
| 1238 | } |
| 1239 | return null; |
| 1240 | } |
| 1224 | 1241 | }; |