authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-26 17:55:30 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-26 17:55:30 -07:00
loge7e3f078dcebdf6ae37eae5dad25f42a343ffba1
treed7cd67ab82b076b8203d431e67ff636e39f07932
parentc32f692aff65076bef79787429c3f09dbb1b6311
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

replace 'std.process.Child' calls with custom implementation


1 files changed, 27 insertions(+), 63 deletions(-)

git.zig+27-63
...@@ -5,6 +5,7 @@ const extras = @import("extras");...@@ -5,6 +5,7 @@ const extras = @import("extras");
5const tracer = @import("tracer");5const tracer = @import("tracer");
6const nfs = @import("nfs");6const nfs = @import("nfs");
7const nio = @import("nio");7const nio = @import("nio");
8const root = @import("root"); // temp
89
9pub const Id = *const [40]u8;10pub const Id = *const [40]u8;
1011
...@@ -69,14 +70,10 @@ pub const CommitIdx = enum(u32) {...@@ -69,14 +70,10 @@ pub const CommitIdx = enum(u32) {
69};70};
7071
71pub fn version(alloc: std.mem.Allocator) !string {72pub fn version(alloc: std.mem.Allocator) !string {
72 const result = try std.process.Child.run(.{73 const result = try root.child_process.run(alloc, .cwd(), .ignore, .pipe, .pipe, 1024, &.{ "git", "--version" });
73 .allocator = alloc,
74 .argv = &.{ "git", "--version" },
75 .max_output_bytes = 1024,
76 });
77 defer alloc.free(result.stdout);74 defer alloc.free(result.stdout);
78 defer alloc.free(result.stderr);75 defer alloc.free(result.stderr);
79 std.debug.assert(result.term == .Exited and result.term.Exited == 0);76 std.debug.assert(result.term == .exited and result.term.exited == 0);
80 return try alloc.dupe(u8, extras.trimPrefixEnsure(std.mem.trimRight(u8, result.stdout, "\n"), "git version ").?);77 return try alloc.dupe(u8, extras.trimPrefixEnsure(std.mem.trimRight(u8, result.stdout, "\n"), "git version ").?);
81}78}
8279
...@@ -137,19 +134,15 @@ pub fn revList(alloc: std.mem.Allocator, dir: nfs.Dir, comptime count: u31, from...@@ -137,19 +134,15 @@ pub fn revList(alloc: std.mem.Allocator, dir: nfs.Dir, comptime count: u31, from
137 const t = tracer.trace(@src(), "({d}) {s} -- {s}", .{ count, from.id, sub_path });134 const t = tracer.trace(@src(), "({d}) {s} -- {s}", .{ count, from.id, sub_path });
138 defer t.end();135 defer t.end();
139136
140 const result = try std.process.Child.run(.{137 const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .pipe, 1024 * 50, &.{
141 .allocator = alloc,138 "git",
142 .cwd_dir = dir.to_std(),139 "rev-list",
143 .argv = &.{140 "-" ++ std.fmt.comptimePrint("{d}", .{count}),
144 "git",141 from.id,
145 "rev-list",142 "--",
146 "-" ++ std.fmt.comptimePrint("{d}", .{count}),143 sub_path,
147 from.id,
148 "--",
149 sub_path,
150 },
151 });144 });
152 std.debug.assert(result.term == .Exited and result.term.Exited == 0);145 std.debug.assert(result.term == .exited and result.term.exited == 0);
153 return std.mem.trimRight(u8, result.stdout, "\n");146 return std.mem.trimRight(u8, result.stdout, "\n");
154}147}
155148
...@@ -161,12 +154,8 @@ pub fn revListAll(alloc: std.mem.Allocator, dir: nfs.Dir, from: CommitId, sub_pa...@@ -161,12 +154,8 @@ pub fn revListAll(alloc: std.mem.Allocator, dir: nfs.Dir, from: CommitId, sub_pa
161 const t = tracer.trace(@src(), " {s} -- {s}", .{ from.id, sub_path });154 const t = tracer.trace(@src(), " {s} -- {s}", .{ from.id, sub_path });
162 defer t.end();155 defer t.end();
163156
164 const result = try std.process.Child.run(.{157 const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .pipe, 1024 * 50, &.{ "git", "rev-list", from.id, "--", sub_path });
165 .allocator = alloc,158 std.debug.assert(result.term == .exited and result.term.exited == 0);
166 .cwd_dir = dir.to_std(),
167 .argv = &.{ "git", "rev-list", from.id, "--", sub_path },
168 });
169 std.debug.assert(result.term == .Exited and result.term.Exited == 0);
170 return std.mem.trimRight(u8, result.stdout, "\n");159 return std.mem.trimRight(u8, result.stdout, "\n");
171}160}
172161
...@@ -261,24 +250,14 @@ pub fn getTreeDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, p...@@ -261,24 +250,14 @@ pub fn getTreeDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, p
261 defer t.end();250 defer t.end();
262251
263 if (parentid == null) {252 if (parentid == null) {
264 const result = try std.process.Child.run(.{253 // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1
265 .allocator = alloc,254 // result of `printf | git hash-object -t tree --stdin`
266 .cwd_dir = dir.to_std(),255 const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .pipe, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "-p", "--raw", "--full-index", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id });
267 // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1256 std.debug.assert(result.term == .exited and result.term.exited == 0);
268 // result of `printf | git hash-object -t tree --stdin`
269 .argv = &.{ "git", "diff-tree", "-p", "--raw", "--full-index", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id },
270 .max_output_bytes = 1024 * 1024 * 1024,
271 });
272 std.debug.assert(result.term == .Exited and result.term.Exited == 0);
273 return std.mem.trim(u8, result.stdout, "\n");257 return std.mem.trim(u8, result.stdout, "\n");
274 }258 }
275 const result = try std.process.Child.run(.{259 const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .pipe, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "-p", "--raw", "--full-index", parentid.?.id, commitid.id });
276 .allocator = alloc,260 std.debug.assert(result.term == .exited and result.term.exited == 0);
277 .cwd_dir = dir.to_std(),
278 .argv = &.{ "git", "diff-tree", "-p", "--raw", "--full-index", parentid.?.id, commitid.id },
279 .max_output_bytes = 1024 * 1024 * 1024,
280 });
281 std.debug.assert(result.term == .Exited and result.term.Exited == 0);
282 return std.mem.trim(u8, result.stdout, "\n");261 return std.mem.trim(u8, result.stdout, "\n");
283}262}
284263
...@@ -289,24 +268,14 @@ pub fn getTreeDiffPath(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitI...@@ -289,24 +268,14 @@ pub fn getTreeDiffPath(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitI
289 defer t.end();268 defer t.end();
290269
291 if (parentid == null) {270 if (parentid == null) {
292 const result = try std.process.Child.run(.{271 // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1
293 .allocator = alloc,272 // result of `printf | git hash-object -t tree --stdin`
294 .cwd_dir = dir.to_std(),273 const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .pipe, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "-p", "--raw", "--full-index", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id, "--", path });
295 // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1274 std.debug.assert(result.term == .exited and result.term.exited == 0);
296 // result of `printf | git hash-object -t tree --stdin`
297 .argv = &.{ "git", "diff-tree", "-p", "--raw", "--full-index", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id, "--", path },
298 .max_output_bytes = 1024 * 1024 * 1024,
299 });
300 std.debug.assert(result.term == .Exited and result.term.Exited == 0);
301 return std.mem.trim(u8, result.stdout, "\n");275 return std.mem.trim(u8, result.stdout, "\n");
302 }276 }
303 const result = try std.process.Child.run(.{277 const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .pipe, 1024 * 1024 * 1024, &.{ "git", "diff-tree", "-p", "--raw", "--full-index", parentid.?.id, commitid.id, "--", path });
304 .allocator = alloc,278 std.debug.assert(result.term == .exited and result.term.exited == 0);
305 .cwd_dir = dir.to_std(),
306 .argv = &.{ "git", "diff-tree", "-p", "--raw", "--full-index", parentid.?.id, commitid.id, "--", path },
307 .max_output_bytes = 1024 * 1024 * 1024,
308 });
309 std.debug.assert(result.term == .Exited and result.term.Exited == 0);
310 return std.mem.trim(u8, result.stdout, "\n");279 return std.mem.trim(u8, result.stdout, "\n");
311}280}
312281
...@@ -574,13 +543,8 @@ pub fn getBlame(alloc: std.mem.Allocator, dir: nfs.Dir, at: CommitId, sub_path:...@@ -574,13 +543,8 @@ pub fn getBlame(alloc: std.mem.Allocator, dir: nfs.Dir, at: CommitId, sub_path:
574 const t = tracer.trace(@src(), " {s} -- {s}", .{ at.id, sub_path });543 const t = tracer.trace(@src(), " {s} -- {s}", .{ at.id, sub_path });
575 defer t.end();544 defer t.end();
576545
577 const result = try std.process.Child.run(.{546 const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .pipe, 1024 * 1024 * 1024, &.{ "git", "blame", "-p", at.id, "--", sub_path });
578 .allocator = alloc,547 extras.assertLog(result.term == .exited and result.term.exited == 0, "{s}", .{result.stderr});
579 .cwd_dir = dir.to_std(),
580 .argv = &.{ "git", "blame", "-p", at.id, "--", sub_path },
581 .max_output_bytes = 1024 * 1024 * 1024,
582 });
583 extras.assertLog(result.term == .Exited and result.term.Exited == 0, "{s}", .{result.stderr});
584 return result.stdout;548 return result.stdout;
585}549}
586550