Skip to content

Commit ece43d9

Browse files
pks-tgitster
authored andcommitted
object-file: introduce struct odb_source_loose
Currently, all state that relates to loose objects is held directly by the `struct odb_source`. Introduce a new `struct odb_source_loose` to hold the state instead so that it is entirely self-contained. This structure will eventually morph into the backend for accessing loose objects. As such, this is part of the refactorings to introduce pluggable object databases. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 0cc12de commit ece43d9

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

object-file.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,3 +1995,16 @@ void object_file_transaction_commit(struct odb_transaction *transaction)
19951995
transaction->odb->transaction = NULL;
19961996
free(transaction);
19971997
}
1998+
1999+
struct odb_source_loose *odb_source_loose_new(struct odb_source *source)
2000+
{
2001+
struct odb_source_loose *loose;
2002+
CALLOC_ARRAY(loose, 1);
2003+
loose->source = source;
2004+
return loose;
2005+
}
2006+
2007+
void odb_source_loose_free(struct odb_source_loose *loose)
2008+
{
2009+
free(loose);
2010+
}

object-file.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ int index_path(struct index_state *istate, struct object_id *oid, const char *pa
1818

1919
struct odb_source;
2020

21+
struct odb_source_loose {
22+
struct odb_source *source;
23+
};
24+
25+
struct odb_source_loose *odb_source_loose_new(struct odb_source *source);
26+
void odb_source_loose_free(struct odb_source_loose *loose);
27+
2128
/*
2229
* Populate and return the loose object cache array corresponding to the
2330
* given object ID.

odb.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ struct odb_source *odb_source_new(struct object_database *odb,
151151
source->odb = odb;
152152
source->local = local;
153153
source->path = xstrdup(path);
154+
source->loose = odb_source_loose_new(source);
154155

155156
return source;
156157
}
@@ -368,6 +369,7 @@ struct odb_source *odb_set_temporary_primary_source(struct object_database *odb,
368369
static void odb_source_free(struct odb_source *source)
369370
{
370371
free(source->path);
372+
odb_source_loose_free(source->loose);
371373
odb_clear_loose_cache(source);
372374
loose_object_map_clear(&source->loose_map);
373375
free(source);

odb.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ struct odb_source {
4848
/* Object database that owns this object source. */
4949
struct object_database *odb;
5050

51+
/* Private state for loose objects. */
52+
struct odb_source_loose *loose;
53+
5154
/*
5255
* Used to store the results of readdir(3) calls when we are OK
5356
* sacrificing accuracy due to races for speed. That includes

0 commit comments

Comments
 (0)