| ... | ... | @@ -1654,13 +1654,14 @@ pub const Repository = struct { |
| 1654 | 1654 | |
| 1655 | 1655 | const base = try r.getCommitA(from.id, .no_cache); |
| 1656 | 1656 | const base_tree = try r.getTreeA(base.tree.id, .no_cache); |
| 1657 | | const base_id, const base_id_parent = (try idFor(r, base_tree, sub_path)).?; |
| 1657 | const base_obj, const base_id_parent = (try idFor(r, base_tree, sub_path)).?; |
| 1658 | 1658 | |
| 1659 | 1659 | var prev_prev_commit: ?*Commit = null; |
| 1660 | 1660 | var prev_commit = base; |
| 1661 | 1661 | var prev_tree = base_id_parent; |
| 1662 | | var prev_id = try r.gpa.dupe(u8, base_id); |
| 1663 | | defer r.gpa.free(prev_id); |
| 1662 | var prev_obj = try r.gpa.create(Tree.Object); |
| 1663 | prev_obj.* = base_obj.*; |
| 1664 | defer r.gpa.destroy(prev_obj); |
| 1664 | 1665 | |
| 1665 | 1666 | while (true) { |
| 1666 | 1667 | if (prev_commit.parents.len == 0) { |
| ... | ... | @@ -1669,11 +1670,11 @@ pub const Repository = struct { |
| 1669 | 1670 | } |
| 1670 | 1671 | const next_commit = try r.getCommitA(prev_commit.parents[0].id, .no_cache); |
| 1671 | 1672 | const next_commit_tree = try r.getTreeA(next_commit.tree.id, .no_cache); |
| 1672 | | const next_id, const next_tree = try idFor(r, next_commit_tree, sub_path) orelse { |
| 1673 | const next_obj, const next_tree = try idFor(r, next_commit_tree, sub_path) orelse { |
| 1673 | 1674 | try list.appendSlice(alloc, prev_prev_commit.?.parents[0].id ++ "\n"); |
| 1674 | 1675 | break; |
| 1675 | 1676 | }; |
| 1676 | | if (std.mem.eql(u8, next_id, prev_id)) { |
| 1677 | if (std.mem.eql(u8, &next_obj.id_bytes, &prev_obj.id_bytes) and next_obj.mode.eql(prev_obj.mode)) { |
| 1677 | 1678 | if (prev_prev_commit) |p| p.destroy(r); |
| 1678 | 1679 | prev_prev_commit = prev_commit; |
| 1679 | 1680 | prev_commit = next_commit; |
| ... | ... | @@ -1685,9 +1686,7 @@ pub const Repository = struct { |
| 1685 | 1686 | prev_prev_commit = prev_commit; |
| 1686 | 1687 | prev_commit = next_commit; |
| 1687 | 1688 | prev_tree = next_tree; |
| 1688 | | |
| 1689 | | r.gpa.free(prev_id); |
| 1690 | | prev_id = try r.gpa.dupe(u8, next_id); |
| 1689 | prev_obj.* = next_obj.*; |
| 1691 | 1690 | continue; |
| 1692 | 1691 | } |
| 1693 | 1692 | |
| ... | ... | @@ -1786,7 +1785,7 @@ pub const Tree = struct { |
| 1786 | 1785 | r.gpa.destroy(t); |
| 1787 | 1786 | } |
| 1788 | 1787 | |
| 1789 | | pub fn get(self: *Tree, name: string) ?Object { |
| 1788 | pub fn get(self: *Tree, name: string) ?*const Object { |
| 1790 | 1789 | // modified std.sort.binarySearch |
| 1791 | 1790 | const i = blk: { |
| 1792 | 1791 | var low: usize = 0; |
| ... | ... | @@ -1813,10 +1812,10 @@ pub const Tree = struct { |
| 1813 | 1812 | } |
| 1814 | 1813 | return null; |
| 1815 | 1814 | }; |
| 1816 | | return self.children[i]; |
| 1815 | return &self.children[i]; |
| 1817 | 1816 | } |
| 1818 | 1817 | |
| 1819 | | pub fn getBlob(self: *Tree, name: string, hint: Object.Type) ?Object { |
| 1818 | pub fn getBlob(self: *Tree, name: string, hint: Object.Type) ?*const Object { |
| 1820 | 1819 | const o = self.get(name, hint) orelse return null; |
| 1821 | 1820 | if (o.id != .blob) return null; |
| 1822 | 1821 | return o; |
| ... | ... | @@ -2150,7 +2149,7 @@ const PathListNode = struct { |
| 2150 | 2149 | }; |
| 2151 | 2150 | |
| 2152 | 2151 | /// Consumes 'tree' and returns a new owned 'Tree' in the tuple. |
| 2153 | | pub fn idFor(r: *Repository, tree: *Tree, sub_path: []const u8) !?struct { Id, *Tree } { |
| 2152 | pub fn idFor(r: *Repository, tree: *Tree, sub_path: []const u8) !?struct { *const Tree.Object, *Tree } { |
| 2154 | 2153 | const s_idx = std.mem.indexOfScalar(u8, sub_path, '/'); |
| 2155 | 2154 | const seg = sub_path[0 .. s_idx orelse sub_path.len]; |
| 2156 | 2155 | const obj = tree.get(seg) orelse { |
| ... | ... | @@ -2164,12 +2163,12 @@ pub fn idFor(r: *Repository, tree: *Tree, sub_path: []const u8) !?struct { Id, * |
| 2164 | 2163 | const new_tree = try r.getTreeA(id.id, .no_cache); |
| 2165 | 2164 | return idFor(r, new_tree, sub_path[s_idx.? + 1 ..]); |
| 2166 | 2165 | }, |
| 2167 | | else => |id| { |
| 2166 | else => { |
| 2168 | 2167 | if (s_idx != null) { |
| 2169 | 2168 | tree.destroy(r); |
| 2170 | 2169 | return null; |
| 2171 | 2170 | } |
| 2172 | | return .{ id.erase(), tree }; |
| 2171 | return .{ obj, tree }; |
| 2173 | 2172 | }, |
| 2174 | 2173 | } |
| 2175 | 2174 | } |