sha1_file: convert force_object_loose to object_id

Convert the definition and declaration of force_object_loose to struct object_id and adjust usage of this function. Signed-off-by: Patryk Obara <patryk.obara@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patryk Obara committed Jan 28, 2018 at 01:13 UTC 4bdb70a4f73369af39989a3ab5732825600dc914
3 files changed +8 -7
builtin/pack-objects.c
+1 -1
@@ -2768,7 +2768,7 @@ static void loosen_unused_packed_objects(struct rev_info *revs)
2768 if (!packlist_find(&to_pack, oid.hash, NULL) &&
2769 !has_sha1_pack_kept_or_nonlocal(&oid) &&
2770 !loosened_object_can_be_discarded(&oid, p->mtime))
2771 - if (force_object_loose(oid.hash, p->mtime))
2771 + if (force_object_loose(&oid, p->mtime))
2772 die("unable to force loose object");
2773 }
2774 }
cache.h
+2 -1
@@ -1248,7 +1248,8 @@ extern int hash_sha1_file_literally(const void *buf, unsigned long len, const ch
1248 extern int pretend_object_file(void *, unsigned long, enum object_type,
1249 struct object_id *oid);
1250
1251 -extern int force_object_loose(const unsigned char *sha1, time_t mtime);
1251 +extern int force_object_loose(const struct object_id *oid, time_t mtime);
1252 +
1253 extern int git_open_cloexec(const char *name, int flags);
1254 #define git_open(name) git_open_cloexec(name, O_RDONLY)
1255 extern void *map_sha1_file(const unsigned char *sha1, unsigned long *size);
sha1_file.c
+5 -5
@@ -1670,7 +1670,7 @@ cleanup:
1670 return status;
1671 }
1672
1673 -int force_object_loose(const unsigned char *sha1, time_t mtime)
1673 +int force_object_loose(const struct object_id *oid, time_t mtime)
1674 {
1675 void *buf;
1676 unsigned long len;
@@ -1679,13 +1679,13 @@ int force_object_loose(const unsigned char *sha1, time_t mtime)
1679 int hdrlen;
1680 int ret;
1681
1682 - if (has_loose_object(sha1))
1682 + if (has_loose_object(oid->hash))
1683 return 0;
1684 - buf = read_object(sha1, &type, &len);
1684 + buf = read_object(oid->hash, &type, &len);
1685 if (!buf)
1686 - return error("cannot read sha1_file for %s", sha1_to_hex(sha1));
1686 + return error("cannot read sha1_file for %s", oid_to_hex(oid));
1687 hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(type), len) + 1;
1688 - ret = write_loose_object(sha1, hdr, hdrlen, buf, len, mtime);
1688 + ret = write_loose_object(oid->hash, hdr, hdrlen, buf, len, mtime);
1689 free(buf);
1690
1691 return ret;