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 {
10501050 return (try r.getBlob(.{ .id = id }, cache_behavior)).?;
10511051 }
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 } {
10541054 const t = tracer.trace(@src(), " {s}", .{id.id});
10551055 defer t.end();
10561056
10571057 if (r.commits.getPtr(id.id)) |val| {
10581058 return .{ id, val.* };
10591059 }
1060 if (try r.getObject(id.id, .cache)) |obj| {
1060 if (try r.getObject(id.id, cache_behavior)) |obj| {
10611061 if (obj.type == .commit) {
1062 errdefer if (cache_behavior == .no_cache) r.gpa.free(obj.content);
10621063 const commit = try parseCommit(r.gpa, obj.content);
10631064 try r.commits.put(r.gpa, id.id, commit);
10641065 return .{ id, commit };
10651066 }
1067 if (cache_behavior == .no_cache) r.gpa.free(obj.content);
10661068 }
10671069 return null;
10681070 }
10691071
1070 pub fn getCommitA(r: *Repository, id: Id) !Commit {
1071 return (try r.getCommit(.{ .id = id })).?.@"1";
1072 pub fn getCommitA(r: *Repository, id: Id, cache_behavior: CacheBehavior) !Commit {
1073 return (try r.getCommit(.{ .id = id }, cache_behavior)).?.@"1";
10721074 }
10731075
10741076 pub fn getTree(r: *Repository, id: TreeId, cache_behavior: CacheBehavior) !?struct { TreeId, Tree } {
......@@ -1231,7 +1233,7 @@ pub const Repository = struct {
12311233
12321234 // const start = time.milliTimestamp();
12331235
1234 const base = try r.getCommitA(base_oid.id);
1236 const base = try r.getCommitA(base_oid.id, .cache);
12351237 const base_tree_id = (try traverseTo(r, base.tree, dir_path)).?;
12361238 const base_tree = try r.getTreeA(base_tree_id.id, .cache);
12371239 const total = base_tree.children.len;
......@@ -1251,7 +1253,7 @@ pub const Repository = struct {
12511253 var tree_id = base_tree_id;
12521254 while (true) {
12531255 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)).?;
12551257 searched += 1;
12561258 defer commit_id_prev = commit_id;
12571259 const new_tree_id = try traverseTo(r, commit.tree, dir_path) orelse {
......@@ -1497,12 +1499,12 @@ pub const Repository = struct {
14971499 }
14981500 };
14991501 if (commitid_from == null) {
1500 const commit = try r.getCommitA(commitid_to.id);
1502 const commit = try r.getCommitA(commitid_to.id, .cache);
15011503 try A.dir(r, writable, commit.tree.id, null, 0);
15021504 return;
15031505 }
1504 const before_commit = try r.getCommitA(commitid_from.?.id);
1505 const after_commit = try r.getCommitA(commitid_to.id);
1506 const before_commit = try r.getCommitA(commitid_from.?.id, .cache);
1507 const after_commit = try r.getCommitA(commitid_to.id, .cache);
15061508 try M.dir(r, writable, before_commit.tree.id, after_commit.tree.id, null);
15071509 }
15081510