| ... | ... | @@ -335,42 +335,54 @@ pub fn parseTreeDiffMeta(input: string) !TreeDiffMeta { |
| 335 | 335 | result.files_changed += 1; |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | | while (lineiter.next()) |lin| { |
| 339 | | std.debug.assert(lin.len > 0); |
| 340 | | switch (lin[0]) { |
| 341 | | // zig fmt: off |
| 342 | | 'd' => continue, // diff --git a/src/Sema.zig b/src/Sema.zig |
| 343 | | // deleted file mode 100644 |
| 344 | | 'n' => continue, // new file mode 100644 |
| 345 | | 'i' => continue, // index 327ff3800..df199be97 100644 |
| 346 | | '@' => continue, // @@ -24629,10 +24634,11 @@ |
| 347 | | ' ' => continue, |
| 348 | | '+' => result.lines_added += 1, |
| 349 | | '-' => result.lines_removed += 1, |
| 350 | | '\\' => continue, // \ No newline at end of file |
| 351 | | 'B' => { |
| 352 | | // Binary files a/stage1/zig1.wasm and b/stage1/zig1.wasm differ |
| 353 | | result.lines_added += 1; |
| 354 | | result.lines_removed += 1; |
| 355 | | }, |
| 356 | | else => { |
| 357 | | std.log.err("{s}", .{lin}); |
| 358 | | std.log.err("{s}", .{input}); |
| 359 | | @panic("unreachable"); |
| 360 | | }, |
| 361 | | // zig fmt: on |
| 338 | std.debug.assert(std.mem.startsWith(u8, lineiter.next().?, "diff --git")); |
| 339 | while (true) { |
| 340 | while (lineiter.next()) |lin| { |
| 341 | if (std.mem.startsWith(u8, lin, "index")) break; |
| 342 | if (std.mem.startsWith(u8, lin, "new file mode")) continue; |
| 343 | if (std.mem.startsWith(u8, lin, "deleted file mode")) continue; |
| 344 | |
| 345 | std.log.err("{s}", .{lin}); |
| 346 | unreachable; |
| 347 | } |
| 348 | if (lineiter.peek() == null) break; // handle empty file being last or being at the end |
| 349 | |
| 350 | if (std.mem.startsWith(u8, lineiter.peek().?, "Binary files")) { |
| 351 | _ = lineiter.next().?; |
| 352 | result.lines_added += 1; |
| 353 | result.lines_removed += 1; |
| 354 | if (lineiter.peek() == null) break; // handle binary file being last |
| 355 | std.debug.assert(std.mem.startsWith(u8, lineiter.next().?, "diff --git")); |
| 356 | continue; |
| 362 | 357 | } |
| 363 | | } |
| 364 | 358 | |
| 365 | | // Every affected file in the diff has a preamble like below that we don't want to double count. |
| 366 | | // |
| 367 | | // diff --git a/notes/all_packages.txt b/notes/all_packages.txt |
| 368 | | // index c06b41d..e8f91cf 100644 |
| 369 | | // --- a/notes/all_packages.txt |
| 370 | | // +++ b/notes/all_packages.txt |
| 371 | | // @@ -89,3 +89,4 @@ freedesktop/xorg/libsm |
| 372 | | result.lines_added -= result.files_changed; |
| 373 | | result.lines_removed -= result.files_changed; |
| 359 | if (std.mem.startsWith(u8, lineiter.peek().?, "diff --git")) { // handle empty file being in the middle |
| 360 | std.debug.assert(std.mem.startsWith(u8, lineiter.next().?, "diff --git")); |
| 361 | continue; |
| 362 | } |
| 363 | |
| 364 | // Every affected text file in the diff has a preamble like below |
| 365 | // |
| 366 | // diff --git a/notes/all_packages.txt b/notes/all_packages.txt |
| 367 | // index c06b41d..e8f91cf 100644 |
| 368 | // --- a/notes/all_packages.txt |
| 369 | // +++ b/notes/all_packages.txt |
| 370 | std.debug.assert(std.mem.startsWith(u8, lineiter.next().?, "---")); |
| 371 | std.debug.assert(std.mem.startsWith(u8, lineiter.next().?, "+++")); |
| 372 | |
| 373 | while (lineiter.next()) |lin| { |
| 374 | if (std.mem.startsWith(u8, lin, "diff --git")) break; |
| 375 | switch (lin[0]) { |
| 376 | '@' => continue, // @@ -89,3 +89,4 @@ freedesktop/xorg/libsm |
| 377 | ' ' => continue, |
| 378 | '+' => result.lines_added += 1, |
| 379 | '-' => result.lines_removed += 1, |
| 380 | '\\' => continue, // \ No newline at end of file |
| 381 | else => @panic(lin), |
| 382 | } |
| 383 | } |
| 384 | if (lineiter.peek() == null) break; // handle being at the end |
| 385 | } |
| 374 | 386 | |
| 375 | 387 | return result; |
| 376 | 388 | } |
| ... | ... | @@ -435,7 +447,15 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff { |
| 435 | 447 | unreachable; |
| 436 | 448 | } |
| 437 | 449 | |
| 438 | | const before_path_raw = lineiter.next().?; |
| 450 | const before_path_raw = lineiter.next() orelse { |
| 451 | // empty file diff has nothing after 'index' line and this branch handles when its the last item |
| 452 | try diffs.append(.{ |
| 453 | .before_path = overview.items[diffs.items.len].sub_path, |
| 454 | .after_path = overview.items[diffs.items.len].sub_path, |
| 455 | .content = "", |
| 456 | }); |
| 457 | break; |
| 458 | }; |
| 439 | 459 | if (std.mem.startsWith(u8, before_path_raw, "Binary files")) { |
| 440 | 460 | try diffs.append(.{ |
| 441 | 461 | .before_path = overview.items[diffs.items.len].sub_path, |
| ... | ... | @@ -443,6 +463,16 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff { |
| 443 | 463 | .content = before_path_raw, |
| 444 | 464 | }); |
| 445 | 465 | _ = lineiter.index orelse break :blk; |
| 466 | std.debug.assert(std.mem.startsWith(u8, lineiter.next().?, "diff --git")); |
| 467 | continue :blk; |
| 468 | } |
| 469 | if (std.mem.startsWith(u8, before_path_raw, "diff --git")) { |
| 470 | // empty file in the middle, no diff |
| 471 | try diffs.append(.{ |
| 472 | .before_path = overview.items[diffs.items.len].sub_path, |
| 473 | .after_path = overview.items[diffs.items.len].sub_path, |
| 474 | .content = "", |
| 475 | }); |
| 446 | 476 | continue :blk; |
| 447 | 477 | } |
| 448 | 478 | const before_path = extras.trimPrefixEnsure(before_path_raw, "--- a/") orelse extras.trimPrefixEnsure(before_path_raw, "--- ") orelse @panic(before_path_raw); |