diff options
author | Torsten Bögershausen <tboegi@web.de> | 2016-06-28 10:01:15 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-07-07 09:17:12 -0700 |
commit | 75964d2722cb95f0a9a04f9c0a5814faabbd232f (patch) | |
tree | 2c977256b804597d114102ed44ea329c2a177cff | |
parent | 6523728499e77afaed0008875b19b308682c3f88 (diff) | |
download | git-75964d2722cb95f0a9a04f9c0a5814faabbd232f.tar.gz |
read-cache: factor out get_sha1_from_index() helper
Factor out the retrieval of the sha1 for a given path in
read_blob_data_from_index() into the function get_sha1_from_index().
This will be used in the next commit, when convert.c can do the
analyze for "text=auto" without slurping the whole blob into memory
at once.
Add a wrapper definition get_sha1_from_cache().
Signed-off-by: Torsten Bögershausen <tboegi@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | cache.h | 3 | ||||
-rw-r--r-- | read-cache.c | 29 |
2 files changed, 21 insertions, 11 deletions
@@ -379,6 +379,7 @@ extern void free_name_hash(struct index_state *istate); #define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at) #define unmerge_cache(pathspec) unmerge_index(&the_index, pathspec) #define read_blob_data_from_cache(path, sz) read_blob_data_from_index(&the_index, (path), (sz)) +#define get_sha1_from_cache(path) get_sha1_from_index (&the_index, (path)) #endif enum object_type { @@ -1008,6 +1009,8 @@ static inline void *read_sha1_file(const unsigned char *sha1, enum object_type * return read_sha1_file_extended(sha1, type, size, LOOKUP_REPLACE_OBJECT); } +const unsigned char *get_sha1_from_index(struct index_state *istate, const char *path); + /* * This internal function is only declared here for the benefit of * lookup_replace_object(). Please do not call it directly. diff --git a/read-cache.c b/read-cache.c index d9fb78bc55..a3ef967411 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; - data = read_sha1_file(istate->cache[pos]->sha1, &type, &sz); - if (!data || type != OBJ_BLOB) { - free(data); - return NULL; - } - if (size) - *size = sz; - return data; + return (istate->cache[pos]->sha1); } void stat_validity_clear(struct stat_validity *sv) |