Re: [PATCH v9 1/6] read-cache: factor out get_sha1_from_index() helper
- From
Junio C Hamano <gitster@pobox.com>
- Date
- May 9, 2016, 19:54 UTC
- Message-ID
- <xmqqy47jt3b6.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <1462601458-23498-1-git-send-email-tboegi@web.de>
tboegi@web.de 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))".
Show 40 quoted lines
> 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)