Subject: Re: [PATCH v2 06/10] blob.c: remove parse_blob_buffer()

From: Junio C Hamano <[email-masked]>
Date: Thu, 29 Apr 2021 13:51:26 +0900

Ævar Arnfjörð Bjarmason  <[email-masked]> writes:

> -int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size)
> -{
> -	item->object.parsed = 1;
> -	return 0;
> -}

Understandable.

> 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;
>  		}

Understandable, too.

>  	} 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;
> +		}

I do not recall this change explained or justified in the log
message.  What am I missing?

>  		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;

Likewise.  Why isn't it just a call to lookup_blob() followed by
setting of its .parsed bit?  

In other words, it is not clear why we need to expose create_blob().

>  	}
>  
>  	buffer = repo_read_object_file(r, oid, &type, &size);