Skip to content

Commit f136f7b

Browse files
committed
read-cache.c: move code to copy incore to ondisk cache to a helper function
This makes the change in a later patch look less scary. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3fc22b5 commit f136f7b

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

read-cache.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,13 +1605,10 @@ static void ce_smudge_racily_clean_entry(struct cache_entry *ce)
16051605
}
16061606
}
16071607

1608-
static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce)
1608+
/* Copy miscellaneous fields but not the name */
1609+
static char *copy_cache_entry_to_ondisk(struct ondisk_cache_entry *ondisk,
1610+
struct cache_entry *ce)
16091611
{
1610-
int size = ondisk_ce_size(ce);
1611-
struct ondisk_cache_entry *ondisk = xcalloc(1, size);
1612-
char *name;
1613-
int result;
1614-
16151612
ondisk->ctime.sec = htonl(ce->ce_ctime.sec);
16161613
ondisk->mtime.sec = htonl(ce->ce_mtime.sec);
16171614
ondisk->ctime.nsec = htonl(ce->ce_ctime.nsec);
@@ -1628,10 +1625,21 @@ static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce)
16281625
struct ondisk_cache_entry_extended *ondisk2;
16291626
ondisk2 = (struct ondisk_cache_entry_extended *)ondisk;
16301627
ondisk2->flags2 = htons((ce->ce_flags & CE_EXTENDED_FLAGS) >> 16);
1631-
name = ondisk2->name;
1628+
return ondisk2->name;
16321629
}
1633-
else
1634-
name = ondisk->name;
1630+
else {
1631+
return ondisk->name;
1632+
}
1633+
}
1634+
1635+
static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce)
1636+
{
1637+
int size = ondisk_ce_size(ce);
1638+
struct ondisk_cache_entry *ondisk = xcalloc(1, size);
1639+
char *name;
1640+
int result;
1641+
1642+
name = copy_cache_entry_to_ondisk(ondisk, ce);
16351643
memcpy(name, ce->name, ce_namelen(ce));
16361644

16371645
result = ce_write(c, fd, ondisk, size);

0 commit comments

Comments
 (0)