Skip to content

Commit 936f53d

Browse files
committed
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 <[email protected]>
1 parent d60c49c commit 936f53d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

read-cache.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,8 @@ static inline uint32_t ntoh_l_force_align(void *p)
13051305
#define ntoh_l(var) ntoh_l_force_align(&(var))
13061306
#endif
13071307

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)
13091310
{
13101311
struct cache_entry *ce;
13111312
size_t len;
@@ -1351,6 +1352,7 @@ static struct cache_entry *create_from_disk(struct ondisk_cache_entry *ondisk)
13511352

13521353
memcpy(ce->name, name, len);
13531354
ce->name[len] = '\0';
1355+
*ent_size = ondisk_ce_size(ce);
13541356
return ce;
13551357
}
13561358

@@ -1404,12 +1406,13 @@ int read_index_from(struct index_state *istate, const char *path)
14041406
for (i = 0; i < istate->cache_nr; i++) {
14051407
struct ondisk_cache_entry *disk_ce;
14061408
struct cache_entry *ce;
1409+
unsigned long consumed;
14071410

14081411
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);
14101413
set_index_entry(istate, i, ce);
14111414

1412-
src_offset += ondisk_ce_size(ce);
1415+
src_offset += consumed;
14131416
}
14141417
istate->timestamp.sec = st.st_mtime;
14151418
istate->timestamp.nsec = ST_MTIME_NSEC(st);

0 commit comments

Comments
 (0)