read-cache.c: move code to copy ondisk to incore 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 3fc22b53313ff035da145b2cb59e587ff3868654
1 file changed +25 -19
read-cache.c
+25 -19
@@ -1307,6 +1307,30 @@ static inline uint32_t ntoh_l_force_align(void *p)
1307 #define ntoh_l(var) ntoh_l_force_align(&(var))
1308 #endif
1309
1310 +static struct cache_entry *cache_entry_from_ondisk(struct ondisk_cache_entry *ondisk,
1311 + unsigned int flags,
1312 + const char *name,
1313 + size_t len)
1314 +{
1315 + struct cache_entry *ce = xmalloc(cache_entry_size(len));
1316 +
1317 + ce->ce_ctime.sec = ntoh_l(ondisk->ctime.sec);
1318 + ce->ce_mtime.sec = ntoh_l(ondisk->mtime.sec);
1319 + ce->ce_ctime.nsec = ntoh_l(ondisk->ctime.nsec);
1320 + ce->ce_mtime.nsec = ntoh_l(ondisk->mtime.nsec);
1321 + ce->ce_dev = ntoh_l(ondisk->dev);
1322 + ce->ce_ino = ntoh_l(ondisk->ino);
1323 + ce->ce_mode = ntoh_l(ondisk->mode);
1324 + ce->ce_uid = ntoh_l(ondisk->uid);
1325 + ce->ce_gid = ntoh_l(ondisk->gid);
1326 + ce->ce_size = ntoh_l(ondisk->size);
1327 + ce->ce_flags = flags;
1328 + hashcpy(ce->sha1, ondisk->sha1);
1329 + memcpy(ce->name, name, len);
1330 + ce->name[len] = '\0';
1331 + return ce;
1332 +}
1333 +
1334 static struct cache_entry *create_from_disk(struct ondisk_cache_entry *ondisk,
1335 unsigned long *ent_size)
1336 {
@@ -1335,25 +1359,7 @@ static struct cache_entry *create_from_disk(struct ondisk_cache_entry *ondisk,
1359
1360 if (len == CE_NAMEMASK)
1361 len = strlen(name);
1338 -
1339 - ce = xmalloc(cache_entry_size(len));
1340 -
1341 - ce->ce_ctime.sec = ntoh_l(ondisk->ctime.sec);
1342 - ce->ce_mtime.sec = ntoh_l(ondisk->mtime.sec);
1343 - ce->ce_ctime.nsec = ntoh_l(ondisk->ctime.nsec);
1344 - ce->ce_mtime.nsec = ntoh_l(ondisk->mtime.nsec);
1345 - ce->ce_dev = ntoh_l(ondisk->dev);
1346 - ce->ce_ino = ntoh_l(ondisk->ino);
1347 - ce->ce_mode = ntoh_l(ondisk->mode);
1348 - ce->ce_uid = ntoh_l(ondisk->uid);
1349 - ce->ce_gid = ntoh_l(ondisk->gid);
1350 - ce->ce_size = ntoh_l(ondisk->size);
1351 - ce->ce_flags = flags;
1352 -
1353 - hashcpy(ce->sha1, ondisk->sha1);
1354 -
1355 - memcpy(ce->name, name, len);
1356 - ce->name[len] = '\0';
1362 + ce = cache_entry_from_ondisk(ondisk, flags, name, len);
1363 *ent_size = ondisk_ce_size(ce);
1364 return ce;
1365 }