#endif
static const char pack_usage[] = "\
-git-pack-objects [{ -q | --progress | --all-progress }] \n\
+git pack-objects [{ -q | --progress | --all-progress }] \n\
[--max-pack-size=N] [--local] [--incremental] \n\
[--window=N] [--window-memory=N] [--depth=N] \n\
[--no-reuse-delta] [--no-reuse-object] [--delta-base-offset] \n\
return hdrlen + datalen;
}
-static off_t write_one(struct sha1file *f,
+static int write_one(struct sha1file *f,
struct object_entry *e,
- off_t offset)
+ off_t *offset)
{
unsigned long size;
/* offset is non zero if object is written already. */
if (e->idx.offset || e->preferred_base)
- return offset;
+ return 1;
/* if we are deltified, write out base object first. */
- if (e->delta) {
- offset = write_one(f, e->delta, offset);
- if (!offset)
- return 0;
- }
+ if (e->delta && !write_one(f, e->delta, offset))
+ return 0;
- e->idx.offset = offset;
- size = write_object(f, e, offset);
+ e->idx.offset = *offset;
+ size = write_object(f, e, *offset);
if (!size) {
e->idx.offset = 0;
return 0;
written_list[nr_written++] = &e->idx;
/* make sure off_t is sufficiently large not to wrap */
- if (offset > offset + size)
+ if (*offset > *offset + size)
die("pack too large for current definition of off_t");
- return offset + size;
+ *offset += size;
+ return 1;
}
/* forward declaration for write_pack_file */
{
uint32_t i = 0, j;
struct sha1file *f;
- off_t offset, offset_one, last_obj_offset = 0;
+ off_t offset;
struct pack_header hdr;
uint32_t nr_remaining = nr_result;
time_t last_mtime = 0;
char tmpname[PATH_MAX];
int fd;
snprintf(tmpname, sizeof(tmpname),
- "%s/tmp_pack_XXXXXX", get_object_directory());
+ "%s/pack/tmp_pack_XXXXXX", get_object_directory());
fd = xmkstemp(tmpname);
pack_tmp_name = xstrdup(tmpname);
f = sha1fd(fd, pack_tmp_name);
offset = sizeof(hdr);
nr_written = 0;
for (; i < nr_objects; i++) {
- last_obj_offset = offset;
- offset_one = write_one(f, objects + i, offset);
- if (!offset_one)
+ if (!write_one(f, objects + i, &offset))
break;
- offset = offset_one;
display_progress(progress_state, written);
}
} else if (nr_written == nr_remaining) {
sha1close(f, sha1, CSUM_FSYNC);
} else {
- int fd = sha1close(f, NULL, 0);
- fixup_pack_header_footer(fd, sha1, pack_tmp_name, nr_written);
+ int fd = sha1close(f, sha1, 0);
+ fixup_pack_header_footer(fd, sha1, pack_tmp_name,
+ nr_written, sha1, offset);
close(fd);
}
int window, int depth, unsigned *processed)
{
uint32_t i, idx = 0, count = 0;
- unsigned int array_size = window * sizeof(struct unpacked);
struct unpacked *array;
unsigned long mem_usage = 0;
- array = xmalloc(array_size);
- memset(array, 0, array_size);
+ array = xcalloc(window, sizeof(struct unpacked));
for (;;) {
struct object_entry *entry = *list++;
if (entry->type < 0)
die("unable to get type of object %s",
sha1_to_hex(entry->idx.sha1));
+ } else {
+ if (entry->type < 0) {
+ /*
+ * This object is not found, but we
+ * don't have to include it anyway.
+ */
+ continue;
+ }
}
delta_list[n++] = entry;
/*
* Compare the objects in the offset order, in order to emulate the
- * "git-rev-list --objects" output that produced the pack originally.
+ * "git rev-list --objects" output that produced the pack originally.
*/
static int ofscmp(const void *a_, const void *b_)
{