summaryrefslogtreecommitdiff
path: root/sha1-file.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-08-13 21:13:39 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-08-13 21:13:39 (GMT)
commitd1a8a8979d61a889b915dca36aea9c2a88d0f3f7 (patch)
tree02eece403714ca30f78b50c485e323db0ab44b97 /sha1-file.c
parent092b6771c799d761a83317f68a467bef930686ad (diff)
parent9eb86f41de7d229bb3a073e16e735cf71e2ffe3b (diff)
downloadgit-d1a8a8979d61a889b915dca36aea9c2a88d0f3f7.zip
git-d1a8a8979d61a889b915dca36aea9c2a88d0f3f7.tar.gz
git-d1a8a8979d61a889b915dca36aea9c2a88d0f3f7.tar.bz2
Merge branch 'jt/has_object'
A new helper function has_object() has been introduced to make it easier to mark object existence checks that do and don't want to trigger lazy fetches, and a few such checks are converted using it. * jt/has_object: fsck: do not lazy fetch known non-promisor object pack-objects: no fetch when allow-{any,promisor} apply: do not lazy fetch when applying binary sha1-file: introduce no-lazy-fetch has_object()
Diffstat (limited to 'sha1-file.c')
-rw-r--r--sha1-file.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/sha1-file.c b/sha1-file.c
index 8904559..dd65bd5 100644
--- a/sha1-file.c
+++ b/sha1-file.c
@@ -1989,6 +1989,18 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
return ret;
}
+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);
+
+ if (!startup_info->have_repository)
+ return 0;
+ return oid_object_info_extended(r, oid, NULL, object_info_flags) >= 0;
+}
+
int repo_has_object_file_with_flags(struct repository *r,
const struct object_id *oid, int flags)
{