void odb_close(struct object_database *o)
{
struct odb_source *source;
- for (source = o->sources; source; source = source->next) {
- struct odb_source_files *files = odb_source_files_downcast(source);
- packfile_store_close(files->packed);
- }
+ for (source = o->sources; source; source = source->next)
+ odb_source_close(source);
close_commit_graph(o);
}
free(files);
}
+static void odb_source_files_close(struct odb_source *source)
+{
+ struct odb_source_files *files = odb_source_files_downcast(source);
+ packfile_store_close(files->packed);
+}
+
static void odb_source_files_reprepare(struct odb_source *source)
{
struct odb_source_files *files = odb_source_files_downcast(source);
files->packed = packfile_store_new(&files->base);
files->base.free = odb_source_files_free;
+ files->base.close = odb_source_files_close;
files->base.reprepare = odb_source_files_reprepare;
/*
*/
void (*free)(struct odb_source *source);
+ /*
+ * This callback is expected to close any open resources, like for
+ * example file descriptors or connections. The source is expected to
+ * still be usable after it has been closed. Closed resources may need
+ * to be reopened in that case.
+ */
+ void (*close)(struct odb_source *source);
+
/*
* This callback is expected to clear underlying caches of the object
* database source. The function is called when the repository has for
*/
void odb_source_release(struct odb_source *source);
+/*
+ * Close the object database source without releasing he underlying data. The
+ * source can still be used going forward, but it first needs to be reopened.
+ * This can be useful to reduce resource usage.
+ */
+static inline void odb_source_close(struct odb_source *source)
+{
+ source->close(source);
+}
+
/*
* Reprepare the object database source and clear any caches. Depending on the
* backend used this may have the effect that concurrently-written objects