authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-07-02 16:28:47 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-07-02 16:28:47 -07:00
log59d257da1f1526e5e76c00eb17d6b08553772f0b
treea8be22953d160d77e01e3a04bdd55e0e7ad1bab1
parente4c3ea47cec1669dc173f0573160901de690e5e7
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

revListAll: handle mode changes


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

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