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 {
518518 },
519519 .action = std.meta.stringToEnum(TreeDiff.Action, action_s).?,
520520 .sub_path = kter.rest(),
521 .adds = 0,
522 .subs = 0,
521523 });
522524 }
523525
......@@ -581,18 +583,24 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {
581583 while (lineiter.next()) |lin| {
582584 if (std.mem.startsWith(u8, lin, "diff --git")) {
583585 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-"));
584589 try diffs.append(.{
585590 .before_path = before_path,
586591 .after_path = after_path,
587 .content = input[start_index..end_index],
592 .content = content,
588593 });
589594 continue :blk;
590595 }
591596 }
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-"));
592600 try diffs.append(.{
593601 .before_path = before_path,
594602 .after_path = after_path,
595 .content = input[start_index..],
603 .content = content,
596604 });
597605 break :blk;
598606 }
......@@ -612,6 +620,8 @@ pub const TreeDiff = struct {
612620 after: State,
613621 action: Action,
614622 sub_path: string,
623 adds: u16,
624 subs: u16,
615625 };
616626
617627 pub const State = struct {