| ... | ... | @@ -5,6 +5,7 @@ const extras = @import("extras"); |
| 5 | 5 | const tracer = @import("tracer"); |
| 6 | 6 | const nfs = @import("nfs"); |
| 7 | 7 | const nio = @import("nio"); |
| 8 | const root = @import("root"); // temp |
| 8 | 9 | |
| 9 | 10 | pub const Id = *const [40]u8; |
| 10 | 11 | |
| ... | ... | @@ -69,14 +70,10 @@ pub const CommitIdx = enum(u32) { |
| 69 | 70 | }; |
| 70 | 71 | |
| 71 | 72 | pub 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" }); |
| 77 | 74 | defer alloc.free(result.stdout); |
| 78 | 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 | 77 | return try alloc.dupe(u8, extras.trimPrefixEnsure(std.mem.trimRight(u8, result.stdout, "\n"), "git version ").?); |
| 81 | 78 | } |
| 82 | 79 | |
| ... | ... | @@ -137,19 +134,15 @@ pub fn revList(alloc: std.mem.Allocator, dir: nfs.Dir, comptime count: u31, from |
| 137 | 134 | const t = tracer.trace(@src(), "({d}) {s} -- {s}", .{ count, from.id, sub_path }); |
| 138 | 135 | defer t.end(); |
| 139 | 136 | |
| 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, |
| 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 | 146 | return std.mem.trimRight(u8, result.stdout, "\n"); |
| 154 | 147 | } |
| 155 | 148 | |
| ... | ... | @@ -161,12 +154,8 @@ pub fn revListAll(alloc: std.mem.Allocator, dir: nfs.Dir, from: CommitId, sub_pa |
| 161 | 154 | const t = tracer.trace(@src(), " {s} -- {s}", .{ from.id, sub_path }); |
| 162 | 155 | defer t.end(); |
| 163 | 156 | |
| 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); |
| 170 | 159 | return std.mem.trimRight(u8, result.stdout, "\n"); |
| 171 | 160 | } |
| 172 | 161 | |
| ... | ... | @@ -261,24 +250,14 @@ pub fn getTreeDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, p |
| 261 | 250 | defer t.end(); |
| 262 | 251 | |
| 263 | 252 | 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); |
| 273 | 257 | return std.mem.trim(u8, result.stdout, "\n"); |
| 274 | 258 | } |
| 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); |
| 282 | 261 | return std.mem.trim(u8, result.stdout, "\n"); |
| 283 | 262 | } |
| 284 | 263 | |
| ... | ... | @@ -289,24 +268,14 @@ pub fn getTreeDiffPath(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitI |
| 289 | 268 | defer t.end(); |
| 290 | 269 | |
| 291 | 270 | 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); |
| 301 | 275 | return std.mem.trim(u8, result.stdout, "\n"); |
| 302 | 276 | } |
| 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); |
| 310 | 279 | return std.mem.trim(u8, result.stdout, "\n"); |
| 311 | 280 | } |
| 312 | 281 | |
| ... | ... | @@ -574,13 +543,8 @@ pub fn getBlame(alloc: std.mem.Allocator, dir: nfs.Dir, at: CommitId, sub_path: |
| 574 | 543 | const t = tracer.trace(@src(), " {s} -- {s}", .{ at.id, sub_path }); |
| 575 | 544 | defer t.end(); |
| 576 | 545 | |
| 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}); |
| 584 | 548 | return result.stdout; |
| 585 | 549 | } |
| 586 | 550 | |