Skip to content

Commit 47b9650

Browse files
pks-tgitster
authored andcommitted
odb/source: make free() function pluggable
Introduce a new callback function in `struct odb_source` to make the function pluggable. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 87842f6 commit 47b9650

4 files changed

Lines changed: 11 additions & 9 deletions

File tree

odb/source-files.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ static void odb_source_files_reparent(const char *name UNUSED,
1818
files->base.path = path;
1919
}
2020

21-
void odb_source_files_free(struct odb_source_files *files)
21+
static void odb_source_files_free(struct odb_source *source)
2222
{
23-
if (!files)
24-
return;
23+
struct odb_source_files *files = odb_source_files_downcast(source);
2524
chdir_notify_unregister(NULL, odb_source_files_reparent, files);
2625
odb_source_loose_free(files->loose);
2726
packfile_store_free(files->packed);
@@ -40,6 +39,8 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
4039
files->loose = odb_source_loose_new(&files->base);
4140
files->packed = packfile_store_new(&files->base);
4241

42+
files->base.free = odb_source_files_free;
43+
4344
/*
4445
* Ideally, we would only ever store absolute paths in the source. This
4546
* is not (yet) possible though because we access and assume relative

odb/source-files.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
2121
const char *path,
2222
bool local);
2323

24-
/* Free the object source and release all associated resources. */
25-
void odb_source_files_free(struct odb_source_files *files);
26-
2724
/*
2825
* Cast the given object database source to the files backend. This will cause
2926
* a BUG in case the source doesn't use this backend.

odb/source.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ void odb_source_init(struct odb_source *source,
2525

2626
void odb_source_free(struct odb_source *source)
2727
{
28-
struct odb_source_files *files;
2928
if (!source)
3029
return;
31-
files = odb_source_files_downcast(source);
32-
odb_source_files_free(files);
30+
source->free(source);
3331
}
3432

3533
void odb_source_release(struct odb_source *source)

odb/source.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ struct odb_source {
5151
* the current working directory.
5252
*/
5353
char *path;
54+
55+
/*
56+
* This callback is expected to free the underlying object database source and
57+
* all associated resources. The function will never be called with a NULL pointer.
58+
*/
59+
void (*free)(struct odb_source *source);
5460
};
5561

5662
/*

0 commit comments

Comments
 (0)