Skip to content

Commit 6a38b13

Browse files
pks-tgitster
authored andcommitted
odb/source: make freshen_object() 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 fdefdc2 commit 6a38b13

3 files changed

Lines changed: 36 additions & 10 deletions

File tree

odb.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -959,18 +959,10 @@ int odb_freshen_object(struct object_database *odb,
959959
const struct object_id *oid)
960960
{
961961
struct odb_source *source;
962-
963962
odb_prepare_alternates(odb);
964-
for (source = odb->sources; source; source = source->next) {
965-
struct odb_source_files *files = odb_source_files_downcast(source);
966-
967-
if (packfile_store_freshen_object(files->packed, oid))
963+
for (source = odb->sources; source; source = source->next)
964+
if (odb_source_freshen_object(source, oid))
968965
return 1;
969-
970-
if (odb_source_loose_freshen_object(source, oid))
971-
return 1;
972-
}
973-
974966
return 0;
975967
}
976968

odb/source-files.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ static int odb_source_files_for_each_object(struct odb_source *source,
8888
return 0;
8989
}
9090

91+
static int odb_source_files_freshen_object(struct odb_source *source,
92+
const struct object_id *oid)
93+
{
94+
struct odb_source_files *files = odb_source_files_downcast(source);
95+
if (packfile_store_freshen_object(files->packed, oid) ||
96+
odb_source_loose_freshen_object(source, oid))
97+
return 1;
98+
return 0;
99+
}
100+
91101
struct odb_source_files *odb_source_files_new(struct object_database *odb,
92102
const char *path,
93103
bool local)
@@ -105,6 +115,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
105115
files->base.read_object_info = odb_source_files_read_object_info;
106116
files->base.read_object_stream = odb_source_files_read_object_stream;
107117
files->base.for_each_object = odb_source_files_for_each_object;
118+
files->base.freshen_object = odb_source_files_freshen_object;
108119

109120
/*
110121
* Ideally, we would only ever store absolute paths in the source. This

odb/source.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,18 @@ struct odb_source {
186186
odb_for_each_object_cb cb,
187187
void *cb_data,
188188
unsigned flags);
189+
190+
/*
191+
* This callback is expected to freshen the given object so that its
192+
* last access time is set to the current time. This is used to ensure
193+
* that objects that are recent will not get garbage collected even if
194+
* they were unreachable.
195+
*
196+
* Returns 0 in case the object does not exist, 1 in case the object
197+
* has been freshened.
198+
*/
199+
int (*freshen_object)(struct odb_source *source,
200+
const struct object_id *oid);
189201
};
190202

191203
/*
@@ -297,4 +309,15 @@ static inline int odb_source_for_each_object(struct odb_source *source,
297309
return source->for_each_object(source, request, cb, cb_data, flags);
298310
}
299311

312+
/*
313+
* Freshen an object in the object database by updating its timestamp.
314+
* Returns 1 in case the object has been freshened, 0 in case the object does
315+
* not exist.
316+
*/
317+
static inline int odb_source_freshen_object(struct odb_source *source,
318+
const struct object_id *oid)
319+
{
320+
return source->freshen_object(source, oid);
321+
}
322+
300323
#endif

0 commit comments

Comments
 (0)