sha1-file: convert freshen functions to object_id

Convert the various functions for freshening objects and has_loose_object_nonlocal to use struct object_id. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed May 2, 2018 at 00:25 UTC 6862ebbfcbdd44b68dbdcfecd432432bdf22b2e5
3 files changed +20 -20
builtin/pack-objects.c
+1 -1
@@ -1012,7 +1012,7 @@ static int want_object_in_pack(const struct object_id *oid,
1012 int want;
1013 struct list_head *pos;
1014
1015 - if (!exclude && local && has_loose_object_nonlocal(oid->hash))
1015 + if (!exclude && local && has_loose_object_nonlocal(oid))
1016 return 0;
1017
1018 /*
cache.h
+1 -1
@@ -1275,7 +1275,7 @@ extern int has_object_file_with_flags(const struct object_id *oid, int flags);
1275 * with the specified name. This function does not respect replace
1276 * references.
1277 */
1278 -extern int has_loose_object_nonlocal(const unsigned char *sha1);
1278 +extern int has_loose_object_nonlocal(const struct object_id *oid);
1279
1280 extern void assert_oid_type(const struct object_id *oid, enum object_type expect);
1281
sha1_file.c
+18 -18
@@ -709,42 +709,42 @@ int check_and_freshen_file(const char *fn, int freshen)
709 return 1;
710 }
711
712 -static int check_and_freshen_local(const unsigned char *sha1, int freshen)
712 +static int check_and_freshen_local(const struct object_id *oid, int freshen)
713 {
714 static struct strbuf buf = STRBUF_INIT;
715
716 strbuf_reset(&buf);
717 - sha1_file_name(the_repository, &buf, sha1);
717 + sha1_file_name(the_repository, &buf, oid->hash);
718
719 return check_and_freshen_file(buf.buf, freshen);
720 }
721
722 -static int check_and_freshen_nonlocal(const unsigned char *sha1, int freshen)
722 +static int check_and_freshen_nonlocal(const struct object_id *oid, int freshen)
723 {
724 struct alternate_object_database *alt;
725 prepare_alt_odb(the_repository);
726 for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next) {
727 - const char *path = alt_sha1_path(alt, sha1);
727 + const char *path = alt_sha1_path(alt, oid->hash);
728 if (check_and_freshen_file(path, freshen))
729 return 1;
730 }
731 return 0;
732 }
733
734 -static int check_and_freshen(const unsigned char *sha1, int freshen)
734 +static int check_and_freshen(const struct object_id *oid, int freshen)
735 {
736 - return check_and_freshen_local(sha1, freshen) ||
737 - check_and_freshen_nonlocal(sha1, freshen);
736 + return check_and_freshen_local(oid, freshen) ||
737 + check_and_freshen_nonlocal(oid, freshen);
738 }
739
740 -int has_loose_object_nonlocal(const unsigned char *sha1)
740 +int has_loose_object_nonlocal(const struct object_id *oid)
741 {
742 - return check_and_freshen_nonlocal(sha1, 0);
742 + return check_and_freshen_nonlocal(oid, 0);
743 }
744
745 -static int has_loose_object(const unsigned char *sha1)
745 +static int has_loose_object(const struct object_id *oid)
746 {
747 - return check_and_freshen(sha1, 0);
747 + return check_and_freshen(oid, 0);
748 }
749
750 static void mmap_limit_check(size_t length)
@@ -1661,15 +1661,15 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
1661 return finalize_object_file(tmp_file.buf, filename.buf);
1662 }
1663
1664 -static int freshen_loose_object(const unsigned char *sha1)
1664 +static int freshen_loose_object(const struct object_id *oid)
1665 {
1666 - return check_and_freshen(sha1, 1);
1666 + return check_and_freshen(oid, 1);
1667 }
1668
1669 -static int freshen_packed_object(const unsigned char *sha1)
1669 +static int freshen_packed_object(const struct object_id *oid)
1670 {
1671 struct pack_entry e;
1672 - if (!find_pack_entry(the_repository, sha1, &e))
1672 + if (!find_pack_entry(the_repository, oid->hash, &e))
1673 return 0;
1674 if (e.p->freshened)
1675 return 1;
@@ -1689,7 +1689,7 @@ int write_object_file(const void *buf, unsigned long len, const char *type,
1689 * it out into .git/objects/??/?{38} file.
1690 */
1691 write_object_file_prepare(buf, len, type, oid, hdr, &hdrlen);
1692 - if (freshen_packed_object(oid->hash) || freshen_loose_object(oid->hash))
1692 + if (freshen_packed_object(oid) || freshen_loose_object(oid))
1693 return 0;
1694 return write_loose_object(oid, hdr, hdrlen, buf, len, 0);
1695 }
@@ -1708,7 +1708,7 @@ int hash_object_file_literally(const void *buf, unsigned long len,
1708
1709 if (!(flags & HASH_WRITE_OBJECT))
1710 goto cleanup;
1711 - if (freshen_packed_object(oid->hash) || freshen_loose_object(oid->hash))
1711 + if (freshen_packed_object(oid) || freshen_loose_object(oid))
1712 goto cleanup;
1713 status = write_loose_object(oid, header, hdrlen, buf, len, 0);
1714
@@ -1726,7 +1726,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
1726 int hdrlen;
1727 int ret;
1728
1729 - if (has_loose_object(oid->hash))
1729 + if (has_loose_object(oid))
1730 return 0;
1731 buf = read_object(oid->hash, &type, &len);
1732 if (!buf)