Merge branch 'jt/sha1-file-cleanup'
Preparatory code clean-up. * jt/sha1-file-cleanup: sha1_file: remove read_packed_sha1() sha1_file: set whence in storage-specific info fnmaint
commit
fa2a4bba2c
39
sha1_file.c
39
sha1_file.c
|
@ -2444,6 +2444,9 @@ int packed_object_info(struct packed_git *p, off_t obj_offset,
|
||||||
hashclr(oi->delta_base_sha1);
|
hashclr(oi->delta_base_sha1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
oi->whence = in_delta_base_cache(p, obj_offset) ? OI_DBCACHED :
|
||||||
|
OI_PACKED;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
unuse_pack(&w_curs);
|
unuse_pack(&w_curs);
|
||||||
return type;
|
return type;
|
||||||
|
@ -2963,6 +2966,7 @@ static int sha1_loose_object_info(const unsigned char *sha1,
|
||||||
if (oi->sizep == &size_scratch)
|
if (oi->sizep == &size_scratch)
|
||||||
oi->sizep = NULL;
|
oi->sizep = NULL;
|
||||||
strbuf_release(&hdrbuf);
|
strbuf_release(&hdrbuf);
|
||||||
|
oi->whence = OI_LOOSE;
|
||||||
return (status < 0) ? status : 0;
|
return (status < 0) ? status : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3000,10 +3004,8 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
|
||||||
|
|
||||||
if (!find_pack_entry(real, &e)) {
|
if (!find_pack_entry(real, &e)) {
|
||||||
/* Most likely it's a loose object. */
|
/* Most likely it's a loose object. */
|
||||||
if (!sha1_loose_object_info(real, oi, flags)) {
|
if (!sha1_loose_object_info(real, oi, flags))
|
||||||
oi->whence = OI_LOOSE;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
/* Not a loose object; someone else may have just packed it. */
|
/* Not a loose object; someone else may have just packed it. */
|
||||||
if (flags & OBJECT_INFO_QUICK) {
|
if (flags & OBJECT_INFO_QUICK) {
|
||||||
|
@ -3026,10 +3028,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
|
||||||
if (rtype < 0) {
|
if (rtype < 0) {
|
||||||
mark_bad_packed_object(e.p, real);
|
mark_bad_packed_object(e.p, real);
|
||||||
return sha1_object_info_extended(real, oi, 0);
|
return sha1_object_info_extended(real, oi, 0);
|
||||||
} else if (in_delta_base_cache(e.p, e.offset)) {
|
} else if (oi->whence == OI_PACKED) {
|
||||||
oi->whence = OI_DBCACHED;
|
|
||||||
} else {
|
|
||||||
oi->whence = OI_PACKED;
|
|
||||||
oi->u.packed.offset = e.offset;
|
oi->u.packed.offset = e.offset;
|
||||||
oi->u.packed.pack = e.p;
|
oi->u.packed.pack = e.p;
|
||||||
oi->u.packed.is_delta = (rtype == OBJ_REF_DELTA ||
|
oi->u.packed.is_delta = (rtype == OBJ_REF_DELTA ||
|
||||||
|
@ -3053,30 +3052,6 @@ int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *read_packed_sha1(const unsigned char *sha1,
|
|
||||||
enum object_type *type, unsigned long *size)
|
|
||||||
{
|
|
||||||
struct pack_entry e;
|
|
||||||
void *data;
|
|
||||||
|
|
||||||
if (!find_pack_entry(sha1, &e))
|
|
||||||
return NULL;
|
|
||||||
data = cache_or_unpack_entry(e.p, e.offset, size, type);
|
|
||||||
if (!data) {
|
|
||||||
/*
|
|
||||||
* We're probably in deep shit, but let's try to fetch
|
|
||||||
* the required object anyway from another pack or loose.
|
|
||||||
* This should happen only in the presence of a corrupted
|
|
||||||
* pack, and is better than failing outright.
|
|
||||||
*/
|
|
||||||
error("failed to read object %s at offset %"PRIuMAX" from %s",
|
|
||||||
sha1_to_hex(sha1), (uintmax_t)e.offset, e.p->pack_name);
|
|
||||||
mark_bad_packed_object(e.p, sha1);
|
|
||||||
data = read_object(sha1, type, size);
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
int pretend_sha1_file(void *buf, unsigned long len, enum object_type type,
|
int pretend_sha1_file(void *buf, unsigned long len, enum object_type type,
|
||||||
unsigned char *sha1)
|
unsigned char *sha1)
|
||||||
{
|
{
|
||||||
|
@ -3459,7 +3434,7 @@ int force_object_loose(const unsigned char *sha1, time_t mtime)
|
||||||
|
|
||||||
if (has_loose_object(sha1))
|
if (has_loose_object(sha1))
|
||||||
return 0;
|
return 0;
|
||||||
buf = read_packed_sha1(sha1, &type, &len);
|
buf = read_object(sha1, &type, &len);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return error("cannot read sha1_file for %s", sha1_to_hex(sha1));
|
return error("cannot read sha1_file for %s", sha1_to_hex(sha1));
|
||||||
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(type), len) + 1;
|
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(type), len) + 1;
|
||||||
|
|
Loading…
Reference in New Issue