| ... | @@ -6,8 +6,7 @@ const extras = @import("extras"); | ... | @@ -6,8 +6,7 @@ const extras = @import("extras"); |
| 6 | const tracer = @import("tracer"); | 6 | const tracer = @import("tracer"); |
| 7 | const nfs = @import("nfs"); | 7 | const nfs = @import("nfs"); |
| 8 | | 8 | |
| 9 | // 40 is length of sha1 hash | 9 | pub const Id = []const u8; |
| 10 | pub const Id = *const [40]u8; | | |
| 11 | | 10 | |
| 12 | pub const TreeId = struct { | 11 | pub const TreeId = struct { |
| 13 | id: Id, | 12 | id: Id, |
| ... | @@ -96,9 +95,10 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: nfs.Dir) !?CommitId { | ... | @@ -96,9 +95,10 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: nfs.Dir) !?CommitId { |
| 96 | return ensureObjId(CommitId, h); | 95 | return ensureObjId(CommitId, h); |
| 97 | } | 96 | } |
| 98 | | 97 | |
| | 98 | // 40 is length of sha1 hash |
| 99 | pub fn ensureObjId(comptime T: type, input: string) T { | 99 | pub fn ensureObjId(comptime T: type, input: string) T { |
| 100 | extras.assertLog(input.len == 40, "ensureObjId: {s}", .{input}); | 100 | extras.assertLog(input.len == 40, "ensureObjId: {s}", .{input}); |
| 101 | return .{ .id = input[0..40] }; | 101 | return .{ .id = input }; |
| 102 | } | 102 | } |
| 103 | | 103 | |
| 104 | // TODO make this inspect .git/objects | 104 | // TODO make this inspect .git/objects |
| ... | @@ -450,7 +450,7 @@ pub fn getTreeDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, p | ... | @@ -450,7 +450,7 @@ pub fn getTreeDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, p |
| 450 | .cwd_dir = dir.to_std(), | 450 | .cwd_dir = dir.to_std(), |
| 451 | // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1 | 451 | // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1 |
| 452 | // result of `printf | git hash-object -t tree --stdin` | 452 | // result of `printf | git hash-object -t tree --stdin` |
| 453 | .argv = &.{ "git", "diff-tree", "-p", "--raw", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id }, | 453 | .argv = &.{ "git", "diff-tree", "-p", "--raw", "--full-index", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id }, |
| 454 | .max_output_bytes = 1024 * 1024 * 1024, | 454 | .max_output_bytes = 1024 * 1024 * 1024, |
| 455 | }); | 455 | }); |
| 456 | std.debug.assert(result.term == .Exited and result.term.Exited == 0); | 456 | std.debug.assert(result.term == .Exited and result.term.Exited == 0); |
| ... | @@ -459,7 +459,7 @@ pub fn getTreeDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, p | ... | @@ -459,7 +459,7 @@ pub fn getTreeDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, p |
| 459 | const result = try std.process.Child.run(.{ | 459 | const result = try std.process.Child.run(.{ |
| 460 | .allocator = alloc, | 460 | .allocator = alloc, |
| 461 | .cwd_dir = dir.to_std(), | 461 | .cwd_dir = dir.to_std(), |
| 462 | .argv = &.{ "git", "diff-tree", "-p", "--raw", parentid.?.id, commitid.id }, | 462 | .argv = &.{ "git", "diff-tree", "-p", "--raw", "--full-index", parentid.?.id, commitid.id }, |
| 463 | .max_output_bytes = 1024 * 1024 * 1024, | 463 | .max_output_bytes = 1024 * 1024 * 1024, |
| 464 | }); | 464 | }); |
| 465 | std.debug.assert(result.term == .Exited and result.term.Exited == 0); | 465 | std.debug.assert(result.term == .Exited and result.term.Exited == 0); |
| ... | @@ -478,7 +478,7 @@ pub fn getTreeDiffPath(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitI | ... | @@ -478,7 +478,7 @@ pub fn getTreeDiffPath(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitI |
| 478 | .cwd_dir = dir.to_std(), | 478 | .cwd_dir = dir.to_std(), |
| 479 | // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1 | 479 | // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1 |
| 480 | // result of `printf | git hash-object -t tree --stdin` | 480 | // result of `printf | git hash-object -t tree --stdin` |
| 481 | .argv = &.{ "git", "diff-tree", "-p", "--raw", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id, "--", path }, | 481 | .argv = &.{ "git", "diff-tree", "-p", "--raw", "--full-index", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id, "--", path }, |
| 482 | .max_output_bytes = 1024 * 1024 * 1024, | 482 | .max_output_bytes = 1024 * 1024 * 1024, |
| 483 | }); | 483 | }); |
| 484 | std.debug.assert(result.term == .Exited and result.term.Exited == 0); | 484 | std.debug.assert(result.term == .Exited and result.term.Exited == 0); |
| ... | @@ -487,7 +487,7 @@ pub fn getTreeDiffPath(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitI | ... | @@ -487,7 +487,7 @@ pub fn getTreeDiffPath(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitI |
| 487 | const result = try std.process.Child.run(.{ | 487 | const result = try std.process.Child.run(.{ |
| 488 | .allocator = alloc, | 488 | .allocator = alloc, |
| 489 | .cwd_dir = dir.to_std(), | 489 | .cwd_dir = dir.to_std(), |
| 490 | .argv = &.{ "git", "diff-tree", "-p", "--raw", parentid.?.id, commitid.id, "--", path }, | 490 | .argv = &.{ "git", "diff-tree", "-p", "--raw", "--full-index", parentid.?.id, commitid.id, "--", path }, |
| 491 | .max_output_bytes = 1024 * 1024 * 1024, | 491 | .max_output_bytes = 1024 * 1024 * 1024, |
| 492 | }); | 492 | }); |
| 493 | std.debug.assert(result.term == .Exited and result.term.Exited == 0); | 493 | std.debug.assert(result.term == .Exited and result.term.Exited == 0); |
| ... | @@ -602,22 +602,9 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff { | ... | @@ -602,22 +602,9 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff { |
| 602 | }, | 602 | }, |
| 603 | .action = std.meta.stringToEnum(TreeDiff.Action, action_s).?, | 603 | .action = std.meta.stringToEnum(TreeDiff.Action, action_s).?, |
| 604 | .sub_path = kter.rest(), | 604 | .sub_path = kter.rest(), |
| 605 | .adds = 0, | | |
| 606 | .subs = 0, | | |
| 607 | }); | 605 | }); |
| 608 | } | 606 | } |
| 609 | | 607 | |
| 610 | const S = struct { | | |
| 611 | fn eql(comptime a: u8) fn (u8) bool { | | |
| 612 | const SS = struct { | | |
| 613 | fn actual(b: u8) bool { | | |
| 614 | return a == b; | | |
| 615 | } | | |
| 616 | }; | | |
| 617 | return SS.actual; | | |
| 618 | } | | |
| 619 | }; | | |
| 620 | | | |
| 621 | // diff --git a/notes/all_packages.txt b/notes/all_packages.txt | 608 | // diff --git a/notes/all_packages.txt b/notes/all_packages.txt |
| 622 | // index c06b41d..e8f91cf 100644 | 609 | // index c06b41d..e8f91cf 100644 |
| 623 | // --- a/notes/all_packages.txt | 610 | // --- a/notes/all_packages.txt |
| ... | @@ -630,10 +617,17 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff { | ... | @@ -630,10 +617,17 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff { |
| 630 | blk: while (true) { | 617 | blk: while (true) { |
| 631 | const first_line = lineiter.next().?; | 618 | const first_line = lineiter.next().?; |
| 632 | std.debug.assert(std.mem.startsWith(u8, first_line, "diff --git")); | 619 | std.debug.assert(std.mem.startsWith(u8, first_line, "diff --git")); |
| 633 | const i = diffs.items.len; | 620 | var i = diffs.items.len; |
| 634 | try diffs.append(.{ .before_path = overview.items[i].sub_path, .after_path = overview.items[i].sub_path, .content = "" }); | 621 | for (overview.items[0..i]) |o| i -= @intFromBool(o.action == .T); |
| 635 | if (extras.matchesAll(u8, overview.items[i].before.blob.id, S.eql('0'))) diffs.items[i].before_path = "/dev/null"; | 622 | try diffs.append(.{ |
| 636 | if (extras.matchesAll(u8, overview.items[i].after.blob.id, S.eql('0'))) diffs.items[i].after_path = "/dev/null"; | 623 | .index = .{ "", "" }, |
| | 624 | .before_path = overview.items[i].sub_path, |
| | 625 | .after_path = overview.items[i].sub_path, |
| | 626 | .subs = 0, |
| | 627 | .adds = 0, |
| | 628 | .content = "", |
| | 629 | }); |
| | 630 | const diff = &diffs.items[diffs.items.len - 1]; |
| 637 | | 631 | |
| 638 | while (true) { | 632 | while (true) { |
| 639 | if (lineiter.index.? >= input.len) { | 633 | if (lineiter.index.? >= input.len) { |
| ... | @@ -641,6 +635,13 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff { | ... | @@ -641,6 +635,13 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff { |
| 641 | } | 635 | } |
| 642 | if (lineiter.peek()) |lin| { | 636 | if (lineiter.peek()) |lin| { |
| 643 | if (std.mem.startsWith(u8, lin, "index")) { | 637 | if (std.mem.startsWith(u8, lin, "index")) { |
| | 638 | const index = lin[6..]; |
| | 639 | var iiter = std.mem.splitSequence(u8, index, ".."); |
| | 640 | diff.index[0] = iiter.next().?; |
| | 641 | diff.index[1] = iiter.next().?; |
| | 642 | std.debug.assert(iiter.next() == null); |
| | 643 | if (std.mem.indexOfScalar(u8, diff.index[1], ' ')) |j| diff.index[1] = diff.index[1][0..j]; |
| | 644 | |
| 644 | lineiter.index.? += lin.len + 1; | 645 | lineiter.index.? += lin.len + 1; |
| 645 | break; | 646 | break; |
| 646 | } | 647 | } |
| ... | @@ -676,10 +677,12 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff { | ... | @@ -676,10 +677,12 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff { |
| 676 | } | 677 | } |
| 677 | if (lineiter.peek()) |lin| { | 678 | if (lineiter.peek()) |lin| { |
| 678 | if (std.mem.startsWith(u8, lin, "--- ")) { | 679 | if (std.mem.startsWith(u8, lin, "--- ")) { |
| | 680 | diff.before_path = extras.trimPrefix(lin[4..], "a/"); |
| 679 | lineiter.index.? += lin.len + 1; | 681 | lineiter.index.? += lin.len + 1; |
| 680 | continue; | 682 | continue; |
| 681 | } | 683 | } |
| 682 | if (std.mem.startsWith(u8, lin, "+++ ")) { | 684 | if (std.mem.startsWith(u8, lin, "+++ ")) { |
| | 685 | diff.after_path = extras.trimPrefix(lin[4..], "b/"); |
| 683 | lineiter.index.? += lin.len + 1; | 686 | lineiter.index.? += lin.len + 1; |
| 684 | continue; | 687 | continue; |
| 685 | } | 688 | } |
| ... | @@ -701,7 +704,7 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff { | ... | @@ -701,7 +704,7 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff { |
| 701 | } | 704 | } |
| 702 | } | 705 | } |
| 703 | if (lineiter.index.? >= input.len) { | 706 | if (lineiter.index.? >= input.len) { |
| 704 | diffs.items[diffs.items.len - 1].content = input[content_start..]; | 707 | diff.content = input[content_start..]; |
| 705 | break :blk; | 708 | break :blk; |
| 706 | } | 709 | } |
| 707 | | 710 | |
| ... | @@ -709,13 +712,19 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff { | ... | @@ -709,13 +712,19 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff { |
| 709 | if (lineiter.peek()) |lin| { | 712 | if (lineiter.peek()) |lin| { |
| 710 | if (std.mem.startsWith(u8, lin, "diff --git")) { | 713 | if (std.mem.startsWith(u8, lin, "diff --git")) { |
| 711 | const content_end = lineiter.index.? - 1; | 714 | const content_end = lineiter.index.? - 1; |
| 712 | diffs.items[diffs.items.len - 1].content = input[content_start..content_end]; | 715 | diff.content = input[content_start..content_end]; |
| 713 | continue :blk; | 716 | continue :blk; |
| 714 | } | 717 | } |
| | 718 | if (lin[0] == '-') { |
| | 719 | diff.subs += 1; |
| | 720 | } |
| | 721 | if (lin[0] == '+') { |
| | 722 | diff.adds += 1; |
| | 723 | } |
| 715 | lineiter.index.? += lin.len + 1; | 724 | lineiter.index.? += lin.len + 1; |
| 716 | | 725 | |
| 717 | if (lineiter.index.? >= input.len) { | 726 | if (lineiter.index.? >= input.len) { |
| 718 | diffs.items[diffs.items.len - 1].content = input[content_start..]; | 727 | diff.content = input[content_start..]; |
| 719 | break :blk; | 728 | break :blk; |
| 720 | } | 729 | } |
| 721 | } | 730 | } |
| ... | @@ -737,8 +746,6 @@ pub const TreeDiff = struct { | ... | @@ -737,8 +746,6 @@ pub const TreeDiff = struct { |
| 737 | after: State, | 746 | after: State, |
| 738 | action: Action, | 747 | action: Action, |
| 739 | sub_path: string, | 748 | sub_path: string, |
| 740 | adds: u32, | | |
| 741 | subs: u32, | | |
| 742 | }; | 749 | }; |
| 743 | | 750 | |
| 744 | pub const State = struct { | 751 | pub const State = struct { |
| ... | @@ -764,8 +771,11 @@ pub const TreeDiff = struct { | ... | @@ -764,8 +771,11 @@ pub const TreeDiff = struct { |
| 764 | }; | 771 | }; |
| 765 | | 772 | |
| 766 | pub const Diff = struct { | 773 | pub const Diff = struct { |
| | 774 | index: [2][]const u8, |
| 767 | before_path: string, | 775 | before_path: string, |
| 768 | after_path: string, | 776 | after_path: string, |
| | 777 | adds: u32, |
| | 778 | subs: u32, |
| 769 | content: string, | 779 | content: string, |
| 770 | }; | 780 | }; |
| 771 | }; | 781 | }; |