summaryrefslogtreecommitdiff
path: root/builtin/mktree.c
diff options
context:
space:
mode:
authorRichard Oliver <roliver@roku.com>2022-06-21 14:59:39 +0100
committerJunio C Hamano <gitster@pobox.com>2022-06-21 10:12:15 -0700
commit817b0f60271086fb53fca2e56d426507b82c7dbd (patch)
tree284c6129a0bfd23448cbb872672556703dd0069b /builtin/mktree.c
parentdc8c8deaa6b5847733bd7df011a4c7b7d1a64e0a (diff)
downloadgit-817b0f60271086fb53fca2e56d426507b82c7dbd.tar.gz
mktree: do not check type of remote objects
With 31c8221a (mktree: validate entry type in input, 2009-05-14), we called the sha1_object_info() API to obtain the type information, but allowed the call to silently fail when the object was missing locally, so that we can sanity-check the types opportunistically when the object did exist. The implementation is understandable because back then there was no lazy/on-demand downloading of individual objects from the promisor remotes that causes a long delay and materializes the object, hence defeating the point of using "--missing". The design is hurting us now. We could bypass the opportunistic type/mode consistency check altogether when "--missing" is given, but instead, use the oid_object_info_extended() API and tell it that we are only interested in objects that locally exist and are immediately available by passing OBJECT_INFO_SKIP_FETCH_OBJECT bit to it. That way, we will still retain the cheap and opportunistic sanity check for local objects. Signed-off-by: Richard Oliver <roliver@roku.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/mktree.c')
-rw-r--r--builtin/mktree.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/builtin/mktree.c b/builtin/mktree.c
index 902edba6d2..06d81400f5 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -74,6 +74,7 @@ static void mktree_line(char *buf, int nul_term_line, int allow_missing)
unsigned mode;
enum object_type mode_type; /* object type derived from mode */
enum object_type obj_type; /* object type derived from sha */
+ struct object_info oi = OBJECT_INFO_INIT;
char *path, *to_free = NULL;
struct object_id oid;
@@ -116,8 +117,14 @@ static void mktree_line(char *buf, int nul_term_line, int allow_missing)
path, ptr, type_name(mode_type));
}
- /* Check the type of object identified by sha1 */
- obj_type = oid_object_info(the_repository, &oid, NULL);
+ /* Check the type of object identified by oid without fetching objects */
+ oi.typep = &obj_type;
+ if (oid_object_info_extended(the_repository, &oid, &oi,
+ OBJECT_INFO_LOOKUP_REPLACE |
+ OBJECT_INFO_QUICK |
+ OBJECT_INFO_SKIP_FETCH_OBJECT) < 0)
+ obj_type = -1;
+
if (obj_type < 0) {
if (allow_missing) {
; /* no problem - missing objects are presumed to be of the right type */