odb: refactor odb_clear() to odb_free()

The function `odb_clear()` releases all resources allocated to an object
database and ensures that all fields become zero'd out. Despite its
naming though it doesn't really clear the object database so that it
becomes ready for reuse afterwards again -- the caller would first have
to reinitialize it, and that contradicts the terminology of "clearing"
as we have defined it in our coding guidelines.

There isn't really only a reason to have "clearing" semantics, either.
There's only a single caller of `odb_clear()`, and that caller also ends
up freeing the object database structure itself.

Refactor the function to have "freeing" semantics instead, so that the
structure itself is also freed, which allows us to drop some useless
boilerplate to zero out the structure's members.

This refactoring reveals that we're trying to close the commit graph
multiple times: once directly via `free_commit_graph()`, and once via
`odb_close()`. Drop the former call.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2025-11-19 08:50:52 +01:00
committed by Junio C Hamano
parent 9aaba57993
commit f8bdf3127a
3 changed files with 13 additions and 14 deletions

4
odb.h
View File

@@ -167,7 +167,9 @@ struct object_database {
};
struct object_database *odb_new(struct repository *repo);
void odb_clear(struct object_database *o);
/* Free the object database and release all resources. */
void odb_free(struct object_database *o);
/*
* Close the object database and all of its sources so that any held resources