Skip to content

Commit f8fc4ca

Browse files
pks-tgitster
authored andcommitted
object-store: allow fetching objects via has_object()
We're about to fully remove `repo_has_object_file()` in favor of `has_object()`. The latter function does not yet have a way to fetch missing objects via a promisor remote though, which means that it cannot fully replace all usecases of `repo_has_object_file()`. Introduce a new flag `HAS_OBJECT_FETCH_PROMISOR` that causes the function to optionally fetch missing objects which are part of a promisor pack. This flag will be used in the subsequent commit. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1a79326 commit f8fc4ca

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

object-store.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -937,12 +937,15 @@ void *read_object_with_reference(struct repository *r,
937937
int has_object(struct repository *r, const struct object_id *oid,
938938
unsigned flags)
939939
{
940-
int quick = !(flags & HAS_OBJECT_RECHECK_PACKED);
941-
unsigned object_info_flags = OBJECT_INFO_SKIP_FETCH_OBJECT |
942-
(quick ? OBJECT_INFO_QUICK : 0);
940+
unsigned object_info_flags = 0;
943941

944942
if (!startup_info->have_repository)
945943
return 0;
944+
if (!(flags & HAS_OBJECT_RECHECK_PACKED))
945+
object_info_flags |= OBJECT_INFO_QUICK;
946+
if (!(flags & HAS_OBJECT_FETCH_PROMISOR))
947+
object_info_flags |= OBJECT_INFO_SKIP_FETCH_OBJECT;
948+
946949
return oid_object_info_extended(r, oid, NULL, object_info_flags) >= 0;
947950
}
948951

object-store.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,16 @@ int oid_object_info_extended(struct repository *r,
262262
const struct object_id *,
263263
struct object_info *, unsigned flags);
264264

265-
/* Retry packed storage after checking packed and loose storage */
266-
#define HAS_OBJECT_RECHECK_PACKED 1
265+
enum {
266+
/* Retry packed storage after checking packed and loose storage */
267+
HAS_OBJECT_RECHECK_PACKED = (1 << 0),
268+
/* Allow fetching the object in case the repository has a promisor remote. */
269+
HAS_OBJECT_FETCH_PROMISOR = (1 << 1),
270+
};
267271

268272
/*
269273
* Returns 1 if the object exists. This function will not lazily fetch objects
270-
* in a partial clone.
274+
* in a partial clone by default.
271275
*/
272276
int has_object(struct repository *r, const struct object_id *oid,
273277
unsigned flags);

0 commit comments

Comments
 (0)