authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-14 04:47:01 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-14 04:47:01 -07:00
log48aabfe1b35f06dedf4e1c86cbe338067b873618
tree25e1bb45341f32a2ad31305dc02c74937ce93686
parentf1c193a7b0522bc268e0185b3e2b118ba90d0c95
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

remove parseTreeDiffMeta and merge into parseTreeDiff


1 files changed, 13 insertions(+), 74 deletions(-)

git.zig+13-74
......@@ -517,80 +517,6 @@ pub fn getTreeDiffPath(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitI
517517 return std.mem.trim(u8, result.stdout, "\n");
518518}
519519
520pub fn parseTreeDiffMeta(input: string) !TreeDiffMeta {
521 const t = tracer.trace(@src(), "", .{});
522 defer t.end();
523
524 var result = std.mem.zeroes(TreeDiffMeta);
525 var lineiter = std.mem.splitScalar(u8, input, '\n');
526
527 while (lineiter.next()) |lin| {
528 if (lin.len == 0) break;
529 std.debug.assert(lin[0] == ':');
530 result.files_changed += 1;
531 }
532
533 std.debug.assert(std.mem.startsWith(u8, lineiter.next() orelse return result, "diff --git"));
534 blk: while (true) {
535 while (lineiter.next()) |lin| {
536 if (std.mem.startsWith(u8, lin, "index")) break;
537 if (std.mem.startsWith(u8, lin, "new file mode")) continue;
538 if (std.mem.startsWith(u8, lin, "deleted file mode")) continue;
539 if (std.mem.startsWith(u8, lin, "old mode")) continue;
540 if (std.mem.startsWith(u8, lin, "new mode")) continue;
541 if (std.mem.startsWith(u8, lin, "diff --git")) continue :blk;
542
543 std.log.err("{s}", .{lin});
544 unreachable;
545 }
546 if (lineiter.peek() == null) break; // handle empty file being last or being at the end
547
548 if (std.mem.startsWith(u8, lineiter.peek().?, "Binary files")) {
549 _ = lineiter.next().?;
550 result.lines_added += 1;
551 result.lines_removed += 1;
552 if (lineiter.peek() == null) break; // handle binary file being last
553 std.debug.assert(std.mem.startsWith(u8, lineiter.next().?, "diff --git"));
554 continue;
555 }
556
557 if (std.mem.startsWith(u8, lineiter.peek().?, "diff --git")) { // handle empty file being in the middle
558 std.debug.assert(std.mem.startsWith(u8, lineiter.next().?, "diff --git"));
559 continue;
560 }
561
562 // Every affected text file in the diff has a preamble like below
563 //
564 // diff --git a/notes/all_packages.txt b/notes/all_packages.txt
565 // index c06b41d..e8f91cf 100644
566 // --- a/notes/all_packages.txt
567 // +++ b/notes/all_packages.txt
568 std.debug.assert(std.mem.startsWith(u8, lineiter.next().?, "---"));
569 std.debug.assert(std.mem.startsWith(u8, lineiter.next().?, "+++"));
570
571 while (lineiter.next()) |lin| {
572 if (std.mem.startsWith(u8, lin, "diff --git")) break;
573 switch (lin[0]) {
574 '@' => continue, // @@ -89,3 +89,4 @@ freedesktop/xorg/libsm
575 ' ' => continue,
576 '+' => result.lines_added += 1,
577 '-' => result.lines_removed += 1,
578 '\\' => continue, // \ No newline at end of file
579 else => @panic(lin),
580 }
581 }
582 if (lineiter.peek() == null) break; // handle being at the end
583 }
584
585 return result;
586}
587
588pub const TreeDiffMeta = struct {
589 files_changed: u16,
590 lines_added: u32,
591 lines_removed: u32,
592};
593
594520pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {
595521 const t = tracer.trace(@src(), "", .{});
596522 defer t.end();
......@@ -598,6 +524,7 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {
598524 var lineiter = std.mem.splitScalar(u8, input, '\n');
599525 var overview = std.ArrayList(TreeDiff.StateLine).init(alloc);
600526 var diffs = std.ArrayList(TreeDiff.Diff).init(alloc);
527 var meta = std.mem.zeroes(TreeDiff.Meta);
601528
602529 while (lineiter.next()) |lin| {
603530 if (lin.len == 0) break;
......@@ -626,11 +553,13 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {
626553 .action = std.meta.stringToEnum(TreeDiff.Action, action_s).?,
627554 .sub_path = kter.rest(),
628555 });
556 meta.files_changed += 1;
629557 }
630558 if (lineiter.peek() == null) {
631559 return TreeDiff{
632560 .overview = overview.items,
633561 .diffs = diffs.items,
562 .meta = meta,
634563 };
635564 }
636565
......@@ -747,9 +676,11 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {
747676 }
748677 if (lin[0] == '-') {
749678 diff.subs += 1;
679 meta.lines_removed += 1;
750680 }
751681 if (lin[0] == '+') {
752682 diff.adds += 1;
683 meta.lines_added += 1;
753684 }
754685 lineiter.index.? += lin.len + 1;
755686
......@@ -764,12 +695,14 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {
764695 return TreeDiff{
765696 .overview = overview.items,
766697 .diffs = diffs.items,
698 .meta = meta,
767699 };
768700}
769701
770702pub const TreeDiff = struct {
771703 overview: []const StateLine,
772704 diffs: []const Diff,
705 meta: Meta,
773706
774707 pub const StateLine = struct {
775708 before: State,
......@@ -808,6 +741,12 @@ pub const TreeDiff = struct {
808741 subs: u32,
809742 content: string,
810743 };
744
745 pub const Meta = struct {
746 files_changed: u32,
747 lines_added: u64,
748 lines_removed: u64,
749 };
811750};
812751
813752pub fn getBranches(alloc: std.mem.Allocator, dir: nfs.Dir) ![]const Ref {