| ... | @@ -41,14 +41,14 @@ pub const TagId = struct { | ... | @@ -41,14 +41,14 @@ pub const TagId = struct { |
| 41 | } | 41 | } |
| 42 | }; | 42 | }; |
| 43 | | 43 | |
| 44 | pub const OidKind = enum { | 44 | pub const RefType = enum { |
| 45 | blob, | 45 | blob, |
| 46 | tree, | 46 | tree, |
| 47 | commit, | 47 | commit, |
| 48 | tag, | 48 | tag, |
| 49 | }; | 49 | }; |
| 50 | | 50 | |
| 51 | pub const AnyId = union(OidKind) { | 51 | pub 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 manually | 159 | // TODO make this inspect .git manually |
| 160 | // https://git-scm.com/book/en/v2/Git-Internals-Git-Objects | 160 | // https://git-scm.com/book/en/v2/Git-Internals-Git-Objects |
| 161 | // https://git-scm.com/book/en/v2/Git-Internals-Packfiles | 161 | // https://git-scm.com/book/en/v2/Git-Internals-Packfiles |
| 162 | pub fn isType(alloc: std.mem.Allocator, dir: nfs.Dir, maybeobj: Id, typ: OidKind) !bool { | 162 | pub 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(); |
| 165 | | 165 | |
| ... | @@ -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 | } |
| 175 | | 175 | |
| 176 | // TODO make this inspect .git manually | 176 | // TODO make this inspect .git manually |
| 177 | // https://git-scm.com/book/en/v2/Git-Internals-Git-Objects | 177 | // https://git-scm.com/book/en/v2/Git-Internals-Git-Objects |
| 178 | // https://git-scm.com/book/en/v2/Git-Internals-Packfiles | 178 | // https://git-scm.com/book/en/v2/Git-Internals-Packfiles |
| 179 | pub fn getType(alloc: std.mem.Allocator, dir: nfs.Dir, obj: Id) !OidKind { | 179 | pub 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(); |
| 182 | | 182 | |
| ... | @@ -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 | } |
| 192 | | 192 | |
| 193 | // TODO make this inspect .git/objects manually | 193 | // 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; |
| 850 | | 850 | |
| ... | @@ -861,7 +861,7 @@ pub fn parseTag(tagfile: string) !Tag { | ... | @@ -861,7 +861,7 @@ pub fn parseTag(tagfile: string) !Tag { |
| 861 | | 861 | |
| 862 | pub const Tag = struct { | 862 | pub 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 | } |
| 1158 | | 1158 | |
| 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, |