authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-04-14 20:13:49 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-04-14 20:13:49 -07:00
log103f4e419c35b88f802bb8234ece1c0a9aa40c03
treee6236878f0889688a41f3a7adc7195a839382fc4
parent4931e5f829b12ebdabb855f5a922d749a5d3ed42

add adds+subs fields to TreeDiff.StateLine


1 files changed, 12 insertions(+), 2 deletions(-)

git.zig+12-2
...@@ -518,6 +518,8 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {...@@ -518,6 +518,8 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {
518 },518 },
519 .action = std.meta.stringToEnum(TreeDiff.Action, action_s).?,519 .action = std.meta.stringToEnum(TreeDiff.Action, action_s).?,
520 .sub_path = kter.rest(),520 .sub_path = kter.rest(),
521 .adds = 0,
522 .subs = 0,
521 });523 });
522 }524 }
523525
...@@ -581,18 +583,24 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {...@@ -581,18 +583,24 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {
581 while (lineiter.next()) |lin| {583 while (lineiter.next()) |lin| {
582 if (std.mem.startsWith(u8, lin, "diff --git")) {584 if (std.mem.startsWith(u8, lin, "diff --git")) {
583 const end_index = lineiter.index.? - lin.len - 2;585 const end_index = lineiter.index.? - lin.len - 2;
586 const content = input[start_index..end_index];
587 overview.items[diffs.items.len].adds = @intCast(std.mem.count(u8, content, "\n+"));
588 overview.items[diffs.items.len].subs = @intCast(std.mem.count(u8, content, "\n-"));
584 try diffs.append(.{589 try diffs.append(.{
585 .before_path = before_path,590 .before_path = before_path,
586 .after_path = after_path,591 .after_path = after_path,
587 .content = input[start_index..end_index],592 .content = content,
588 });593 });
589 continue :blk;594 continue :blk;
590 }595 }
591 }596 }
597 const content = input[start_index..];
598 overview.items[diffs.items.len].adds = @intCast(std.mem.count(u8, content, "\n+"));
599 overview.items[diffs.items.len].subs = @intCast(std.mem.count(u8, content, "\n-"));
592 try diffs.append(.{600 try diffs.append(.{
593 .before_path = before_path,601 .before_path = before_path,
594 .after_path = after_path,602 .after_path = after_path,
595 .content = input[start_index..],603 .content = content,
596 });604 });
597 break :blk;605 break :blk;
598 }606 }
...@@ -612,6 +620,8 @@ pub const TreeDiff = struct {...@@ -612,6 +620,8 @@ pub const TreeDiff = struct {
612 after: State,620 after: State,
613 action: Action,621 action: Action,
614 sub_path: string,622 sub_path: string,
623 adds: u16,
624 subs: u16,
615 };625 };
616626
617 pub const State = struct {627 pub const State = struct {