authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-24 16:33:17 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-24 16:33:17 -07:00
log11d5f86c0bc824f147fdeeea22dda03d751abb83
tree4550631c2e3a5b0afefdc5ee4ccfca162986693b
parent565f5b3eeb02a756be48690138ad8e83c06ff186
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

getCommit: add CacheBehavior param


1 files changed, 11 insertions(+), 9 deletions(-)

git.zig+11-9
...@@ -1050,25 +1050,27 @@ pub const Repository = struct {...@@ -1050,25 +1050,27 @@ pub const Repository = struct {
1050 return (try r.getBlob(.{ .id = id }, cache_behavior)).?;1050 return (try r.getBlob(.{ .id = id }, cache_behavior)).?;
1051 }1051 }
10521052
1053 pub fn getCommit(r: *Repository, id: CommitId) !?struct { CommitId, Commit } {1053 pub fn getCommit(r: *Repository, id: CommitId, cache_behavior: CacheBehavior) !?struct { CommitId, Commit } {
1054 const t = tracer.trace(@src(), " {s}", .{id.id});1054 const t = tracer.trace(@src(), " {s}", .{id.id});
1055 defer t.end();1055 defer t.end();
10561056
1057 if (r.commits.getPtr(id.id)) |val| {1057 if (r.commits.getPtr(id.id)) |val| {
1058 return .{ id, val.* };1058 return .{ id, val.* };
1059 }1059 }
1060 if (try r.getObject(id.id, .cache)) |obj| {1060 if (try r.getObject(id.id, cache_behavior)) |obj| {
1061 if (obj.type == .commit) {1061 if (obj.type == .commit) {
1062 errdefer if (cache_behavior == .no_cache) r.gpa.free(obj.content);
1062 const commit = try parseCommit(r.gpa, obj.content);1063 const commit = try parseCommit(r.gpa, obj.content);
1063 try r.commits.put(r.gpa, id.id, commit);1064 try r.commits.put(r.gpa, id.id, commit);
1064 return .{ id, commit };1065 return .{ id, commit };
1065 }1066 }
1067 if (cache_behavior == .no_cache) r.gpa.free(obj.content);
1066 }1068 }
1067 return null;1069 return null;
1068 }1070 }
10691071
1070 pub fn getCommitA(r: *Repository, id: Id) !Commit {1072 pub fn getCommitA(r: *Repository, id: Id, cache_behavior: CacheBehavior) !Commit {
1071 return (try r.getCommit(.{ .id = id })).?.@"1";1073 return (try r.getCommit(.{ .id = id }, cache_behavior)).?.@"1";
1072 }1074 }
10731075
1074 pub fn getTree(r: *Repository, id: TreeId, cache_behavior: CacheBehavior) !?struct { TreeId, Tree } {1076 pub fn getTree(r: *Repository, id: TreeId, cache_behavior: CacheBehavior) !?struct { TreeId, Tree } {
...@@ -1231,7 +1233,7 @@ pub const Repository = struct {...@@ -1231,7 +1233,7 @@ pub const Repository = struct {
12311233
1232 // const start = time.milliTimestamp();1234 // const start = time.milliTimestamp();
12331235
1234 const base = try r.getCommitA(base_oid.id);1236 const base = try r.getCommitA(base_oid.id, .cache);
1235 const base_tree_id = (try traverseTo(r, base.tree, dir_path)).?;1237 const base_tree_id = (try traverseTo(r, base.tree, dir_path)).?;
1236 const base_tree = try r.getTreeA(base_tree_id.id, .cache);1238 const base_tree = try r.getTreeA(base_tree_id.id, .cache);
1237 const total = base_tree.children.len;1239 const total = base_tree.children.len;
...@@ -1251,7 +1253,7 @@ pub const Repository = struct {...@@ -1251,7 +1253,7 @@ pub const Repository = struct {
1251 var tree_id = base_tree_id;1253 var tree_id = base_tree_id;
1252 while (true) {1254 while (true) {
1253 if (commit.parents.len == 0) break;1255 if (commit.parents.len == 0) break;
1254 commit_id, commit = (try r.getCommit(commit.parents[0])).?;1256 commit_id, commit = (try r.getCommit(commit.parents[0], .cache)).?;
1255 searched += 1;1257 searched += 1;
1256 defer commit_id_prev = commit_id;1258 defer commit_id_prev = commit_id;
1257 const new_tree_id = try traverseTo(r, commit.tree, dir_path) orelse {1259 const new_tree_id = try traverseTo(r, commit.tree, dir_path) orelse {
...@@ -1497,12 +1499,12 @@ pub const Repository = struct {...@@ -1497,12 +1499,12 @@ pub const Repository = struct {
1497 }1499 }
1498 };1500 };
1499 if (commitid_from == null) {1501 if (commitid_from == null) {
1500 const commit = try r.getCommitA(commitid_to.id);1502 const commit = try r.getCommitA(commitid_to.id, .cache);
1501 try A.dir(r, writable, commit.tree.id, null, 0);1503 try A.dir(r, writable, commit.tree.id, null, 0);
1502 return;1504 return;
1503 }1505 }
1504 const before_commit = try r.getCommitA(commitid_from.?.id);1506 const before_commit = try r.getCommitA(commitid_from.?.id, .cache);
1505 const after_commit = try r.getCommitA(commitid_to.id);1507 const after_commit = try r.getCommitA(commitid_to.id, .cache);
1506 try M.dir(r, writable, before_commit.tree.id, after_commit.tree.id, null);1508 try M.dir(r, writable, before_commit.tree.id, after_commit.tree.id, null);
1507 }1509 }
15081510