Re: [PATCH v9 1/6] read-cache: factor out get_sha1_from_index() helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



tboegi@xxxxxx writes:

> +#define get_sha1_from_cache(path)  get_sha1_from_index (&the_index, (path))
>  #endif

Micronit: lose the extra SP; i.e. "get_sha1_from_index(&the_index, (path))".

> diff --git a/read-cache.c b/read-cache.c
> index d9fb78b..a3ef967 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -2263,13 +2263,27 @@ int index_name_is_other(const struct index_state *istate, const char *name,
>  
>  void *read_blob_data_from_index(struct index_state *istate, const char *path, unsigned long *size)
>  {
> -	int pos, len;
> +	const unsigned char *sha1;
>  	unsigned long sz;
>  	enum object_type type;
>  	void *data;
>  
> -	len = strlen(path);
> -	pos = index_name_pos(istate, path, len);
> +	sha1 = get_sha1_from_index(istate, path);
> +	if (!sha1)
> +		return NULL;
> +	data = read_sha1_file(sha1, &type, &sz);
> +	if (!data || type != OBJ_BLOB) {
> +		free(data);
> +		return NULL;
> +	}
> +	if (size)
> +		*size = sz;
> +	return data;
> +}
> +
> +const unsigned char *get_sha1_from_index(struct index_state *istate, const char *path)
> +{
> +	int pos = index_name_pos(istate, path, strlen(path));
>  	if (pos < 0) {
>  		/*
>  		 * We might be in the middle of a merge, in which
> @@ -2285,14 +2299,7 @@ void *read_blob_data_from_index(struct index_state *istate, const char *path, un
>  	}
>  	if (pos < 0)
>  		return NULL;
> +	return (istate->cache[pos]->sha1);

Micronit: lose the extra () pair around what is returned.

I wondered if we can share more code with this helper and
get_sha1_with_context_1(), which is the canonical copy of this logic
used to parse ":$path" and get the object name at $path in the
index, but this is sufficiently low-level and such a refactoring
of small code would not be of great benefit, so this patch is OK.

Thanks.

>  }
>  
>  void stat_validity_clear(struct stat_validity *sv)
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]