mirror of
https://github.com/git/git
synced 2024-08-27 19:49:21 +00:00
fast-import: use write_idx_file() instead of custom code
This allows for the creation of pack index version 2 with its object CRC and the possibility for a pack to be larger than 4 GB. Signed-off-by: Nicolas Pitre <nico@fluxnic.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
212818160d
commit
427cb22c40
|
@ -854,67 +854,30 @@ static void start_packfile(void)
|
||||||
all_packs[pack_id] = p;
|
all_packs[pack_id] = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int oecmp (const void *a_, const void *b_)
|
static const char *create_index(void)
|
||||||
{
|
{
|
||||||
struct object_entry *a = *((struct object_entry**)a_);
|
const char *tmpfile;
|
||||||
struct object_entry *b = *((struct object_entry**)b_);
|
struct pack_idx_entry **idx, **c, **last;
|
||||||
return hashcmp(a->idx.sha1, b->idx.sha1);
|
struct object_entry *e;
|
||||||
}
|
|
||||||
|
|
||||||
static char *create_index(void)
|
|
||||||
{
|
|
||||||
static char tmpfile[PATH_MAX];
|
|
||||||
git_SHA_CTX ctx;
|
|
||||||
struct sha1file *f;
|
|
||||||
struct object_entry **idx, **c, **last, *e;
|
|
||||||
struct object_entry_pool *o;
|
struct object_entry_pool *o;
|
||||||
uint32_t array[256];
|
|
||||||
int i, idx_fd;
|
|
||||||
|
|
||||||
/* Build the sorted table of object IDs. */
|
/* Build the table of object IDs. */
|
||||||
idx = xmalloc(object_count * sizeof(struct object_entry*));
|
idx = xmalloc(object_count * sizeof(*idx));
|
||||||
c = idx;
|
c = idx;
|
||||||
for (o = blocks; o; o = o->next_pool)
|
for (o = blocks; o; o = o->next_pool)
|
||||||
for (e = o->next_free; e-- != o->entries;)
|
for (e = o->next_free; e-- != o->entries;)
|
||||||
if (pack_id == e->pack_id)
|
if (pack_id == e->pack_id)
|
||||||
*c++ = e;
|
*c++ = &e->idx;
|
||||||
last = idx + object_count;
|
last = idx + object_count;
|
||||||
if (c != last)
|
if (c != last)
|
||||||
die("internal consistency error creating the index");
|
die("internal consistency error creating the index");
|
||||||
qsort(idx, object_count, sizeof(struct object_entry*), oecmp);
|
|
||||||
|
|
||||||
/* Generate the fan-out array. */
|
tmpfile = write_idx_file(NULL, idx, object_count, pack_data->sha1);
|
||||||
c = idx;
|
|
||||||
for (i = 0; i < 256; i++) {
|
|
||||||
struct object_entry **next = c;
|
|
||||||
while (next < last) {
|
|
||||||
if ((*next)->idx.sha1[0] != i)
|
|
||||||
break;
|
|
||||||
next++;
|
|
||||||
}
|
|
||||||
array[i] = htonl(next - idx);
|
|
||||||
c = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
idx_fd = odb_mkstemp(tmpfile, sizeof(tmpfile),
|
|
||||||
"pack/tmp_idx_XXXXXX");
|
|
||||||
f = sha1fd(idx_fd, tmpfile);
|
|
||||||
sha1write(f, array, 256 * sizeof(int));
|
|
||||||
git_SHA1_Init(&ctx);
|
|
||||||
for (c = idx; c != last; c++) {
|
|
||||||
uint32_t offset = htonl((*c)->idx.offset);
|
|
||||||
sha1write(f, &offset, 4);
|
|
||||||
sha1write(f, (*c)->idx.sha1, sizeof((*c)->idx.sha1));
|
|
||||||
git_SHA1_Update(&ctx, (*c)->idx.sha1, 20);
|
|
||||||
}
|
|
||||||
sha1write(f, pack_data->sha1, sizeof(pack_data->sha1));
|
|
||||||
sha1close(f, NULL, CSUM_FSYNC);
|
|
||||||
free(idx);
|
free(idx);
|
||||||
git_SHA1_Final(pack_data->sha1, &ctx);
|
|
||||||
return tmpfile;
|
return tmpfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *keep_pack(char *curr_index_name)
|
static char *keep_pack(const char *curr_index_name)
|
||||||
{
|
{
|
||||||
static char name[PATH_MAX];
|
static char name[PATH_MAX];
|
||||||
static const char *keep_msg = "fast-import";
|
static const char *keep_msg = "fast-import";
|
||||||
|
@ -936,6 +899,7 @@ static char *keep_pack(char *curr_index_name)
|
||||||
get_object_directory(), sha1_to_hex(pack_data->sha1));
|
get_object_directory(), sha1_to_hex(pack_data->sha1));
|
||||||
if (move_temp_to_file(curr_index_name, name))
|
if (move_temp_to_file(curr_index_name, name))
|
||||||
die("cannot store index file");
|
die("cannot store index file");
|
||||||
|
free((void *)curr_index_name);
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1134,6 +1098,8 @@ static int store_object(
|
||||||
object_count++;
|
object_count++;
|
||||||
object_count_by_type[type]++;
|
object_count_by_type[type]++;
|
||||||
|
|
||||||
|
crc32_begin(pack_file);
|
||||||
|
|
||||||
if (delta) {
|
if (delta) {
|
||||||
unsigned long ofs = e->idx.offset - last->offset;
|
unsigned long ofs = e->idx.offset - last->offset;
|
||||||
unsigned pos = sizeof(hdr) - 1;
|
unsigned pos = sizeof(hdr) - 1;
|
||||||
|
@ -1160,6 +1126,8 @@ static int store_object(
|
||||||
sha1write(pack_file, out, s.total_out);
|
sha1write(pack_file, out, s.total_out);
|
||||||
pack_size += s.total_out;
|
pack_size += s.total_out;
|
||||||
|
|
||||||
|
e->idx.crc32 = crc32_end(pack_file);
|
||||||
|
|
||||||
free(out);
|
free(out);
|
||||||
free(delta);
|
free(delta);
|
||||||
if (last) {
|
if (last) {
|
||||||
|
@ -1219,6 +1187,8 @@ static void stream_blob(uintmax_t len, unsigned char *sha1out, uintmax_t mark)
|
||||||
git_SHA1_Init(&c);
|
git_SHA1_Init(&c);
|
||||||
git_SHA1_Update(&c, out_buf, hdrlen);
|
git_SHA1_Update(&c, out_buf, hdrlen);
|
||||||
|
|
||||||
|
crc32_begin(pack_file);
|
||||||
|
|
||||||
memset(&s, 0, sizeof(s));
|
memset(&s, 0, sizeof(s));
|
||||||
deflateInit(&s, pack_compression_level);
|
deflateInit(&s, pack_compression_level);
|
||||||
|
|
||||||
|
@ -1288,6 +1258,7 @@ static void stream_blob(uintmax_t len, unsigned char *sha1out, uintmax_t mark)
|
||||||
e->type = OBJ_BLOB;
|
e->type = OBJ_BLOB;
|
||||||
e->pack_id = pack_id;
|
e->pack_id = pack_id;
|
||||||
e->idx.offset = offset;
|
e->idx.offset = offset;
|
||||||
|
e->idx.crc32 = crc32_end(pack_file);
|
||||||
object_count++;
|
object_count++;
|
||||||
object_count_by_type[OBJ_BLOB]++;
|
object_count_by_type[OBJ_BLOB]++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue