cache-tree: convert remnants to struct object_id

Convert the remaining portions of cache-tree.c to use struct object_id. Convert several instances of 20 to use the_hash_algo instead. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Mar 12, 2018 at 02:27 UTC 6dcb462530b1142a0fc1ad326dfd68ce1cde7387
1 file changed +15 -14
cache-tree.c
+15 -14
@@ -320,7 +320,7 @@ static int update_one(struct cache_tree *it,
320 struct cache_tree_sub *sub = NULL;
321 const char *path, *slash;
322 int pathlen, entlen;
323 - const unsigned char *sha1;
323 + const struct object_id *oid;
324 unsigned mode;
325 int expected_missing = 0;
326 int contains_ita = 0;
@@ -338,7 +338,7 @@ static int update_one(struct cache_tree *it,
338 die("cache-tree.c: '%.*s' in '%s' not found",
339 entlen, path + baselen, path);
340 i += sub->count;
341 - sha1 = sub->cache_tree->oid.hash;
341 + oid = &sub->cache_tree->oid;
342 mode = S_IFDIR;
343 contains_ita = sub->cache_tree->entry_count < 0;
344 if (contains_ita) {
@@ -347,19 +347,19 @@ static int update_one(struct cache_tree *it,
347 }
348 }
349 else {
350 - sha1 = ce->oid.hash;
350 + oid = &ce->oid;
351 mode = ce->ce_mode;
352 entlen = pathlen - baselen;
353 i++;
354 }
355
356 - if (is_null_sha1(sha1) ||
357 - (mode != S_IFGITLINK && !missing_ok && !has_sha1_file(sha1))) {
356 + if (is_null_oid(oid) ||
357 + (mode != S_IFGITLINK && !missing_ok && !has_object_file(oid))) {
358 strbuf_release(&buffer);
359 if (expected_missing)
360 return -1;
361 return error("invalid object %06o %s for '%.*s'",
362 - mode, sha1_to_hex(sha1), entlen+baselen, path);
362 + mode, oid_to_hex(oid), entlen+baselen, path);
363 }
364
365 /*
@@ -385,12 +385,12 @@ static int update_one(struct cache_tree *it,
385 /*
386 * "sub" can be an empty tree if all subentries are i-t-a.
387 */
388 - if (contains_ita && !hashcmp(sha1, EMPTY_TREE_SHA1_BIN))
388 + if (contains_ita && !oidcmp(oid, &empty_tree_oid))
389 continue;
390
391 strbuf_grow(&buffer, entlen + 100);
392 strbuf_addf(&buffer, "%o %.*s%c", mode, entlen, path + baselen, '\0');
393 - strbuf_add(&buffer, sha1, 20);
393 + strbuf_add(&buffer, oid->hash, the_hash_algo->rawsz);
394
395 #if DEBUG
396 fprintf(stderr, "cache-tree update-one %o %.*s\n",
@@ -401,7 +401,7 @@ static int update_one(struct cache_tree *it,
401 if (repair) {
402 struct object_id oid;
403 hash_object_file(buffer.buf, buffer.len, tree_type, &oid);
404 - if (has_sha1_file(oid.hash))
404 + if (has_object_file(&oid))
405 oidcpy(&it->oid, &oid);
406 else
407 to_invalidate = 1;
@@ -465,7 +465,7 @@ static void write_one(struct strbuf *buffer, struct cache_tree *it,
465 #endif
466
467 if (0 <= it->entry_count) {
468 - strbuf_add(buffer, it->oid.hash, 20);
468 + strbuf_add(buffer, it->oid.hash, the_hash_algo->rawsz);
469 }
470 for (i = 0; i < it->subtree_nr; i++) {
471 struct cache_tree_sub *down = it->down[i];
@@ -492,6 +492,7 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
492 char *ep;
493 struct cache_tree *it;
494 int i, subtree_nr;
495 + const unsigned rawsz = the_hash_algo->rawsz;
496
497 it = NULL;
498 /* skip name, but make sure name exists */
@@ -520,11 +521,11 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
521 goto free_return;
522 buf++; size--;
523 if (0 <= it->entry_count) {
523 - if (size < 20)
524 + if (size < rawsz)
525 goto free_return;
525 - hashcpy(it->oid.hash, (const unsigned char*)buf);
526 - buf += 20;
527 - size -= 20;
526 + memcpy(it->oid.hash, (const unsigned char*)buf, rawsz);
527 + buf += rawsz;
528 + size -= rawsz;
529 }
530
531 #if DEBUG