sha1_file.c: Avoid multiple calls to find_pack_entry().
We used to call find_pack_entry() twice from read_sha1_file() in order to avoid printing an error message, when the object did not exist. This is fixed by moving the call to error() to the only place it really could be called. Signed-off-by: Peter Eriksen <s022018@student.dtu.dk> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
e136f33b5f
commit
8276c0070f
19
sha1_file.c
19
sha1_file.c
@ -1469,21 +1469,20 @@ static void *read_packed_sha1(const unsigned char *sha1, char *type, unsigned lo
|
|||||||
{
|
{
|
||||||
struct pack_entry e;
|
struct pack_entry e;
|
||||||
|
|
||||||
if (!find_pack_entry(sha1, &e, NULL)) {
|
if (!find_pack_entry(sha1, &e, NULL))
|
||||||
error("cannot read sha1_file for %s", sha1_to_hex(sha1));
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
else
|
||||||
return unpack_entry(e.p, e.offset, type, size);
|
return unpack_entry(e.p, e.offset, type, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size)
|
void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size)
|
||||||
{
|
{
|
||||||
unsigned long mapsize;
|
unsigned long mapsize;
|
||||||
void *map, *buf;
|
void *map, *buf;
|
||||||
struct pack_entry e;
|
|
||||||
|
|
||||||
if (find_pack_entry(sha1, &e, NULL))
|
buf = read_packed_sha1(sha1, type, size);
|
||||||
return read_packed_sha1(sha1, type, size);
|
if (buf)
|
||||||
|
return buf;
|
||||||
map = map_sha1_file(sha1, &mapsize);
|
map = map_sha1_file(sha1, &mapsize);
|
||||||
if (map) {
|
if (map) {
|
||||||
buf = unpack_sha1_file(map, mapsize, type, size);
|
buf = unpack_sha1_file(map, mapsize, type, size);
|
||||||
@ -1491,9 +1490,7 @@ void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
reprepare_packed_git();
|
reprepare_packed_git();
|
||||||
if (find_pack_entry(sha1, &e, NULL))
|
return read_packed_sha1(sha1, type, size);
|
||||||
return read_packed_sha1(sha1, type, size);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void *read_object_with_reference(const unsigned char *sha1,
|
void *read_object_with_reference(const unsigned char *sha1,
|
||||||
@ -1781,6 +1778,8 @@ static void *repack_object(const unsigned char *sha1, unsigned long *objsize)
|
|||||||
|
|
||||||
/* need to unpack and recompress it by itself */
|
/* need to unpack and recompress it by itself */
|
||||||
unpacked = read_packed_sha1(sha1, type, &len);
|
unpacked = read_packed_sha1(sha1, type, &len);
|
||||||
|
if (!unpacked)
|
||||||
|
error("cannot read sha1_file for %s", sha1_to_hex(sha1));
|
||||||
|
|
||||||
hdrlen = sprintf(hdr, "%s %lu", type, len) + 1;
|
hdrlen = sprintf(hdr, "%s %lu", type, len) + 1;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user