Skip to content

Commit be659c9

Browse files
pks-tgitster
authored andcommitted
object-file: hide internals when we need to reprepare loose sources
There are two different situations where we have to clear the cache of loose objects: - When freeing the loose object source itself to avoid memory leaks. - When repreparing the loose object source so that any potentially- stale data is getting evicted from the cache. The former is already handled by `odb_source_loose_free()`. But the latter case is still done manually by in `odb_reprepare()`, so we are leaking internals into that code. Introduce a new `odb_source_loose_reprepare()` function as an equivalent to `packfile_store_prepare()` to hide these implementation details. Furthermore, while at it, rename the function `odb_clear_loose_cache()` to `odb_source_loose_clear()`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 90a93f9 commit be659c9

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

object-file.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,12 +1834,17 @@ struct oidtree *odb_source_loose_cache(struct odb_source *source,
18341834
return source->loose->cache;
18351835
}
18361836

1837-
void odb_clear_loose_cache(struct odb_source *source)
1837+
static void odb_source_loose_clear_cache(struct odb_source_loose *loose)
18381838
{
1839-
oidtree_clear(source->loose->cache);
1840-
FREE_AND_NULL(source->loose->cache);
1841-
memset(&source->loose->subdir_seen, 0,
1842-
sizeof(source->loose->subdir_seen));
1839+
oidtree_clear(loose->cache);
1840+
FREE_AND_NULL(loose->cache);
1841+
memset(&loose->subdir_seen, 0,
1842+
sizeof(loose->subdir_seen));
1843+
}
1844+
1845+
void odb_source_loose_reprepare(struct odb_source *source)
1846+
{
1847+
odb_source_loose_clear_cache(source->loose);
18431848
}
18441849

18451850
static int check_stream_oid(git_zstream *stream,
@@ -2008,6 +2013,6 @@ void odb_source_loose_free(struct odb_source_loose *loose)
20082013
{
20092014
if (!loose)
20102015
return;
2011-
odb_clear_loose_cache(loose->source);
2016+
odb_source_loose_clear_cache(loose);
20122017
free(loose);
20132018
}

object-file.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ struct odb_source_loose {
3737
struct odb_source_loose *odb_source_loose_new(struct odb_source *source);
3838
void odb_source_loose_free(struct odb_source_loose *loose);
3939

40+
/* Reprepare the loose source by emptying the loose object cache. */
41+
void odb_source_loose_reprepare(struct odb_source *source);
42+
4043
/*
4144
* Populate and return the loose object cache array corresponding to the
4245
* given object ID.
4346
*/
4447
struct oidtree *odb_source_loose_cache(struct odb_source *source,
4548
const struct object_id *oid);
4649

47-
/* Empty the loose object cache for the specified object directory. */
48-
void odb_clear_loose_cache(struct odb_source *source);
49-
5050
/*
5151
* Put in `buf` the name of the file in the local object database that
5252
* would be used to store a loose object with the specified oid.

odb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ void odb_reprepare(struct object_database *o)
10711071
odb_prepare_alternates(o);
10721072

10731073
for (source = o->sources; source; source = source->next)
1074-
odb_clear_loose_cache(source);
1074+
odb_source_loose_reprepare(source);
10751075

10761076
o->approximate_object_count_valid = 0;
10771077

0 commit comments

Comments
 (0)