From 9746c5534dd277e310256217fb8670463cf3eef6 Mon Sep 17 00:00:00 2001
From: tri <tri@thac.loan>
Date: Fri, 3 Oct 2025 20:55:45 +0700
Subject: [PATCH] skip weird objects reported by git-ls-tree

---
 src/git.zig  | 17 +++++++++++------
 src/main.zig | 10 +++++-----
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/src/git.zig b/src/git.zig
index c8ebed3..c8cac10 100644
--- a/src/git.zig
+++ b/src/git.zig
@@ -221,7 +221,7 @@ pub fn walkTree(arena: mem.Allocator, dir: fs.Dir) !Walker {
 //    );
 //}
 
-pub const ObjectType = enum { blob, commit, tree };
+pub const ObjectType = enum { blob, commit, tree, other };
 
 pub fn objectType(arena: mem.Allocator, dir: fs.Dir, object_hash: []const u8) !ObjectType {
     var proc = try std.process.Child.run(.{
@@ -245,11 +245,16 @@ pub fn objectType(arena: mem.Allocator, dir: fs.Dir, object_hash: []const u8) !O
         return .tree;
     }
 
-    std.debug.panic("Unrecognized object type: {s} \"{s}\" - {s}", .{
-        object_hash,
-        result,
-        proc.stderr,
-    });
+    // I ran into a repo that had an empty folder, which `git ls-tree` listed
+    // as a "commit" object, but other commands like `git show` would say that
+    // same hash is invalid. I never figured out why that is, so just skip such
+    // cases for now.
+    return .other;
+    //std.debug.panic("Unrecognized object type: {s} \"{s}\" - {s}", .{
+    //    object_hash,
+    //    result,
+    //    proc.stderr,
+    //});
 }
 
 /// Replicates git's simple heuristic: if there's a null byte in the first 8k
diff --git a/src/main.zig b/src/main.zig
index 1176acb..2e7285c 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -514,6 +514,11 @@ pub fn writeFilePage(
     _ = out_dir.statFile(file_name) catch |err| {
         switch (err) {
             error.FileNotFound => {
+                const object_type = try git.objectType(arena, args.in_repo_dir, src_file.hash);
+                if (object_type != .blob) {
+                    return;
+                }
+
                 println("    writing {s}: {s}/{s}", .{
                     args.repo_name,
                     constants.web_objects_path,
@@ -556,11 +561,6 @@ pub fn writeFilePage(
                     try utils.humanReadableSize(arena, src_file.size),
                 });
 
-                const object_type = try git.objectType(arena, args.in_repo_dir, src_file.hash);
-                if (object_type != .blob) {
-                    std.debug.panic("Not implemented: {any}\n", .{object_type});
-                }
-
                 try writer.writeAll(
                     \\<pre class="blob-content">
                     \\
-- 
2.47.3

