}
static void *map_sha1_file_internal(const unsigned char *sha1,
- unsigned long *size,
- int say_error)
+ unsigned long *size)
{
struct stat st;
void *map;
char *filename = find_sha1_file(sha1, &st);
if (!filename) {
- if (say_error)
- error("cannot map sha1 file %s", sha1_to_hex(sha1));
return NULL;
}
break;
/* Fallthrough */
case 0:
- if (say_error)
- perror(filename);
return NULL;
}
return map;
}
-void *map_sha1_file(const unsigned char *sha1, unsigned long *size)
-{
- return map_sha1_file_internal(sha1, size, 1);
-}
-
int unpack_sha1_header(z_stream *stream, void *map, unsigned long mapsize, void *buffer, unsigned long size)
{
/* Get the data stream */
z_stream stream;
char hdr[128];
- map = map_sha1_file_internal(sha1, &mapsize, 0);
+ map = map_sha1_file_internal(sha1, &mapsize);
if (!map) {
struct pack_entry e;
{
unsigned long mapsize;
void *map, *buf;
+ struct pack_entry e;
- map = map_sha1_file_internal(sha1, &mapsize, 0);
+ if (find_pack_entry(sha1, &e))
+ return read_packed_sha1(sha1, type, size);
+ map = map_sha1_file_internal(sha1, &mapsize);
if (map) {
buf = unpack_sha1_file(map, mapsize, type, size);
munmap(map, mapsize);
return buf;
}
- return read_packed_sha1(sha1, type, size);
+ return NULL;
}
void *read_object_with_reference(const unsigned char *sha1,
ssize_t size;
unsigned long objsize;
int posn = 0;
- char *buf = map_sha1_file_internal(sha1, &objsize, 0);
+ void *buf = map_sha1_file_internal(sha1, &objsize);
z_stream stream;
if (!buf) {
unsigned char *unpacked;
stream.avail_out = size;
/* First header.. */
- stream.next_in = hdr;
+ stream.next_in = (void *)hdr;
stream.avail_in = hdrlen;
while (deflate(&stream, 0) == Z_OK)
/* nothing */;
struct stat st;
struct pack_entry e;
- if (find_sha1_file(sha1, &st))
+ if (find_pack_entry(sha1, &e))
return 1;
- return find_pack_entry(sha1, &e);
+ return find_sha1_file(sha1, &st) ? 1 : 0;
}
int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, const char *type)