sha1_object_info(): be consistent with read_sha1_file()
We used to try loose objects first with sha1_object_info(), but packed objects first with read_sha1_file(). Now, prefer packed objects over loose ones with sha1_object_info(), too. Usually the old behaviour would pose no problem, but when you tried to fix a fscked up repository by inserting a known-good pack, git cat-file $(git cat-file -t <sha1>) <sha1> could fail, even when git cat-file blob <sha1> would _not_ fail. Worse, a repack would fail, too. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
1d541c120b
commit
f0df4ed562
33
sha1_file.c
33
sha1_file.c
@ -1261,7 +1261,7 @@ struct packed_git *find_sha1_pack(const unsigned char *sha1,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int sha1_object_info(const unsigned char *sha1, char *type, unsigned long *sizep)
|
static int sha1_loose_object_info(const unsigned char *sha1, char *type, unsigned long *sizep)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
unsigned long mapsize, size;
|
unsigned long mapsize, size;
|
||||||
@ -1270,20 +1270,8 @@ int sha1_object_info(const unsigned char *sha1, char *type, unsigned long *sizep
|
|||||||
char hdr[128];
|
char hdr[128];
|
||||||
|
|
||||||
map = map_sha1_file(sha1, &mapsize);
|
map = map_sha1_file(sha1, &mapsize);
|
||||||
if (!map) {
|
if (!map)
|
||||||
struct pack_entry e;
|
|
||||||
|
|
||||||
if (!find_pack_entry(sha1, &e, NULL)) {
|
|
||||||
reprepare_packed_git();
|
|
||||||
if (!find_pack_entry(sha1, &e, NULL))
|
|
||||||
return error("unable to find %s", sha1_to_hex(sha1));
|
return error("unable to find %s", sha1_to_hex(sha1));
|
||||||
}
|
|
||||||
if (use_packed_git(e.p))
|
|
||||||
die("cannot map packed file");
|
|
||||||
status = packed_object_info(e.p, e.offset, type, sizep);
|
|
||||||
unuse_packed_git(e.p);
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
|
if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
|
||||||
status = error("unable to unpack %s header",
|
status = error("unable to unpack %s header",
|
||||||
sha1_to_hex(sha1));
|
sha1_to_hex(sha1));
|
||||||
@ -1299,6 +1287,23 @@ int sha1_object_info(const unsigned char *sha1, char *type, unsigned long *sizep
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sha1_object_info(const unsigned char *sha1, char *type, unsigned long *sizep)
|
||||||
|
{
|
||||||
|
int status;
|
||||||
|
struct pack_entry e;
|
||||||
|
|
||||||
|
if (!find_pack_entry(sha1, &e, NULL)) {
|
||||||
|
reprepare_packed_git();
|
||||||
|
if (!find_pack_entry(sha1, &e, NULL))
|
||||||
|
return sha1_loose_object_info(sha1, type, sizep);
|
||||||
|
}
|
||||||
|
if (use_packed_git(e.p))
|
||||||
|
die("cannot map packed file");
|
||||||
|
status = packed_object_info(e.p, e.offset, type, sizep);
|
||||||
|
unuse_packed_git(e.p);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
static void *read_packed_sha1(const unsigned char *sha1, char *type, unsigned long *size)
|
static void *read_packed_sha1(const unsigned char *sha1, char *type, unsigned long *size)
|
||||||
{
|
{
|
||||||
struct pack_entry e;
|
struct pack_entry e;
|
||||||
|
Loading…
Reference in New Issue
Block a user