authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-26 05:05:22 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-26 05:46:56 -07:00
log142935ded09b5d316fe013c673576b24debaf0bb
tree80064fe1f3d030f934affac6f0c3c9a53fb25864
parentcc1a8c505113b2932f676313dee79b657d2da63f
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

parseTreeDiff: handle mode changes in Diff instead of relying on StateLine


1 files changed, 14 insertions(+), 4 deletions(-)

git.zig+14-4
...@@ -406,11 +406,15 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {...@@ -406,11 +406,15 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {
406 .index = @splat(.{ .id = "0000000000000000000000000000000000000000" }),406 .index = @splat(.{ .id = "0000000000000000000000000000000000000000" }),
407 .before_path = overview.items[i].sub_path,407 .before_path = overview.items[i].sub_path,
408 .after_path = overview.items[i].sub_path,408 .after_path = overview.items[i].sub_path,
409 .before_mode = overview.items[i].before.mode,
410 .after_mode = overview.items[i].after.mode,
409 .subs = 0,411 .subs = 0,
410 .adds = 0,412 .adds = 0,
411 .content = "",413 .content = "",
412 });414 });
413 const diff = &diffs.items[diffs.items.len - 1];415 const diff = &diffs.items[diffs.items.len - 1];
416 if (overview.items[i].action == .T) diff.before_mode = .none;
417 if (overview.items[i].action == .T) diff.after_mode = .none;
414418
415 while (true) {419 while (true) {
416 if (lineiter.index.? >= input.len) {420 if (lineiter.index.? >= input.len) {
...@@ -429,19 +433,23 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {...@@ -429,19 +433,23 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {
429 lineiter.index.? += lin.len + 1;433 lineiter.index.? += lin.len + 1;
430 break;434 break;
431 }435 }
432 if (std.mem.startsWith(u8, lin, "new file mode")) {436 if (extras.trimPrefixEnsure(lin, "new file mode ")) |sl| {
437 diff.after_mode = parseTreeMode(sl) catch unreachable;
433 lineiter.index.? += lin.len + 1;438 lineiter.index.? += lin.len + 1;
434 continue;439 continue;
435 }440 }
436 if (std.mem.startsWith(u8, lin, "deleted file mode")) {441 if (extras.trimPrefixEnsure(lin, "deleted file mode ")) |sl| {
442 diff.before_mode = parseTreeMode(sl) catch unreachable;
437 lineiter.index.? += lin.len + 1;443 lineiter.index.? += lin.len + 1;
438 continue;444 continue;
439 }445 }
440 if (std.mem.startsWith(u8, lin, "old mode")) {446 if (extras.trimPrefixEnsure(lin, "old mode ")) |sl| {
447 diff.before_mode = parseTreeMode(sl) catch unreachable;
441 lineiter.index.? += lin.len + 1;448 lineiter.index.? += lin.len + 1;
442 continue;449 continue;
443 }450 }
444 if (std.mem.startsWith(u8, lin, "new mode")) {451 if (extras.trimPrefixEnsure(lin, "new mode ")) |sl| {
452 diff.after_mode = parseTreeMode(sl) catch unreachable;
445 lineiter.index.? += lin.len + 1;453 lineiter.index.? += lin.len + 1;
446 continue;454 continue;
447 }455 }
...@@ -562,6 +570,8 @@ pub const TreeDiff = struct {...@@ -562,6 +570,8 @@ pub const TreeDiff = struct {
562 index: [2]CommitId,570 index: [2]CommitId,
563 before_path: string,571 before_path: string,
564 after_path: string,572 after_path: string,
573 before_mode: Tree.Object.Mode,
574 after_mode: Tree.Object.Mode,
565 adds: u32,575 adds: u32,
566 subs: u32,576 subs: u32,
567 content: string,577 content: string,