read-cache.c: make create_from_disk() report number of bytes it consumed
The function is the one that is reading from the data stream. It only is natural to make it responsible for reporting this number, not the caller. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Apr 3, 2012 at 15:53 UTC
936f53d055c9a336e9ad89ad06c4efd56e5896e8
1 file changed
+6
-3
read-cache.c
+6
-3
@@ -1305,7 +1305,8 @@ static inline uint32_t ntoh_l_force_align(void *p)
1305
#define ntoh_l(var) ntoh_l_force_align(&(var))
1306
#endif
1307
1308
-static struct cache_entry *create_from_disk(struct ondisk_cache_entry *ondisk)
1308
+static struct cache_entry *create_from_disk(struct ondisk_cache_entry *ondisk,
1309
+ unsigned long *ent_size)
1310
{
1311
struct cache_entry *ce;
1312
size_t len;
@@ -1351,6 +1352,7 @@ static struct cache_entry *create_from_disk(struct ondisk_cache_entry *ondisk)
1352
1353
memcpy(ce->name, name, len);
1354
ce->name[len] = '\0';
1355
+ *ent_size = ondisk_ce_size(ce);
1356
return ce;
1357
}
1358
@@ -1404,12 +1406,13 @@ int read_index_from(struct index_state *istate, const char *path)
1406
for (i = 0; i < istate->cache_nr; i++) {
1407
struct ondisk_cache_entry *disk_ce;
1408
struct cache_entry *ce;
1409
+ unsigned long consumed;
1410
1411
disk_ce = (struct ondisk_cache_entry *)((char *)mmap + src_offset);
1409
- ce = create_from_disk(disk_ce);
1412
+ ce = create_from_disk(disk_ce, &consumed);
1413
set_index_entry(istate, i, ce);
1414
1412
- src_offset += ondisk_ce_size(ce);
1415
+ src_offset += consumed;
1416
}
1417
istate->timestamp.sec = st.st_mtime;
1418
istate->timestamp.nsec = ST_MTIME_NSEC(st);