Skip to content

Commit 3c7c41d

Browse files
aaronp24gitster
authored andcommitted
object: apply skip_hash and discard_tree optimizations to unknown blobs too
parse_object_with_flags() has an optimization to skip parsing blobs if PARSE_OBJECT_SKIP_HASH_CHECK is set and the object hasn't been seen before or might be a blob but hasn't been parsed yet. The latter can happen, for example, if add_tree_entries() walks a path that references a blob object that hasn't been seen before: lookup_blob() marks the referenced oid as being a blob, but does not provide any additional information about it until it is parsed. It's possible for an object to be created without even a type, such as when prepare_revision_walk() uses mark_uninteresting() to mark all promisor objects as uninteresting. These objects have obj->parsed == false and obj->type == OBJ_NONE. The skip_hash optimization does not consider this kind of object, so parse_object_with_flags() proceeds to fully parse the object to determine its type. Improve the optimization by applying it to OBJ_NONE objects as well as OBJ_BLOB ones. Apply a similar fix for trees. Fixes: 8db2dad ("parse_object(): check on-disk type of suspected blob") Signed-off-by: Aaron Plattner <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f0ef5b6 commit 3c7c41d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

object.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ struct object *parse_object_with_flags(struct repository *r,
328328
return &commit->object;
329329
}
330330

331-
if ((!obj || obj->type == OBJ_BLOB) &&
331+
if ((!obj || obj->type == OBJ_NONE || obj->type == OBJ_BLOB) &&
332332
odb_read_object_info(r->objects, oid, NULL) == OBJ_BLOB) {
333333
if (!skip_hash && stream_object_signature(r, repl) < 0) {
334334
error(_("hash mismatch %s"), oid_to_hex(oid));
@@ -344,7 +344,7 @@ struct object *parse_object_with_flags(struct repository *r,
344344
* have the on-disk object with the correct type.
345345
*/
346346
if (skip_hash && discard_tree &&
347-
(!obj || obj->type == OBJ_TREE) &&
347+
(!obj || obj->type == OBJ_NONE || obj->type == OBJ_TREE) &&
348348
odb_read_object_info(r->objects, oid, NULL) == OBJ_TREE) {
349349
return &lookup_tree(r, oid)->object;
350350
}

0 commit comments

Comments
 (0)