mirror of
https://github.com/git/git.git
synced 2026-01-23 07:17:18 +09:00
odb: introduce odb_for_each_object()
Introduce a new function `odb_for_each_object()` that knows to iterate through all objects part of a given object database. This function is essentially a simple wrapper around the object database sources. Subsequent commits will adapt callers to use this new function. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
9360712ee9
commit
403d681b60
27
odb.c
27
odb.c
@ -995,6 +995,33 @@ int odb_freshen_object(struct object_database *odb,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int odb_for_each_object(struct object_database *odb,
|
||||
struct object_info *oi,
|
||||
odb_for_each_object_cb cb,
|
||||
void *cb_data,
|
||||
unsigned flags)
|
||||
{
|
||||
int ret;
|
||||
|
||||
odb_prepare_alternates(odb);
|
||||
for (struct odb_source *source = odb->sources; source; source = source->next) {
|
||||
if (flags & ODB_FOR_EACH_OBJECT_LOCAL_ONLY && !source->local)
|
||||
continue;
|
||||
|
||||
if (!(flags & ODB_FOR_EACH_OBJECT_PROMISOR_ONLY)) {
|
||||
ret = odb_source_loose_for_each_object(source, oi, cb, cb_data, flags);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = packfile_store_for_each_object(source->packfiles, oi, cb, cb_data, flags);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void odb_assert_oid_type(struct object_database *odb,
|
||||
const struct object_id *oid, enum object_type expect)
|
||||
{
|
||||
|
||||
17
odb.h
17
odb.h
@ -475,6 +475,23 @@ typedef int (*odb_for_each_object_cb)(const struct object_id *oid,
|
||||
struct object_info *oi,
|
||||
void *cb_data);
|
||||
|
||||
/*
|
||||
* Iterate through all objects contained in the object database. Note that
|
||||
* objects may be iterated over multiple times in case they are either stored
|
||||
* in different backends or in case they are stored in multiple sources.
|
||||
*
|
||||
* Returning a non-zero error code from the callback function will cause
|
||||
* iteration to abort. The error code will be propagated.
|
||||
*
|
||||
* Returns 0 on success, a negative error code in case a failure occurred, or
|
||||
* an arbitrary non-zero error code returned by the callback itself.
|
||||
*/
|
||||
int odb_for_each_object(struct object_database *odb,
|
||||
struct object_info *oi,
|
||||
odb_for_each_object_cb cb,
|
||||
void *cb_data,
|
||||
unsigned flags);
|
||||
|
||||
enum {
|
||||
/*
|
||||
* By default, `odb_write_object()` does not actually write anything
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user