return NULL;
}
-#define PACK_MAX_SZ (1<<26)
static int pack_used_ctr;
static unsigned long pack_mapped;
struct packed_git *packed_git;
struct pack_header *hdr;
pack_mapped += p->pack_size;
- while (PACK_MAX_SZ < pack_mapped && unuse_one_packed_git())
+ while (packed_git_limit < pack_mapped && unuse_one_packed_git())
; /* nothing */
fd = open(p->pack_name, O_RDONLY);
if (fd < 0)
for (;;) {
switch (kind) {
default:
- die("corrupted pack file %s containing object of kind %d",
+ die("pack %s contains unknown object type %d",
p->pack_name, kind);
case OBJ_COMMIT:
case OBJ_TREE:
strcpy(type, type_names[kind]);
break;
default:
- die("corrupted pack file %s containing object of kind %d",
+ die("pack %s contains unknown object type %d",
p->pack_name, kind);
}
if (sizep)
unsigned long result_size, base_size, base_offset;
offset = get_delta_base(p, offset, kind, obj_offset, &base_offset);
- base = unpack_entry_gently(p, base_offset, type, &base_size);
+ base = unpack_entry(p, base_offset, type, &base_size);
if (!base)
die("failed to read delta base object at %lu from %s",
base_offset, p->pack_name);
return result;
}
-static void *unpack_entry(struct pack_entry *entry,
+void *unpack_entry(struct packed_git *p, unsigned long offset,
char *type, unsigned long *sizep)
{
- struct packed_git *p = entry->p;
+ unsigned long size, obj_offset = offset;
+ enum object_type kind;
void *retval;
if (use_packed_git(p))
die("cannot map packed file");
- retval = unpack_entry_gently(p, entry->offset, type, sizep);
- unuse_packed_git(p);
- if (!retval)
- die("corrupted pack file %s", p->pack_name);
- return retval;
-}
-
-/* The caller is responsible for use_packed_git()/unuse_packed_git() pair */
-void *unpack_entry_gently(struct packed_git *p, unsigned long offset,
- char *type, unsigned long *sizep)
-{
- unsigned long size, obj_offset = offset;
- enum object_type kind;
-
offset = unpack_object_header(p, offset, &kind, &size);
switch (kind) {
case OBJ_OFS_DELTA:
case OBJ_REF_DELTA:
- return unpack_delta_entry(p, offset, size, kind, obj_offset, type, sizep);
+ retval = unpack_delta_entry(p, offset, size, kind, obj_offset, type, sizep);
+ break;
case OBJ_COMMIT:
case OBJ_TREE:
case OBJ_BLOB:
case OBJ_TAG:
strcpy(type, type_names[kind]);
*sizep = size;
- return unpack_compressed_entry(p, offset, size);
+ retval = unpack_compressed_entry(p, offset, size);
+ break;
default:
- return NULL;
+ die("unknown object type %i in %s", kind, p->pack_name);
}
+ unuse_packed_git(p);
+ return retval;
}
int num_packed_objects(const struct packed_git *p)
}
-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;
unsigned long mapsize, size;
char hdr[128];
map = map_sha1_file(sha1, &mapsize);
- 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));
- }
- 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 (!map)
+ return error("unable to find %s", sha1_to_hex(sha1));
if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
status = error("unable to unpack %s header",
sha1_to_hex(sha1));
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)
{
struct pack_entry e;
error("cannot read sha1_file for %s", sha1_to_hex(sha1));
return NULL;
}
- return unpack_entry(&e, type, size);
+ return unpack_entry(e.p, e.offset, type, size);
}
void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size)
unlink(tmpfile);
if (ret) {
if (ret != EEXIST) {
- fprintf(stderr, "unable to write sha1 filename %s: %s\n", filename, strerror(ret));
- return -1;
+ return error("unable to write sha1 filename %s: %s\n", filename, strerror(ret));
}
/* FIXME!!! Collision check here ? */
}
}
if (errno != ENOENT) {
- fprintf(stderr, "sha1 file %s: %s\n", filename, strerror(errno));
- return -1;
+ return error("sha1 file %s: %s\n", filename, strerror(errno));
}
snprintf(tmpfile, sizeof(tmpfile), "%s/obj_XXXXXX", get_object_directory());
fd = mkstemp(tmpfile);
if (fd < 0) {
- fprintf(stderr, "unable to create temporary sha1 filename %s: %s\n", tmpfile, strerror(errno));
- return -1;
+ if (errno == EPERM)
+ return error("insufficient permission for adding an object to repository database %s\n", get_object_directory());
+ else
+ return error("unable to create temporary sha1 filename %s: %s\n", tmpfile, strerror(errno));
}
/* Set it up */
snprintf(tmpfile, sizeof(tmpfile), "%s/obj_XXXXXX", get_object_directory());
local = mkstemp(tmpfile);
- if (local < 0)
- return error("Couldn't open %s for %s",
- tmpfile, sha1_to_hex(sha1));
+ if (local < 0) {
+ if (errno == EPERM)
+ return error("insufficient permission for adding an object to repository database %s\n", get_object_directory());
+ else
+ return error("unable to create temporary sha1 filename %s: %s\n", tmpfile, strerror(errno));
+ }
memset(&stream, 0, sizeof(stream));