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 {...@@ -41,14 +41,14 @@ pub const TagId = struct {
41 }41 }
42};42};
4343
44pub const OidKind = enum {44pub const RefType = enum {
45 blob,45 blob,
46 tree,46 tree,
47 commit,47 commit,
48 tag,48 tag,
49};49};
5050
51pub const AnyId = union(OidKind) {51pub const AnyId = union(RefType) {
52 blob: BlobId,52 blob: BlobId,
53 tree: TreeId,53 tree: TreeId,
54 commit: CommitId,54 commit: CommitId,
...@@ -159,7 +159,7 @@ pub fn getObjectSize(alloc: std.mem.Allocator, dir: nfs.Dir, obj: Id) !u64 {...@@ -159,7 +159,7 @@ pub fn getObjectSize(alloc: std.mem.Allocator, dir: nfs.Dir, obj: Id) !u64 {
159// TODO make this inspect .git manually159// TODO make this inspect .git manually
160// https://git-scm.com/book/en/v2/Git-Internals-Git-Objects160// https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
161// https://git-scm.com/book/en/v2/Git-Internals-Packfiles161// 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 {
163 const t = tracer.trace(@src(), " {s} = {s} ?", .{ maybeobj, @tagName(typ) });163 const t = tracer.trace(@src(), " {s} = {s} ?", .{ maybeobj, @tagName(typ) });
164 defer t.end();164 defer t.end();
165165
...@@ -170,13 +170,13 @@ pub fn isType(alloc: std.mem.Allocator, dir: nfs.Dir, maybeobj: Id, typ: OidKind...@@ -170,13 +170,13 @@ pub fn isType(alloc: std.mem.Allocator, dir: nfs.Dir, maybeobj: Id, typ: OidKind
170 });170 });
171 std.debug.assert(result.term == .Exited and result.term.Exited == 0);171 std.debug.assert(result.term == .Exited and result.term.Exited == 0);
172 const output = std.mem.trimRight(u8, result.stdout, "\n");172 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;
174}174}
175175
176// TODO make this inspect .git manually176// TODO make this inspect .git manually
177// https://git-scm.com/book/en/v2/Git-Internals-Git-Objects177// https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
178// https://git-scm.com/book/en/v2/Git-Internals-Packfiles178// 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 {
180 const t = tracer.trace(@src(), " {s}", .{obj});180 const t = tracer.trace(@src(), " {s}", .{obj});
181 defer t.end();181 defer t.end();
182182
...@@ -187,7 +187,7 @@ pub fn getType(alloc: std.mem.Allocator, dir: nfs.Dir, obj: Id) !OidKind {...@@ -187,7 +187,7 @@ pub fn getType(alloc: std.mem.Allocator, dir: nfs.Dir, obj: Id) !OidKind {
187 });187 });
188 std.debug.assert(result.term == .Exited and result.term.Exited == 0);188 std.debug.assert(result.term == .Exited and result.term.Exited == 0);
189 const output = std.mem.trimRight(u8, result.stdout, "\n");189 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);
191}191}
192192
193// TODO make this inspect .git/objects manually193// TODO make this inspect .git/objects manually
...@@ -331,7 +331,7 @@ pub fn parseTree(alloc: std.mem.Allocator, treefile: string) !Tree {...@@ -331,7 +331,7 @@ pub fn parseTree(alloc: std.mem.Allocator, treefile: string) !Tree {
331 }331 }
332 var jter = std.mem.splitScalar(u8, line, ' ');332 var jter = std.mem.splitScalar(u8, line, ' ');
333 const mode = jter.next().?;333 const mode = jter.next().?;
334 const otype = std.meta.stringToEnum(OidKind, jter.next().?).?;334 const otype = std.meta.stringToEnum(RefType, jter.next().?).?;
335 const id_and_name = jter.rest();335 const id_and_name = jter.rest();
336 const tab_pos = std.mem.indexOfScalar(u8, id_and_name, '\t').?; // why git. why.336 const tab_pos = std.mem.indexOfScalar(u8, id_and_name, '\t').?; // why git. why.
337 std.debug.assert(tab_pos == 40);337 std.debug.assert(tab_pos == 40);
...@@ -844,7 +844,7 @@ pub fn parseTag(tagfile: string) !Tag {...@@ -844,7 +844,7 @@ pub fn parseTag(tagfile: string) !Tag {
844 std.debug.assert(object.len == 40);844 std.debug.assert(object.len == 40);
845 result.object = object[0..40];845 result.object = object[0..40];
846 const ty = extras.trimPrefixEnsure(iter.next().?, "type ").?;846 const ty = extras.trimPrefixEnsure(iter.next().?, "type ").?;
847 result.type = std.meta.stringToEnum(OidKind, ty).?;847 result.type = std.meta.stringToEnum(RefType, ty).?;
848 const tag = extras.trimPrefixEnsure(iter.next().?, "tag ").?;848 const tag = extras.trimPrefixEnsure(iter.next().?, "tag ").?;
849 _ = tag;849 _ = tag;
850850
...@@ -861,7 +861,7 @@ pub fn parseTag(tagfile: string) !Tag {...@@ -861,7 +861,7 @@ pub fn parseTag(tagfile: string) !Tag {
861861
862pub const Tag = struct {862pub const Tag = struct {
863 object: Id,863 object: Id,
864 type: OidKind,864 type: RefType,
865 tagger: ?UserAndAt,865 tagger: ?UserAndAt,
866 message: string,866 message: string,
867};867};
...@@ -1156,13 +1156,6 @@ pub const Repository = struct {...@@ -1156,13 +1156,6 @@ pub const Repository = struct {
1156 return null;1156 return null;
1157 }1157 }
11581158
1159 const RefType = enum {
1160 blob,
1161 tree,
1162 commit,
1163 tag,
1164 };
1165
1166 const GitObject = struct {1159 const GitObject = struct {
1167 type: RefType,1160 type: RefType,
1168 content: []const u8,1161 content: []const u8,