authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-10 02:31:41 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-10 02:31:41 -07:00
log10d1d2f0499e09f8c66a263d8fa7a2601e29d385
tree3c7afde89159e6cb46e4c1b222c51b6eb62234bf
parentd666933ee74a8729063104bf3068c037804485ed
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

OidKind -> RefType


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

git.zig+9-16
......@@ -41,14 +41,14 @@ pub const TagId = struct {
4141 }
4242};
4343
44pub const OidKind = enum {
44pub const RefType = enum {
4545 blob,
4646 tree,
4747 commit,
4848 tag,
4949};
5050
51pub const AnyId = union(OidKind) {
51pub const AnyId = union(RefType) {
5252 blob: BlobId,
5353 tree: TreeId,
5454 commit: CommitId,
......@@ -159,7 +159,7 @@ pub fn getObjectSize(alloc: std.mem.Allocator, dir: nfs.Dir, obj: Id) !u64 {
159159// TODO make this inspect .git manually
160160// https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
161161// https://git-scm.com/book/en/v2/Git-Internals-Packfiles
162pub fn isType(alloc: std.mem.Allocator, dir: nfs.Dir, maybeobj: Id, typ: OidKind) !bool {
162pub fn isType(alloc: std.mem.Allocator, dir: nfs.Dir, maybeobj: Id, typ: RefType) !bool {
163163 const t = tracer.trace(@src(), " {s} = {s} ?", .{ maybeobj, @tagName(typ) });
164164 defer t.end();
165165
......@@ -170,13 +170,13 @@ pub fn isType(alloc: std.mem.Allocator, dir: nfs.Dir, maybeobj: Id, typ: OidKind
170170 });
171171 std.debug.assert(result.term == .Exited and result.term.Exited == 0);
172172 const output = std.mem.trimRight(u8, result.stdout, "\n");
173 return std.meta.stringToEnum(OidKind, output).? == typ;
173 return std.meta.stringToEnum(RefType, output).? == typ;
174174}
175175
176176// TODO make this inspect .git manually
177177// https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
178178// https://git-scm.com/book/en/v2/Git-Internals-Packfiles
179pub fn getType(alloc: std.mem.Allocator, dir: nfs.Dir, obj: Id) !OidKind {
179pub fn getType(alloc: std.mem.Allocator, dir: nfs.Dir, obj: Id) !RefType {
180180 const t = tracer.trace(@src(), " {s}", .{obj});
181181 defer t.end();
182182
......@@ -187,7 +187,7 @@ pub fn getType(alloc: std.mem.Allocator, dir: nfs.Dir, obj: Id) !OidKind {
187187 });
188188 std.debug.assert(result.term == .Exited and result.term.Exited == 0);
189189 const output = std.mem.trimRight(u8, result.stdout, "\n");
190 return std.meta.stringToEnum(OidKind, output) orelse @panic(output);
190 return std.meta.stringToEnum(RefType, output) orelse @panic(output);
191191}
192192
193193// TODO make this inspect .git/objects manually
......@@ -331,7 +331,7 @@ pub fn parseTree(alloc: std.mem.Allocator, treefile: string) !Tree {
331331 }
332332 var jter = std.mem.splitScalar(u8, line, ' ');
333333 const mode = jter.next().?;
334 const otype = std.meta.stringToEnum(OidKind, jter.next().?).?;
334 const otype = std.meta.stringToEnum(RefType, jter.next().?).?;
335335 const id_and_name = jter.rest();
336336 const tab_pos = std.mem.indexOfScalar(u8, id_and_name, '\t').?; // why git. why.
337337 std.debug.assert(tab_pos == 40);
......@@ -844,7 +844,7 @@ pub fn parseTag(tagfile: string) !Tag {
844844 std.debug.assert(object.len == 40);
845845 result.object = object[0..40];
846846 const ty = extras.trimPrefixEnsure(iter.next().?, "type ").?;
847 result.type = std.meta.stringToEnum(OidKind, ty).?;
847 result.type = std.meta.stringToEnum(RefType, ty).?;
848848 const tag = extras.trimPrefixEnsure(iter.next().?, "tag ").?;
849849 _ = tag;
850850
......@@ -861,7 +861,7 @@ pub fn parseTag(tagfile: string) !Tag {
861861
862862pub const Tag = struct {
863863 object: Id,
864 type: OidKind,
864 type: RefType,
865865 tagger: ?UserAndAt,
866866 message: string,
867867};
......@@ -1156,13 +1156,6 @@ pub const Repository = struct {
11561156 return null;
11571157 }
11581158
1159 const RefType = enum {
1160 blob,
1161 tree,
1162 commit,
1163 tag,
1164 };
1165
11661159 const GitObject = struct {
11671160 type: RefType,
11681161 content: []const u8,