From ef8d303fd2efa79c645bdf221edbb1a0087271ca Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Mon, 15 Jun 2026 12:15:32 -0700 Subject: [PATCH] break diffFileIterator out of writeTreeDiffOnlyRaw --- git.zig | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/git.zig b/git.zig index 481ca1f162f05792cc8eef1d9eb27e35832e5f23..077b19d9174c8f72a1322b1807f447bc2c4f925b 100644 --- a/git.zig +++ b/git.zig @@ -1305,18 +1305,7 @@ pub const Repository = struct { return try arena.dupe(CommitId, result.values()); } - pub fn writeTreeDiffOnlyRaw(r: *Repository, writable: anytype, commitid: CommitId, parentid: ?CommitId) !void { - const S = struct { - fn item(w: anytype, b_mode: Tree.Object.Mode, a_mode: Tree.Object.Mode, b_id: Id, a_id: Id, action: TreeDiff.Action, p: ?*const PathListNode, name: []const u8) !void { - if (p == null) { - try w.writevAll(&.{ ":", &b_mode.intbytes(), " ", &a_mode.intbytes(), " ", b_id, " ", a_id, " ", @tagName(action), "\t", name, "\n" }); - return; - } - try w.writevAll(&.{ ":", &b_mode.intbytes(), " ", &a_mode.intbytes(), " ", b_id, " ", a_id, " ", @tagName(action), "\t" }); - try p.?.nprint(w); - try w.writevAll(&.{ "/", name, "\n" }); - } - }; + pub fn diffFileIterator(r: *Repository, writable: anytype, commitid_from: ?CommitId, commitid_to: CommitId, S: type) !void { const A = struct { fn item(w: anytype, mode: Tree.Object.Mode, id: Id, p: ?*const PathListNode, name: []const u8) !void { try S.item(w, .none, mode, &@splat('0'), id, .A, p, name); @@ -1503,18 +1492,33 @@ pub const Repository = struct { } } }; - if (parentid == null) { - const commitidx = try r.getCommitA(r.gpa, commitid.id); + if (commitid_from == null) { + const commitidx = try r.getCommitA(r.gpa, commitid_to.id); const commit = commitidx.reify(r); try A.dir(r, writable, commit.tree.id, null, 0); return; } - const before_commitidx = try r.getCommitA(r.gpa, parentid.?.id); + const before_commitidx = try r.getCommitA(r.gpa, commitid_from.?.id); const before_commit = before_commitidx.reify(r); - const after_commitidx = try r.getCommitA(r.gpa, commitid.id); + const after_commitidx = try r.getCommitA(r.gpa, commitid_to.id); const after_commit = after_commitidx.reify(r); try M.dir(r, writable, before_commit.tree.id, after_commit.tree.id, null); } + + pub fn writeTreeDiffOnlyRaw(r: *Repository, writable: anytype, commitid: CommitId, parentid: ?CommitId) !void { + const S = struct { + fn item(w: anytype, b_mode: Tree.Object.Mode, a_mode: Tree.Object.Mode, b_id: Id, a_id: Id, action: TreeDiff.Action, p: ?*const PathListNode, name: []const u8) !void { + if (p == null) { + try w.writevAll(&.{ ":", &b_mode.intbytes(), " ", &a_mode.intbytes(), " ", b_id, " ", a_id, " ", @tagName(action), "\t", name, "\n" }); + return; + } + try w.writevAll(&.{ ":", &b_mode.intbytes(), " ", &a_mode.intbytes(), " ", b_id, " ", a_id, " ", @tagName(action), "\t" }); + try p.?.nprint(w); + try w.writevAll(&.{ "/", name, "\n" }); + } + }; + return diffFileIterator(r, writable, parentid, commitid, S); + } }; const z = @cImport({ -- 2.54.0