As noted in the comment introduced in 837d395a5c0 (Replace parse_blob() with an explanatory comment, 2010-01-18) the old parse_blob() function and the parse_blob_buffer() existed to provide consistency in the API. See bd2c39f58f9 ([PATCH] don't load and decompress objects twice with parse_object(), 2005-05-06) for the introduction of parse_blob_buffer(). We're not going to parse blobs like we "parse" commits, trees or tags. So we should not have the parse_blob_buffer() take arguments that pretends that we do. Its only use is to set the "parsed" flag. So let's entirely remove the function, and use our newly created create_blob() for the allocation. We can then set the "parsed" flag directly in parse_object_buffer() and parse_object() instead. At this point I could move the comment added in 837d395a5c0 to one or both of those object.c function, but let's just delete it instead. I think it's obvious from the flow of the code what's going on here. Setting the parsed flag no longer happens at a distance, so why we're doing it isn't unclear anymore. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx> --- blob.c | 8 +------- blob.h | 12 +----------- object.c | 11 +++++++---- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/blob.c b/blob.c index d98b6badc7..1308299eab 100644 --- a/blob.c +++ b/blob.c @@ -5,7 +5,7 @@ const char *blob_type = "blob"; -static struct blob *create_blob(struct repository *r, const struct object_id *oid) +struct blob *create_blob(struct repository *r, const struct object_id *oid) { return create_object(r, oid, alloc_blob_node(r)); } @@ -17,9 +17,3 @@ struct blob *lookup_blob(struct repository *r, const struct object_id *oid) return create_blob(r, oid); return object_as_type(obj, OBJ_BLOB, 0); } - -int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size) -{ - item->object.parsed = 1; - return 0; -} diff --git a/blob.h b/blob.h index 1664872055..6e6b23a769 100644 --- a/blob.h +++ b/blob.h @@ -9,17 +9,7 @@ struct blob { struct object object; }; +struct blob *create_blob(struct repository *r, const struct object_id *oid); struct blob *lookup_blob(struct repository *r, const struct object_id *oid); -int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size); - -/** - * Blobs do not contain references to other objects and do not have - * structured data that needs parsing. However, code may use the - * "parsed" bit in the struct object for a blob to determine whether - * its content has been found to actually be available, so - * parse_blob_buffer() is used (by object.c) to flag that the object - * has been read successfully from the database. - **/ - #endif /* BLOB_H */ diff --git a/object.c b/object.c index 78343781ae..f4e419e5c3 100644 --- a/object.c +++ b/object.c @@ -195,8 +195,7 @@ struct object *parse_object_buffer(struct repository *r, const struct object_id if (type == OBJ_BLOB) { struct blob *blob = lookup_blob(r, oid); if (blob) { - if (parse_blob_buffer(blob, buffer, size)) - return NULL; + blob->object.parsed = 1; obj = &blob->object; } } else if (type == OBJ_TREE) { @@ -262,12 +261,16 @@ struct object *parse_object(struct repository *r, const struct object_id *oid) if ((obj && obj->type == OBJ_BLOB && repo_has_object_file(r, oid)) || (!obj && repo_has_object_file(r, oid) && oid_object_info(r, oid, NULL) == OBJ_BLOB)) { + if (!obj) { + struct blob *blob = create_blob(r, oid); + obj = &blob->object; + } if (check_object_signature(r, repl, NULL, 0, NULL) < 0) { error(_("hash mismatch %s"), oid_to_hex(oid)); return NULL; } - parse_blob_buffer(lookup_blob(r, oid), NULL, 0); - return lookup_object(r, oid); + obj->parsed = 1; + return obj; } buffer = repo_read_object_file(r, oid, &type, &size); -- 2.31.1.723.ga5d7868e4a