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");
55const tracer = @import("tracer");
66const nfs = @import("nfs");
77const nio = @import("nio");
8const root = @import("root"); // temp
89
910pub const Id = *const [40]u8;
1011
......@@ -69,14 +70,10 @@ pub const CommitIdx = enum(u32) {
6970};
7071
7172pub fn version(alloc: std.mem.Allocator) !string {
72 const result = try std.process.Child.run(.{
73 .allocator = alloc,
74 .argv = &.{ "git", "--version" },
75 .max_output_bytes = 1024,
76 });
73 const result = try root.child_process.run(alloc, .cwd(), .ignore, .pipe, .pipe, 1024, &.{ "git", "--version" });
7774 defer alloc.free(result.stdout);
7875 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);
8077 return try alloc.dupe(u8, extras.trimPrefixEnsure(std.mem.trimRight(u8, result.stdout, "\n"), "git version ").?);
8178}
8279
......@@ -137,19 +134,15 @@ pub fn revList(alloc: std.mem.Allocator, dir: nfs.Dir, comptime count: u31, from
137134 const t = tracer.trace(@src(), "({d}) {s} -- {s}", .{ count, from.id, sub_path });
138135 defer t.end();
139136
140 const result = try std.process.Child.run(.{
141 .allocator = alloc,
142 .cwd_dir = dir.to_std(),
143 .argv = &.{
144 "git",
145 "rev-list",
146 "-" ++ std.fmt.comptimePrint("{d}", .{count}),
147 from.id,
148 "--",
149 sub_path,
150 },
137 const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .pipe, 1024 * 50, &.{
138 "git",
139 "rev-list",
140 "-" ++ std.fmt.comptimePrint("{d}", .{count}),
141 from.id,
142 "--",
143 sub_path,
151144 });
152 std.debug.assert(result.term == .Exited and result.term.Exited == 0);
145 std.debug.assert(result.term == .exited and result.term.exited == 0);
153146 return std.mem.trimRight(u8, result.stdout, "\n");
154147}
155148
......@@ -161,12 +154,8 @@ pub fn revListAll(alloc: std.mem.Allocator, dir: nfs.Dir, from: CommitId, sub_pa
161154 const t = tracer.trace(@src(), " {s} -- {s}", .{ from.id, sub_path });
162155 defer t.end();
163156
164 const result = try std.process.Child.run(.{
165 .allocator = alloc,
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);
157 const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .pipe, 1024 * 50, &.{ "git", "rev-list", from.id, "--", sub_path });
158 std.debug.assert(result.term == .exited and result.term.exited == 0);
170159 return std.mem.trimRight(u8, result.stdout, "\n");
171160}
172161
......@@ -261,24 +250,14 @@ pub fn getTreeDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, p
261250 defer t.end();
262251
263252 if (parentid == null) {
264 const result = try std.process.Child.run(.{
265 .allocator = alloc,
266 .cwd_dir = dir.to_std(),
267 // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1
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);
253 // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1
254 // result of `printf | git hash-object -t tree --stdin`
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 });
256 std.debug.assert(result.term == .exited and result.term.exited == 0);
273257 return std.mem.trim(u8, result.stdout, "\n");
274258 }
275 const result = try std.process.Child.run(.{
276 .allocator = alloc,
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);
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 });
260 std.debug.assert(result.term == .exited and result.term.exited == 0);
282261 return std.mem.trim(u8, result.stdout, "\n");
283262}
284263
......@@ -289,24 +268,14 @@ pub fn getTreeDiffPath(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitI
289268 defer t.end();
290269
291270 if (parentid == null) {
292 const result = try std.process.Child.run(.{
293 .allocator = alloc,
294 .cwd_dir = dir.to_std(),
295 // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1
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);
271 // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1
272 // result of `printf | git hash-object -t tree --stdin`
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 });
274 std.debug.assert(result.term == .exited and result.term.exited == 0);
301275 return std.mem.trim(u8, result.stdout, "\n");
302276 }
303 const result = try std.process.Child.run(.{
304 .allocator = alloc,
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);
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 });
278 std.debug.assert(result.term == .exited and result.term.exited == 0);
310279 return std.mem.trim(u8, result.stdout, "\n");
311280}
312281
......@@ -574,13 +543,8 @@ pub fn getBlame(alloc: std.mem.Allocator, dir: nfs.Dir, at: CommitId, sub_path:
574543 const t = tracer.trace(@src(), " {s} -- {s}", .{ at.id, sub_path });
575544 defer t.end();
576545
577 const result = try std.process.Child.run(.{
578 .allocator = alloc,
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});
546 const result = try root.child_process.run(alloc, dir, .ignore, .pipe, .pipe, 1024 * 1024 * 1024, &.{ "git", "blame", "-p", at.id, "--", sub_path });
547 extras.assertLog(result.term == .exited and result.term.exited == 0, "{s}", .{result.stderr});
584548 return result.stdout;
585549}
586550