sha1_file: remove read_packed_sha1()

Use read_object() in its place instead. This avoids duplication of code. This makes force_object_loose() slightly slower (because of a redundant check of loose object storage), but only in the error case. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Aug 11, 2017 at 13:36 UTC 789bf26b07dbdd5985e30136f4ba638bb9c7f00e
1 file changed +1 -25
sha1_file.c
+1 -25
@@ -3062,30 +3062,6 @@ int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)
3062 return type;
3063 }
3064
3065 -static void *read_packed_sha1(const unsigned char *sha1,
3066 - enum object_type *type, unsigned long *size)
3067 -{
3068 - struct pack_entry e;
3069 - void *data;
3070 -
3071 - if (!find_pack_entry(sha1, &e))
3072 - return NULL;
3073 - data = cache_or_unpack_entry(e.p, e.offset, size, type);
3074 - if (!data) {
3075 - /*
3076 - * We're probably in deep shit, but let's try to fetch
3077 - * the required object anyway from another pack or loose.
3078 - * This should happen only in the presence of a corrupted
3079 - * pack, and is better than failing outright.
3080 - */
3081 - error("failed to read object %s at offset %"PRIuMAX" from %s",
3082 - sha1_to_hex(sha1), (uintmax_t)e.offset, e.p->pack_name);
3083 - mark_bad_packed_object(e.p, sha1);
3084 - data = read_object(sha1, type, size);
3085 - }
3086 - return data;
3087 -}
3088 -
3065 int pretend_sha1_file(void *buf, unsigned long len, enum object_type type,
3066 unsigned char *sha1)
3067 {
@@ -3468,7 +3444,7 @@ int force_object_loose(const unsigned char *sha1, time_t mtime)
3444
3445 if (has_loose_object(sha1))
3446 return 0;
3471 - buf = read_packed_sha1(sha1, &type, &len);
3447 + buf = read_object(sha1, &type, &len);
3448 if (!buf)
3449 return error("cannot read sha1_file for %s", sha1_to_hex(sha1));
3450 hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(type), len) + 1;