]> gitweb.ps.run Git - ziggit/commitdiff
Create type for object parse return enum
authorpatrick-scho <patrick.schoenberger@posteo.de>
Thu, 22 Aug 2024 09:23:26 +0000 (11:23 +0200)
committerpatrick-scho <patrick.schoenberger@posteo.de>
Thu, 22 Aug 2024 09:23:26 +0000 (11:23 +0200)
git.zig

diff --git a/git.zig b/git.zig
index c45963ea9887938adc0be110adea8eabc2f23753..37933c987c857c99f413668400d1ebd4f0e8e066 100644 (file)
--- 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;
     }