commit 766d34f3045c4e47f4d6a656a38a644d05d7429f
parent 2d7fbd48166c9519ea85d8dd9ec61aae2cebdd7c
Author: Chris Bracken <chris@bracken.jp>
Date: Tue, 17 Feb 2026 18:16:23 +0900
commit: eliminate git_diff struct member
Diffstat:
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/src/git/commit.c b/src/git/commit.c
@@ -29,8 +29,6 @@ struct GitCommit {
size_t addcount;
size_t delcount;
size_t filecount;
-
- git_diff* diff;
};
GitCommit* gitcommit_create(const git_oid* oid, git_repository* repo) {
@@ -94,8 +92,6 @@ GitCommit* gitcommit_create(const git_oid* oid, git_repository* repo) {
git_tree_free(commit_tree);
git_tree_free(parent_tree);
- commit->diff = diff;
-
git_diff_find_options fopts;
if (git_diff_find_options_init(&fopts, GIT_DIFF_FIND_OPTIONS_VERSION)) {
errx(1, "git_diff_find_init_options");
@@ -104,19 +100,19 @@ GitCommit* gitcommit_create(const git_oid* oid, git_repository* repo) {
/* find renames and copies, exact matches (no heuristic) for renames. */
fopts.flags |= GIT_DIFF_FIND_RENAMES | GIT_DIFF_FIND_COPIES |
GIT_DIFF_FIND_EXACT_MATCH_ONLY;
- if (git_diff_find_similar(commit->diff, &fopts)) {
+ if (git_diff_find_similar(diff, &fopts)) {
errx(1, "git_diff_find_similar");
}
// Add deltas.
commit->addcount = 0;
commit->delcount = 0;
- size_t deltas_len = git_diff_num_deltas(commit->diff);
+ size_t deltas_len = git_diff_num_deltas(diff);
commit->deltas = ecalloc(deltas_len, sizeof(GitDelta*));
size_t deltas_out_count = 0;
for (size_t i = 0; i < deltas_len; i++) {
git_patch* patch = NULL;
- if (git_patch_from_diff(&patch, commit->diff, i)) {
+ if (git_patch_from_diff(&patch, diff, i)) {
continue;
}
@@ -131,6 +127,7 @@ GitCommit* gitcommit_create(const git_oid* oid, git_repository* repo) {
commit->deltas_len = deltas_out_count;
commit->filecount = deltas_len;
+ git_diff_free(diff);
git_commit_free(gcommit);
return commit;
}
@@ -152,8 +149,6 @@ void gitcommit_free(GitCommit* commit) {
free(commit->deltas);
commit->deltas = NULL;
- git_diff_free(commit->diff);
- commit->diff = NULL;
free(commit);
}