Skip to content

Commit 24c43fb

Browse files
committed
Merge branch 'ps/odb-misc-fixes'
Miscellaneous fixes on object database layer. * ps/odb-misc-fixes: odb: properly close sources before freeing them builtin/gc: fix condition for whether to write commit graphs
2 parents c045383 + 3d09968 commit 24c43fb

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

builtin/gc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,8 +1130,10 @@ static int dfs_on_ref(const struct reference *ref, void *cb_data)
11301130
return 0;
11311131

11321132
commit = lookup_commit(the_repository, maybe_peeled);
1133-
if (!commit)
1133+
if (!commit || commit->object.flags & SEEN)
11341134
return 0;
1135+
commit->object.flags |= SEEN;
1136+
11351137
if (repo_parse_commit(the_repository, commit) ||
11361138
commit_graph_position(commit) != COMMIT_NOT_FROM_GRAPH)
11371139
return 0;
@@ -1141,7 +1143,7 @@ static int dfs_on_ref(const struct reference *ref, void *cb_data)
11411143
if (data->num_not_in_graph >= data->limit)
11421144
return 1;
11431145

1144-
commit_list_append(commit, &stack);
1146+
commit_list_insert(commit, &stack);
11451147

11461148
while (!result && stack) {
11471149
struct commit_list *parent;
@@ -1162,7 +1164,7 @@ static int dfs_on_ref(const struct reference *ref, void *cb_data)
11621164
break;
11631165
}
11641166

1165-
commit_list_append(parent->item, &stack);
1167+
commit_list_insert(parent->item, &stack);
11661168
}
11671169
}
11681170

odb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,13 +1117,13 @@ void odb_free(struct object_database *o)
11171117
oidmap_clear(&o->replace_map, 1);
11181118
pthread_mutex_destroy(&o->replace_mutex);
11191119

1120+
odb_close(o);
11201121
odb_free_sources(o);
11211122

11221123
for (size_t i = 0; i < o->cached_object_nr; i++)
11231124
free((char *) o->cached_objects[i].value.buf);
11241125
free(o->cached_objects);
11251126

1126-
odb_close(o);
11271127
packfile_store_free(o->packfiles);
11281128
string_list_clear(&o->submodule_source_paths, 0);
11291129

t/t7900-maintenance.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,31 @@ test_expect_success 'commit-graph auto condition' '
206206
test_subcommand $COMMIT_GRAPH_WRITE <cg-two-satisfied.txt
207207
'
208208

209+
test_expect_success 'commit-graph auto condition with merges' '
210+
test_when_finished "rm -rf repo" &&
211+
git init repo &&
212+
(
213+
cd repo &&
214+
git config set maintenance.auto false &&
215+
test_commit initial &&
216+
git switch --create feature &&
217+
test_commit feature-1 &&
218+
test_commit feature-2 &&
219+
git switch - &&
220+
test_commit main-1 &&
221+
test_commit main-2 &&
222+
git merge feature &&
223+
224+
# We have 6 commits, none of which are covered by a commit
225+
# graph. So this must be the boundary at which we start to
226+
# perform maintenance.
227+
test_must_fail git -c maintenance.commit-graph.auto=7 \
228+
maintenance is-needed --auto --task=commit-graph &&
229+
git -c maintenance.commit-graph.auto=6 \
230+
maintenance is-needed --auto --task=commit-graph
231+
)
232+
'
233+
209234
test_expect_success 'run --task=bogus' '
210235
test_must_fail git maintenance run --task=bogus 2>err &&
211236
test_grep "is not a valid task" err

0 commit comments

Comments
 (0)