From: patrick-scho Date: Thu, 22 Aug 2024 09:23:26 +0000 (+0200) Subject: Create type for object parse return enum X-Git-Url: https://gitweb.ps.run/ziggit/commitdiff_plain/efdfc67c25639929fb63ef7f6e18474690546599?ds=inline Create type for object parse return enum --- diff --git a/git.zig b/git.zig index c45963e..37933c9 100644 --- a/git.zig +++ b/git.zig @@ -23,6 +23,11 @@ const Tree = std.ArrayList(TreeEntry); const Blob = struct { data: []u8, }; +const ParsedObject = union(enum) { + c: Commit, + t: Tree, + b: Blob, +}; const Object = struct { kind: u3, data: []u8, @@ -33,7 +38,7 @@ const Object = struct { .data = data, }; } - pub fn parse(self: Object, alloc: Alloc) !union(enum) { c: Commit, t: Tree, b: Blob } { + pub fn parse(self: Object, alloc: Alloc) !ParsedObject { switch (self.kind) { 1 => { const authorOffset = std.mem.indexOf(u8, self.data, "author ") orelse return error.InvalidCommitFormat; @@ -350,7 +355,9 @@ const PackFile = struct { const pckReader = self.pckFile.reader().any(); try self.pckFile.seekTo(offset); - return try self.readObject(pckReader); + const o = try self.readObject(pckReader); + + return o; } return null; }