authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-15 19:31:36 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-15 19:31:36 -07:00
logee13f80f6a00477098711a81fdef8d65ca6d1c2e
treecc697b5735b1541a914487d879f9f866774c8556
parentf203efd825c26709ae1df22df4adad3d959fed76
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

rewrite getTreeDiffOnlySummary in zig as writeTreeDiffOnlySummary


1 files changed, 42 insertions(+), 17 deletions(-)

git.zig+42-17
......@@ -278,23 +278,6 @@ pub fn getTreeDiffOnlyStat(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: Com
278278 return result.stdout;
279279}
280280
281// TODO make this inspect .git manually
282pub fn getTreeDiffOnlySummary(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, parentid: ?CommitId) !string {
283 const t = tracer.trace(@src(), "", .{});
284 defer t.end();
285
286 if (parentid == null) {
287 // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1
288 // result of `printf | git hash-object -t tree --stdin`
289 const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .ignore, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "--summary", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id });
290 std.debug.assert(result.term == .exited and result.term.exited == 0);
291 return result.stdout;
292 }
293 const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .ignore, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "--summary", parentid.?.id, commitid.id });
294 std.debug.assert(result.term == .exited and result.term.exited == 0);
295 return result.stdout;
296}
297
298281// TODO make this inspect .git manually
299282pub fn getTreeDiffOnlyDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, parentid: ?CommitId) !string {
300283 const t = tracer.trace(@src(), "", .{});
......@@ -1519,6 +1502,48 @@ pub const Repository = struct {
15191502 };
15201503 return diffFileIterator(r, writable, parentid, commitid, S);
15211504 }
1505
1506 pub fn writeTreeDiffOnlySummary(r: *Repository, writable: anytype, commitid: CommitId, parentid: ?CommitId) !void {
1507 const S = struct {
1508 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 {
1509 _ = b_id;
1510 _ = a_id;
1511 switch (action) {
1512 .A => {
1513 if (p == null) {
1514 try w.writevAll(&.{ " create mode ", &a_mode.intbytes(), " ", name, "\n" });
1515 return;
1516 }
1517 try w.writevAll(&.{ " create mode ", &a_mode.intbytes(), " " });
1518 try p.?.nprint(w);
1519 try w.writevAll(&.{ "/", name, "\n" });
1520 },
1521 .D => {
1522 if (p == null) {
1523 try w.writevAll(&.{ " delete mode ", &b_mode.intbytes(), " ", name, "\n" });
1524 return;
1525 }
1526 try w.writevAll(&.{ " delete mode ", &b_mode.intbytes(), " " });
1527 try p.?.nprint(w);
1528 try w.writevAll(&.{ "/", name, "\n" });
1529 },
1530 .M => {
1531 if (!std.mem.eql(u8, &b_mode.intbytes(), &a_mode.intbytes())) {
1532 if (p == null) {
1533 try w.writevAll(&.{ " mode change ", &b_mode.intbytes(), " => ", &a_mode.intbytes(), " ", name, "\n" });
1534 return;
1535 }
1536 try w.writevAll(&.{ " mode change ", &b_mode.intbytes(), " => ", &a_mode.intbytes(), " " });
1537 try p.?.nprint(w);
1538 try w.writevAll(&.{ "/", name, "\n" });
1539 }
1540 },
1541 else => {},
1542 }
1543 }
1544 };
1545 return diffFileIterator(r, writable, parentid, commitid, S);
1546 }
15221547};
15231548
15241549const z = @cImport({