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>
Peter Eriksen committed
Jan 22, 2007 at 21:29 UTC
8276c0070f8f8959ab4b6ec458fa0740e9abda9e
1 file changed
+9
-10
sha1_file.c
+9
-10
@@ -1469,21 +1469,20 @@ static void *read_packed_sha1(const unsigned char *sha1, char *type, unsigned lo
1469
{
1470
struct pack_entry e;
1471
1472
- if (!find_pack_entry(sha1, &e, NULL)) {
1473
- error("cannot read sha1_file for %s", sha1_to_hex(sha1));
1472
+ if (!find_pack_entry(sha1, &e, NULL))
1473
return NULL;
1475
- }
1476
- return unpack_entry(e.p, e.offset, type, size);
1474
+ else
1475
+ return unpack_entry(e.p, e.offset, type, size);
1476
}
1477
1478
void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size)
1479
{
1480
unsigned long mapsize;
1481
void *map, *buf;
1483
- struct pack_entry e;
1482
1485
- if (find_pack_entry(sha1, &e, NULL))
1486
- return read_packed_sha1(sha1, type, size);
1483
+ buf = read_packed_sha1(sha1, type, size);
1484
+ if (buf)
1485
+ return buf;
1486
map = map_sha1_file(sha1, &mapsize);
1487
if (map) {
1488
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
1490
return buf;
1491
}
1492
reprepare_packed_git();
1494
- if (find_pack_entry(sha1, &e, NULL))
1495
- return read_packed_sha1(sha1, type, size);
1496
- return NULL;
1493
+ return read_packed_sha1(sha1, type, size);
1494
}
1495
1496
void *read_object_with_reference(const unsigned char *sha1,
@@ -1781,6 +1778,8 @@ static void *repack_object(const unsigned char *sha1, unsigned long *objsize)
1778
1779
/* need to unpack and recompress it by itself */
1780
unpacked = read_packed_sha1(sha1, type, &len);
1781
+ if (!unpacked)
1782
+ error("cannot read sha1_file for %s", sha1_to_hex(sha1));
1783
1784
hdrlen = sprintf(hdr, "%s %lu", type, len) + 1;
1785