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 <gitster@pobox.com>

Junio C Hamano committed Apr 3, 2012 at 15:53 UTC f136f7bfe816b46ebabf5439f8e55f37097ca353
1 file changed +17 -9
read-cache.c
+17 -9
@@ -1605,13 +1605,10 @@ static void ce_smudge_racily_clean_entry(struct cache_entry *ce)
1605 }
1606 }
1607
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)
1611 {
1610 - int size = ondisk_ce_size(ce);
1611 - struct ondisk_cache_entry *ondisk = xcalloc(1, size);
1612 - char *name;
1613 - int result;
1614 -
1612 ondisk->ctime.sec = htonl(ce->ce_ctime.sec);
1613 ondisk->mtime.sec = htonl(ce->ce_mtime.sec);
1614 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)
1625 struct ondisk_cache_entry_extended *ondisk2;
1626 ondisk2 = (struct ondisk_cache_entry_extended *)ondisk;
1627 ondisk2->flags2 = htons((ce->ce_flags & CE_EXTENDED_FLAGS) >> 16);
1631 - name = ondisk2->name;
1628 + return ondisk2->name;
1629 }
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);
1643 memcpy(name, ce->name, ce_namelen(ce));
1644
1645 result = ce_write(c, fd, ondisk, size);