From bd47c78ad5d0534eac28ec12379deef8f01c335d Mon Sep 17 00:00:00 2001
From: tri <tri@thac.loan>
Date: Tue, 7 Oct 2025 17:51:21 +0700
Subject: [PATCH] generate patches using git-format-patch instead

Two things:

- It can be fed into `git am`, which preserves authorship
- It actually includes binary blobs, unlike the previous format
---
 src/git.zig  | 17 +++++++++++++++++
 src/main.zig |  4 +++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/git.zig b/src/git.zig
index 4ae29ff..7466b3d 100644
--- a/src/git.zig
+++ b/src/git.zig
@@ -295,3 +295,20 @@ pub fn show(arena: mem.Allocator, dir: fs.Dir, commit_hash: []const u8) ![]const
     std.debug.assert(git_proc.term.Exited == 0);
     return git_proc.stdout;
 }
+
+pub fn formatPatch(arena: mem.Allocator, dir: fs.Dir, commit_hash: []const u8) ![]const u8 {
+    var proc = try std.process.Child.run(.{
+        .allocator = arena,
+        .cwd_dir = dir,
+        .max_output_bytes = 1024 * 1024 * 1024,
+        .argv = &.{
+            "git",
+            "format-patch",
+            "-1",
+            "--stdout",
+            commit_hash,
+        },
+    });
+    std.debug.assert(proc.term.Exited == 0);
+    return proc.stdout;
+}
diff --git a/src/main.zig b/src/main.zig
index fe2aa4f..4369af7 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -651,9 +651,11 @@ pub fn writeCommitPage(
     var objects_dir = try out_repo_dir.openDir(constants.web_objects_path, .{});
     defer objects_dir.close();
 
+    const patch = try git.formatPatch(arena, args.in_repo_dir, commit.hash);
+
     try objects_dir.writeFile(.{
         .sub_path = try fmt.allocPrint(arena, "{s}.patch", .{commit.hash}),
-        .data = commit_text,
+        .data = patch,
         .flags = .{},
     });
 }
-- 
2.47.3

