File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1062,10 +1062,8 @@ struct object_database *odb_new(struct repository *repo,
10621062void odb_close (struct object_database * o )
10631063{
10641064 struct odb_source * source ;
1065- for (source = o -> sources ; source ; source = source -> next ) {
1066- struct odb_source_files * files = odb_source_files_downcast (source );
1067- packfile_store_close (files -> packed );
1068- }
1065+ for (source = o -> sources ; source ; source = source -> next )
1066+ odb_source_close (source );
10691067 close_commit_graph (o );
10701068}
10711069
Original file line number Diff line number Diff line change @@ -28,6 +28,12 @@ static void odb_source_files_free(struct odb_source *source)
2828 free (files );
2929}
3030
31+ static void odb_source_files_close (struct odb_source * source )
32+ {
33+ struct odb_source_files * files = odb_source_files_downcast (source );
34+ packfile_store_close (files -> packed );
35+ }
36+
3137static void odb_source_files_reprepare (struct odb_source * source )
3238{
3339 struct odb_source_files * files = odb_source_files_downcast (source );
@@ -47,6 +53,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
4753 files -> packed = packfile_store_new (& files -> base );
4854
4955 files -> base .free = odb_source_files_free ;
56+ files -> base .close = odb_source_files_close ;
5057 files -> base .reprepare = odb_source_files_reprepare ;
5158
5259 /*
Original file line number Diff line number Diff line change @@ -58,6 +58,14 @@ struct odb_source {
5858 */
5959 void (* free )(struct odb_source * source );
6060
61+ /*
62+ * This callback is expected to close any open resources, like for
63+ * example file descriptors or connections. The source is expected to
64+ * still be usable after it has been closed. Closed resources may need
65+ * to be reopened in that case.
66+ */
67+ void (* close )(struct odb_source * source );
68+
6169 /*
6270 * This callback is expected to clear underlying caches of the object
6371 * database source. The function is called when the repository has for
@@ -103,6 +111,16 @@ void odb_source_free(struct odb_source *source);
103111 */
104112void odb_source_release (struct odb_source * source );
105113
114+ /*
115+ * Close the object database source without releasing he underlying data. The
116+ * source can still be used going forward, but it first needs to be reopened.
117+ * This can be useful to reduce resource usage.
118+ */
119+ static inline void odb_source_close (struct odb_source * source )
120+ {
121+ source -> close (source );
122+ }
123+
106124/*
107125 * Reprepare the object database source and clear any caches. Depending on the
108126 * backend used this may have the effect that concurrently-written objects
You can’t perform that action at this time.
0 commit comments