authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-12 21:31:08 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-12 21:31:08 -07:00
log8610e2358d919445eb36f2eba18b4bb307b9202f
tree95c8858a4aa98e11636819a9867577b443697283
parent91e933583cac89fa00ad2e44a7075dc37a62157b
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add more getTreeDiff variations for specific endpoints


1 files changed, 87 insertions(+), 0 deletions(-)

git.zig+87
......@@ -261,6 +261,93 @@ pub fn getTreeDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, p
261261 return std.mem.trim(u8, result.stdout, "\n");
262262}
263263
264// TODO make this inspect .git manually
265pub fn getTreeDiffOnlyRaw(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, parentid: ?CommitId) !string {
266 const t = tracer.trace(@src(), "", .{});
267 defer t.end();
268
269 if (parentid == null) {
270 // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1
271 // result of `printf | git hash-object -t tree --stdin`
272 const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .ignore, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "--raw", "-r", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id });
273 std.debug.assert(result.term == .exited and result.term.exited == 0);
274 return std.mem.trim(u8, result.stdout, "\n");
275 }
276 const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .ignore, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "--raw", "-r", parentid.?.id, commitid.id });
277 std.debug.assert(result.term == .exited and result.term.exited == 0);
278 return std.mem.trim(u8, result.stdout, "\n");
279}
280
281// TODO make this inspect .git manually
282pub fn getTreeDiffOnlyStat(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", "--stat", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id });
290 std.debug.assert(result.term == .exited and result.term.exited == 0);
291 return std.mem.trim(u8, result.stdout, "\n");
292 }
293 const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .ignore, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "--stat", parentid.?.id, commitid.id });
294 std.debug.assert(result.term == .exited and result.term.exited == 0);
295 return std.mem.trim(u8, result.stdout, "\n");
296}
297
298// TODO make this inspect .git manually
299pub fn getTreeDiffOnlySummary(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, parentid: ?CommitId) !string {
300 const t = tracer.trace(@src(), "", .{});
301 defer t.end();
302
303 if (parentid == null) {
304 // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1
305 // result of `printf | git hash-object -t tree --stdin`
306 const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .ignore, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "--summary", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id });
307 std.debug.assert(result.term == .exited and result.term.exited == 0);
308 return std.mem.trim(u8, result.stdout, "\n");
309 }
310 const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .ignore, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "--summary", parentid.?.id, commitid.id });
311 std.debug.assert(result.term == .exited and result.term.exited == 0);
312 return std.mem.trim(u8, result.stdout, "\n");
313}
314
315// TODO make this inspect .git manually
316pub fn getTreeDiffOnlyDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, parentid: ?CommitId) !string {
317 const t = tracer.trace(@src(), "", .{});
318 defer t.end();
319
320 if (parentid == null) {
321 // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1
322 // result of `printf | git hash-object -t tree --stdin`
323 const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .ignore, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "--patch", "--full-index", "--patience", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id });
324 if (!(result.term == .exited and result.term.exited == 0)) std.log.err("{s}", .{result.stderr});
325 std.debug.assert(result.term == .exited and result.term.exited == 0);
326 return std.mem.trim(u8, result.stdout, "\n");
327 }
328 const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .ignore, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "--patch", "--full-index", "--patience", parentid.?.id, commitid.id });
329 if (!(result.term == .exited and result.term.exited == 0)) std.log.err("{s}", .{result.stderr});
330 std.debug.assert(result.term == .exited and result.term.exited == 0);
331 return std.mem.trim(u8, result.stdout, "\n");
332}
333
334// TODO make this inspect .git manually
335pub fn getFormatPatch(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, parentid: ?CommitId) !string {
336 const t = tracer.trace(@src(), "", .{});
337 defer t.end();
338
339 if (parentid == null) {
340 const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .pipe, 1024 * 1024 * 1024, &.{ "git", "format-patch", "--stdout", "--full-index", "--patience", "--root", commitid.id });
341 if (!(result.term == .exited and result.term.exited == 0)) std.log.err("{s}", .{result.stderr});
342 std.debug.assert(result.term == .exited and result.term.exited == 0);
343 return std.mem.trim(u8, result.stdout, "\n");
344 }
345 const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .pipe, 1024 * 1024 * 1024, &.{ "git", "format-patch", "--stdout", "--full-index", "--patience", parentid.?.id ++ "..." ++ commitid.id });
346 if (!(result.term == .exited and result.term.exited == 0)) std.log.err("{s}", .{result.stderr});
347 std.debug.assert(result.term == .exited and result.term.exited == 0);
348 return std.mem.trim(u8, result.stdout, "\n");
349}
350
264351// TODO make this inspect .git manually
265352// TODO make this return a Reader when we implement it ourselves
266353pub fn getTreeDiffPath(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, parentid: ?CommitId, path: []const u8) !string {