Patrick Steinhardt <ps@xxxxxx> writes: > We're about to fully remove `repo_has_object_file()` in favor of > `has_object()` given that the latter has better defaults: it neither > reloads packfiles by default nor does it fetch any promised objects in > case they are missing. > > The latter usecase keeps us from converting a couple of callsites that > currently do fetch objects though. It is not really clear whether _all_ > of those callsites should be fetching objects, but for a subset of them > it is the desired behaviour indeed. > > Introduce a new flag `HAS_OBJECT_FETCH_PROMISOR` that causes the > function to optionally fetch missing objects which are part of a > promisor pack. > > Signed-off-by: Patrick Steinhardt <ps@xxxxxx> > --- > object-store.c | 9 ++++++--- > object-store.h | 10 +++++++--- > 2 files changed, 13 insertions(+), 6 deletions(-) > > diff --git a/object-store.c b/object-store.c > index 0cbad5a19a0..0d873868a6d 100644 > --- a/object-store.c > +++ b/object-store.c > @@ -937,12 +937,15 @@ void *read_object_with_reference(struct repository *r, > int has_object(struct repository *r, const struct object_id *oid, > unsigned flags) > { > - int quick = !(flags & HAS_OBJECT_RECHECK_PACKED); > - unsigned object_info_flags = OBJECT_INFO_SKIP_FETCH_OBJECT | > - (quick ? OBJECT_INFO_QUICK : 0); > + unsigned object_info_flags = 0; > > if (!startup_info->have_repository) > return 0; > + if (!(flags & HAS_OBJECT_RECHECK_PACKED)) > + object_info_flags |= OBJECT_INFO_QUICK; > + if (!(flags & HAS_OBJECT_FETCH_PROMISOR)) > + object_info_flags |= OBJECT_INFO_SKIP_FETCH_OBJECT; > + This already is much easier to read. > return oid_object_info_extended(r, oid, NULL, object_info_flags) >= 0; > } > > diff --git a/object-store.h b/object-store.h > index 5bbdaba92d1..c6055376f49 100644 > --- a/object-store.h > +++ b/object-store.h > @@ -266,12 +266,16 @@ int oid_object_info_extended(struct repository *r, > const struct object_id *, > struct object_info *, unsigned flags); > > -/* Retry packed storage after checking packed and loose storage */ > -#define HAS_OBJECT_RECHECK_PACKED 1 > +enum { > + /* Retry packed storage after checking packed and loose storage */ > + HAS_OBJECT_RECHECK_PACKED = (1 << 0), > + /* Allow fetching the object in case the repository has a promisor remote. */ > + HAS_OBJECT_FETCH_PROMISOR = (1 << 1), > +}; > > /* > * Returns 1 if the object exists. This function will not lazily fetch objects > - * in a partial clone. > + * in a partial clone by default. > */ > int has_object(struct repository *r, const struct object_id *oid, > unsigned flags); > > -- > 2.49.0.901.g37484f566f.dirty Okay so we add the functionality here, and possibly use it in the future patches. Good.
Attachment:
signature.asc
Description: PGP signature