| ... | @@ -277,3 +277,67 @@ pub const Tree = struct { | ... | @@ -277,3 +277,67 @@ pub const Tree = struct { |
| 277 | }; | 277 | }; |
| 278 | }; | 278 | }; |
| 279 | }; | 279 | }; |
| | 280 | |
| | 281 | // TODO make this inspect .git manually |
| | 282 | // TODO make this return a Reader when we implement it ourselves |
| | 283 | pub fn getTreeDiff(alloc: std.mem.Allocator, dir: std.fs.Dir, commitid: CommitId, parentid: CommitId) !string { |
| | 284 | const result = try std.ChildProcess.exec(.{ |
| | 285 | .allocator = alloc, |
| | 286 | .cwd_dir = dir, |
| | 287 | .argv = &.{ "git", "diff-tree", "-p", "--raw", commitid.id, parentid.id }, |
| | 288 | .max_output_bytes = 1024 * 1024 * 1024, |
| | 289 | }); |
| | 290 | return std.mem.trim(u8, result.stdout, "\n"); |
| | 291 | } |
| | 292 | |
| | 293 | pub fn parseTreeDiffMeta(input: string) !TreeDiffMeta { |
| | 294 | var result = std.mem.zeroes(TreeDiffMeta); |
| | 295 | var lineiter = std.mem.split(u8, input, "\n"); |
| | 296 | |
| | 297 | while (lineiter.next()) |lin| { |
| | 298 | if (lin.len == 0) break; |
| | 299 | std.debug.assert(lin[0] == ':'); |
| | 300 | result.files_changed += 1; |
| | 301 | } |
| | 302 | |
| | 303 | while (lineiter.next()) |lin| { |
| | 304 | std.debug.assert(lin.len > 0); |
| | 305 | switch (lin[0]) { |
| | 306 | // zig fmt: off |
| | 307 | 'd' => continue, // diff --git a/src/Sema.zig b/src/Sema.zig |
| | 308 | // deleted file mode 100644 |
| | 309 | 'n' => continue, // new file mode 100644 |
| | 310 | 'B' => continue, // Binary files a/stage1/zig1.wasm and b/stage1/zig1.wasm differ |
| | 311 | 'i' => continue, // index 327ff3800..df199be97 100644 |
| | 312 | '@' => continue, // @@ -24629,10 +24634,11 @@ |
| | 313 | ' ' => continue, |
| | 314 | '+' => result.lines_added += 1, |
| | 315 | '-' => result.lines_removed += 1, |
| | 316 | '\\' => continue, // \ No newline at end of file |
| | 317 | else => { |
| | 318 | std.log.err("{s}", .{lin}); |
| | 319 | std.log.err("{s}", .{input}); |
| | 320 | @panic("unreachable"); |
| | 321 | }, |
| | 322 | // zig fmt: on |
| | 323 | } |
| | 324 | } |
| | 325 | |
| | 326 | // Every affected file in the diff has a preamble like below that we don't want to double count. |
| | 327 | // |
| | 328 | // diff --git a/notes/all_packages.txt b/notes/all_packages.txt |
| | 329 | // index c06b41d..e8f91cf 100644 |
| | 330 | // --- a/notes/all_packages.txt |
| | 331 | // +++ b/notes/all_packages.txt |
| | 332 | // @@ -89,3 +89,4 @@ freedesktop/xorg/libsm |
| | 333 | result.lines_added -= result.files_changed; |
| | 334 | result.lines_removed -= result.files_changed; |
| | 335 | |
| | 336 | return result; |
| | 337 | } |
| | 338 | |
| | 339 | pub const TreeDiffMeta = struct { |
| | 340 | files_changed: u16, |
| | 341 | lines_added: u32, |
| | 342 | lines_removed: u32, |
| | 343 | }; |