Subject: Re: [PATCH v1 3/3] convert: ce_compare_data() checks for a sha1 of a path

From: Junio C Hamano <[email-masked]>
Date: Sun, 15 May 2016 15:14:11 -0700

[email-masked] writes:

> -static int has_cr_in_index(const char *path)
> +static int has_cr_in_index(const char *path, const unsigned char *sha1)
>  {
>  	unsigned long sz;
>  	void *data;
>  	int has_cr;
> -
> -	data = read_blob_data_from_cache(path, &sz);
> -	if (!data)
> +	enum object_type type;
> +	if (!sha1)
> +		sha1 = get_sha1_from_cache(path);
> +	if (!sha1)
> +		return 0;
> +	data = read_sha1_file(sha1, &type, &sz);
> +	if (!data || type != OBJ_BLOB) {
> +		free(data);
>  		return 0;
> +	}
> +
>  	has_cr = memchr(data, '\r', sz) != NULL;
>  	free(data);
>  	return has_cr;
>  }

Does this really need 2/3?  Wouldn't this be equivalent to

	if (!sha1) {
        	data = read_blob_data_from_cache(path, &sz);
	} else {
        	data = read_sha1_file(sha1, &type, &sz);
	}
	if (!data || type != OBJ_BLOB) {
        	free(data);
                return 0;
	}

        has_cr = ...