read_blob_data_from_index(): optionally return the size of blob data
This allows for optionally getting the size of the returned data and will be used in a follow-up patch. Signed-off-by: Lukas Fleischer <git@cryptocrack.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Lukas Fleischer committed
Apr 13, 2013 at 15:28 UTC
ff36682505dfb580172306fe1b265b860f89bcea
3 files changed
+6
-4
attr.c
+1
-1
@@ -387,7 +387,7 @@ static struct attr_stack *read_attr_from_index(const char *path, int macro_ok)
387
char *buf, *sp;
388
int lineno = 0;
389
390
- buf = read_blob_data_from_index(use_index ? use_index : &the_index, path);
390
+ buf = read_blob_data_from_index(use_index ? use_index : &the_index, path, NULL);
391
if (!buf)
392
return NULL;
393
cache.h
+2
-2
@@ -307,7 +307,7 @@ extern void free_name_hash(struct index_state *istate);
307
#define resolve_undo_clear() resolve_undo_clear_index(&the_index)
308
#define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at)
309
#define unmerge_cache(pathspec) unmerge_index(&the_index, pathspec)
310
-#define read_blob_data_from_cache(path) read_blob_data_from_index(&the_index, (path))
310
+#define read_blob_data_from_cache(path, sz) read_blob_data_from_index(&the_index, (path), (sz))
311
#endif
312
313
enum object_type {
@@ -453,7 +453,7 @@ extern int add_file_to_index(struct index_state *, const char *path, int flags);
453
extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh);
454
extern int ce_same_name(struct cache_entry *a, struct cache_entry *b);
455
extern int index_name_is_other(const struct index_state *, const char *, int);
456
-extern void *read_blob_data_from_index(struct index_state *, const char *);
456
+extern void *read_blob_data_from_index(struct index_state *, const char *, unsigned long *);
457
458
/* do stat comparison even if CE_VALID is true */
459
#define CE_MATCH_IGNORE_VALID 01
read-cache.c
+3
-1
@@ -1896,7 +1896,7 @@ int index_name_is_other(const struct index_state *istate, const char *name,
1896
return 1;
1897
}
1898
1899
-void *read_blob_data_from_index(struct index_state *istate, const char *path)
1899
+void *read_blob_data_from_index(struct index_state *istate, const char *path, unsigned long *size)
1900
{
1901
int pos, len;
1902
unsigned long sz;
@@ -1925,5 +1925,7 @@ void *read_blob_data_from_index(struct index_state *istate, const char *path)
1925
free(data);
1926
return NULL;
1927
}
1928
+ if (size)
1929
+ *size = sz;
1930
return data;
1931
}