Skip to content

Commit 789bf26

Browse files
jonathantanmygitster
authored andcommitted
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>
1 parent 3ab0fb0 commit 789bf26

File tree

1 file changed

+1
-25
lines changed

1 file changed

+1
-25
lines changed

sha1_file.c

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3062,30 +3062,6 @@ int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)
30623062
return type;
30633063
}
30643064

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-
30893065
int pretend_sha1_file(void *buf, unsigned long len, enum object_type type,
30903066
unsigned char *sha1)
30913067
{
@@ -3468,7 +3444,7 @@ int force_object_loose(const unsigned char *sha1, time_t mtime)
34683444

34693445
if (has_loose_object(sha1))
34703446
return 0;
3471-
buf = read_packed_sha1(sha1, &type, &len);
3447+
buf = read_object(sha1, &type, &len);
34723448
if (!buf)
34733449
return error("cannot read sha1_file for %s", sha1_to_hex(sha1));
34743450
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(type), len) + 1;

0 commit comments

Comments
 (0)