summaryrefslogtreecommitdiff
path: root/object-store.h
diff options
context:
space:
mode:
authorJonathan Tan <jonathantanmy@google.com>2020-08-05 23:06:49 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-08-06 20:01:02 (GMT)
commit1d8d9cb62099e1524ce1269ea88faad871c2197f (patch)
treed319dd7f637a3c89fa0a6ed3ff0f37c758643a05 /object-store.h
parentdc04167d378fb29d30e1647ff6ff51dd182bc9a3 (diff)
downloadgit-1d8d9cb62099e1524ce1269ea88faad871c2197f.zip
git-1d8d9cb62099e1524ce1269ea88faad871c2197f.tar.gz
git-1d8d9cb62099e1524ce1269ea88faad871c2197f.tar.bz2
sha1-file: introduce no-lazy-fetch has_object()
There have been a few bugs wherein Git fetches missing objects whenever the existence of an object is checked, even though it does not need to perform such a fetch. To resolve these bugs, we could look at all the places that has_object_file() (or a similar function) is used. As a first step, introduce a new function has_object() that checks for the existence of an object, with a default behavior of not fetching if the object is missing and the repository is a partial clone. As we verify each has_object_file() (or similar) usage, we can replace it with has_object(), and we will know that we are done when we can delete has_object_file() (and the other similar functions). Also, the new function has_object() has more appropriate defaults: besides not fetching, it also does not recheck packed storage. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'object-store.h')
-rw-r--r--object-store.h25
1 files changed, 23 insertions, 2 deletions
diff --git a/object-store.h b/object-store.h
index f439d47..c4fc9dd 100644
--- a/object-store.h
+++ b/object-store.h
@@ -239,12 +239,33 @@ int read_loose_object(const char *path,
unsigned long *size,
void **contents);
+/* Retry packed storage after checking packed and loose storage */
+#define HAS_OBJECT_RECHECK_PACKED 1
+
+/*
+ * Returns 1 if the object exists. This function will not lazily fetch objects
+ * in a partial clone.
+ */
+int has_object(struct repository *r, const struct object_id *oid,
+ unsigned flags);
+
+/*
+ * These macros and functions are deprecated. If checking existence for an
+ * object that is likely to be missing and/or whose absence is relatively
+ * inconsequential (or is consequential but the caller is prepared to handle
+ * it), use has_object(), which has better defaults (no lazy fetch in a partial
+ * clone and no rechecking of packed storage). In the unlikely event that a
+ * caller needs to assert existence of an object that it fully expects to
+ * exist, and wants to trigger a lazy fetch in a partial clone, use
+ * oid_object_info_extended() with a NULL struct object_info.
+ *
+ * These functions can be removed once all callers have migrated to
+ * has_object() and/or oid_object_info_extended().
+ */
#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
#define has_sha1_file_with_flags(sha1, flags) repo_has_sha1_file_with_flags(the_repository, sha1, flags)
#define has_sha1_file(sha1) repo_has_sha1_file(the_repository, sha1)
#endif
-
-/* Same as the above, except for struct object_id. */
int repo_has_object_file(struct repository *r, const struct object_id *oid);
int repo_has_object_file_with_flags(struct repository *r,
const struct object_id *oid, int flags);