| ... | @@ -770,7 +770,7 @@ pub const TreeDiff = struct { | ... | @@ -770,7 +770,7 @@ pub const TreeDiff = struct { |
| 770 | }; | 770 | }; |
| 771 | }; | 771 | }; |
| 772 | | 772 | |
| 773 | pub fn getBranches(alloc: std.mem.Allocator, dir: nfs.Dir) ![]const Ref { | 773 | pub fn getBranches(alloc: std.mem.Allocator, dir: nfs.Dir) ![]Ref { |
| 774 | const t = tracer.trace(@src(), "", .{}); | 774 | const t = tracer.trace(@src(), "", .{}); |
| 775 | defer t.end(); | 775 | defer t.end(); |
| 776 | | 776 | |
| ... | @@ -788,15 +788,14 @@ pub fn getBranches(alloc: std.mem.Allocator, dir: nfs.Dir) ![]const Ref { | ... | @@ -788,15 +788,14 @@ pub fn getBranches(alloc: std.mem.Allocator, dir: nfs.Dir) ![]const Ref { |
| 788 | while (iter.next()) |line| { | 788 | while (iter.next()) |line| { |
| 789 | var jter = std.mem.splitScalar(u8, line, ' '); | 789 | var jter = std.mem.splitScalar(u8, line, ' '); |
| 790 | try list.append(Ref{ | 790 | try list.append(Ref{ |
| 791 | .commit = ensureObjId(CommitId, jter.next().?), | 791 | .oid = ensureObjId(CommitId, jter.next().?).id, |
| 792 | .label = extras.trimPrefixEnsure(jter.rest(), "refs/heads/").?, | 792 | .label = extras.trimPrefixEnsure(jter.rest(), "refs/heads/").?, |
| 793 | .tag = null, | | |
| 794 | }); | 793 | }); |
| 795 | } | 794 | } |
| 796 | return list.toOwnedSlice(); | 795 | return list.toOwnedSlice(); |
| 797 | } | 796 | } |
| 798 | | 797 | |
| 799 | pub fn getTags(alloc: std.mem.Allocator, dir: nfs.Dir) ![]const Ref { | 798 | pub fn getTags(alloc: std.mem.Allocator, dir: nfs.Dir) ![]Ref { |
| 800 | const t = tracer.trace(@src(), "", .{}); | 799 | const t = tracer.trace(@src(), "", .{}); |
| 801 | defer t.end(); | 800 | defer t.end(); |
| 802 | | 801 | |
| ... | @@ -807,7 +806,7 @@ pub fn getTags(alloc: std.mem.Allocator, dir: nfs.Dir) ![]const Ref { | ... | @@ -807,7 +806,7 @@ pub fn getTags(alloc: std.mem.Allocator, dir: nfs.Dir) ![]const Ref { |
| 807 | const result = try std.process.Child.run(.{ | 806 | const result = try std.process.Child.run(.{ |
| 808 | .allocator = alloc, | 807 | .allocator = alloc, |
| 809 | .cwd_dir = dir.to_std(), | 808 | .cwd_dir = dir.to_std(), |
| 810 | .argv = &.{ "git", "show-ref", "--tags", "--dereference" }, | 809 | .argv = &.{ "git", "show-ref", "--tags" }, |
| 811 | .max_output_bytes = 1024 * 1024 * 1024, | 810 | .max_output_bytes = 1024 * 1024 * 1024, |
| 812 | }); | 811 | }); |
| 813 | if (result.term == .Exited and result.term.Exited == 1) return &.{}; // show-ref exits 1 when there are no tags | 812 | if (result.term == .Exited and result.term.Exited == 1) return &.{}; // show-ref exits 1 when there are no tags |
| ... | @@ -820,43 +819,18 @@ pub fn getTags(alloc: std.mem.Allocator, dir: nfs.Dir) ![]const Ref { | ... | @@ -820,43 +819,18 @@ pub fn getTags(alloc: std.mem.Allocator, dir: nfs.Dir) ![]const Ref { |
| 820 | var jter = std.mem.splitScalar(u8, line, ' '); | 819 | var jter = std.mem.splitScalar(u8, line, ' '); |
| 821 | const id = ensureObjId(CommitId, jter.next().?).id; | 820 | const id = ensureObjId(CommitId, jter.next().?).id; |
| 822 | const label = extras.trimPrefixEnsure(jter.rest(), "refs/tags/").?; | 821 | const label = extras.trimPrefixEnsure(jter.rest(), "refs/tags/").?; |
| 823 | extras.assertLog(!std.mem.endsWith(u8, label, "^{}"), "{s}", .{label}); | 822 | |
| 824 | | 823 | try list.append(Ref{ |
| 825 | switch (try getType(alloc, dir, id)) { | 824 | .oid = id, |
| 826 | .tree => continue, | 825 | .label = label, |
| 827 | .blob => unreachable, | 826 | }); |
| 828 | .commit => { | | |
| 829 | try list.append(Ref{ | | |
| 830 | .label = label, | | |
| 831 | .commit = ensureObjId(CommitId, id), | | |
| 832 | .tag = null, | | |
| 833 | }); | | |
| 834 | }, | | |
| 835 | .tag => { | | |
| 836 | const derefline = iter.next().?; | | |
| 837 | var kter = std.mem.splitScalar(u8, derefline, ' '); | | |
| 838 | const id2 = ensureObjId(CommitId, kter.next().?).id; | | |
| 839 | const label2 = extras.trimPrefixEnsure(kter.rest(), "refs/tags/").?; | | |
| 840 | extras.assertLog(std.mem.endsWith(u8, label2, "^{}"), "{s}", .{label2}); | | |
| 841 | std.debug.assert(std.mem.eql(u8, label, extras.trimSuffixEnsure(label2, "^{}").?)); | | |
| 842 | // extras.assertLog(try isType(alloc, dir, id2, .commit), id2); // linux kernel has a single tag that points at a tree | | |
| 843 | if (!try isType(alloc, dir, id2, .commit)) continue; | | |
| 844 | | | |
| 845 | try list.append(Ref{ | | |
| 846 | .label = label, | | |
| 847 | .commit = ensureObjId(CommitId, id2), | | |
| 848 | .tag = ensureObjId(TagId, id), | | |
| 849 | }); | | |
| 850 | }, | | |
| 851 | } | | |
| 852 | } | 827 | } |
| 853 | return list.toOwnedSlice(); | 828 | return list.toOwnedSlice(); |
| 854 | } | 829 | } |
| 855 | | 830 | |
| 856 | pub const Ref = struct { | 831 | pub const Ref = struct { |
| | 832 | oid: Id, |
| 857 | label: string, | 833 | label: string, |
| 858 | commit: CommitId, | | |
| 859 | tag: ?TagId, | | |
| 860 | }; | 834 | }; |
| 861 | | 835 | |
| 862 | // TODO make this inspect .git/objects | 836 | // TODO make this inspect .git/objects |