commit-graph: use chunk-format write API
The commit-graph write logic is ready to make use of the chunk-format write API. Each chunk write method is already in the correct prototype. We only need to use the 'struct chunkfile' pointer and the correct API calls. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
570df42610
commit
47410aa837
117
commit-graph.c
117
commit-graph.c
@ -19,6 +19,7 @@
|
|||||||
#include "shallow.h"
|
#include "shallow.h"
|
||||||
#include "json-writer.h"
|
#include "json-writer.h"
|
||||||
#include "trace2.h"
|
#include "trace2.h"
|
||||||
|
#include "chunk-format.h"
|
||||||
|
|
||||||
void git_test_write_commit_graph_or_die(void)
|
void git_test_write_commit_graph_or_die(void)
|
||||||
{
|
{
|
||||||
@ -44,7 +45,6 @@ void git_test_write_commit_graph_or_die(void)
|
|||||||
#define GRAPH_CHUNKID_BLOOMINDEXES 0x42494458 /* "BIDX" */
|
#define GRAPH_CHUNKID_BLOOMINDEXES 0x42494458 /* "BIDX" */
|
||||||
#define GRAPH_CHUNKID_BLOOMDATA 0x42444154 /* "BDAT" */
|
#define GRAPH_CHUNKID_BLOOMDATA 0x42444154 /* "BDAT" */
|
||||||
#define GRAPH_CHUNKID_BASE 0x42415345 /* "BASE" */
|
#define GRAPH_CHUNKID_BASE 0x42415345 /* "BASE" */
|
||||||
#define MAX_NUM_CHUNKS 9
|
|
||||||
|
|
||||||
#define GRAPH_DATA_WIDTH (the_hash_algo->rawsz + 16)
|
#define GRAPH_DATA_WIDTH (the_hash_algo->rawsz + 16)
|
||||||
|
|
||||||
@ -1758,27 +1758,17 @@ static int write_graph_chunk_base(struct hashfile *f,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef int (*chunk_write_fn)(struct hashfile *f,
|
|
||||||
void *data);
|
|
||||||
|
|
||||||
struct chunk_info {
|
|
||||||
uint32_t id;
|
|
||||||
uint64_t size;
|
|
||||||
chunk_write_fn write_fn;
|
|
||||||
};
|
|
||||||
|
|
||||||
static int write_commit_graph_file(struct write_commit_graph_context *ctx)
|
static int write_commit_graph_file(struct write_commit_graph_context *ctx)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
int fd;
|
int fd;
|
||||||
struct hashfile *f;
|
struct hashfile *f;
|
||||||
struct lock_file lk = LOCK_INIT;
|
struct lock_file lk = LOCK_INIT;
|
||||||
struct chunk_info chunks[MAX_NUM_CHUNKS + 1];
|
|
||||||
const unsigned hashsz = the_hash_algo->rawsz;
|
const unsigned hashsz = the_hash_algo->rawsz;
|
||||||
struct strbuf progress_title = STRBUF_INIT;
|
struct strbuf progress_title = STRBUF_INIT;
|
||||||
int num_chunks = 3;
|
int num_chunks = 3;
|
||||||
uint64_t chunk_offset;
|
|
||||||
struct object_id file_hash;
|
struct object_id file_hash;
|
||||||
|
struct chunkfile *cf;
|
||||||
|
|
||||||
if (ctx->split) {
|
if (ctx->split) {
|
||||||
struct strbuf tmp_file = STRBUF_INIT;
|
struct strbuf tmp_file = STRBUF_INIT;
|
||||||
@ -1824,76 +1814,50 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
|
|||||||
f = hashfd(lk.tempfile->fd, lk.tempfile->filename.buf);
|
f = hashfd(lk.tempfile->fd, lk.tempfile->filename.buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
chunks[0].id = GRAPH_CHUNKID_OIDFANOUT;
|
cf = init_chunkfile(f);
|
||||||
chunks[0].size = GRAPH_FANOUT_SIZE;
|
|
||||||
chunks[0].write_fn = write_graph_chunk_fanout;
|
add_chunk(cf, GRAPH_CHUNKID_OIDFANOUT, GRAPH_FANOUT_SIZE,
|
||||||
chunks[1].id = GRAPH_CHUNKID_OIDLOOKUP;
|
write_graph_chunk_fanout);
|
||||||
chunks[1].size = hashsz * ctx->commits.nr;
|
add_chunk(cf, GRAPH_CHUNKID_OIDLOOKUP, hashsz * ctx->commits.nr,
|
||||||
chunks[1].write_fn = write_graph_chunk_oids;
|
write_graph_chunk_oids);
|
||||||
chunks[2].id = GRAPH_CHUNKID_DATA;
|
add_chunk(cf, GRAPH_CHUNKID_DATA, (hashsz + 16) * ctx->commits.nr,
|
||||||
chunks[2].size = (hashsz + 16) * ctx->commits.nr;
|
write_graph_chunk_data);
|
||||||
chunks[2].write_fn = write_graph_chunk_data;
|
|
||||||
|
|
||||||
if (git_env_bool(GIT_TEST_COMMIT_GRAPH_NO_GDAT, 0))
|
if (git_env_bool(GIT_TEST_COMMIT_GRAPH_NO_GDAT, 0))
|
||||||
ctx->write_generation_data = 0;
|
ctx->write_generation_data = 0;
|
||||||
if (ctx->write_generation_data) {
|
if (ctx->write_generation_data)
|
||||||
chunks[num_chunks].id = GRAPH_CHUNKID_GENERATION_DATA;
|
add_chunk(cf, GRAPH_CHUNKID_GENERATION_DATA,
|
||||||
chunks[num_chunks].size = sizeof(uint32_t) * ctx->commits.nr;
|
sizeof(uint32_t) * ctx->commits.nr,
|
||||||
chunks[num_chunks].write_fn = write_graph_chunk_generation_data;
|
write_graph_chunk_generation_data);
|
||||||
num_chunks++;
|
if (ctx->num_generation_data_overflows)
|
||||||
}
|
add_chunk(cf, GRAPH_CHUNKID_GENERATION_DATA_OVERFLOW,
|
||||||
if (ctx->num_generation_data_overflows) {
|
sizeof(timestamp_t) * ctx->num_generation_data_overflows,
|
||||||
chunks[num_chunks].id = GRAPH_CHUNKID_GENERATION_DATA_OVERFLOW;
|
write_graph_chunk_generation_data_overflow);
|
||||||
chunks[num_chunks].size = sizeof(timestamp_t) * ctx->num_generation_data_overflows;
|
if (ctx->num_extra_edges)
|
||||||
chunks[num_chunks].write_fn = write_graph_chunk_generation_data_overflow;
|
add_chunk(cf, GRAPH_CHUNKID_EXTRAEDGES,
|
||||||
num_chunks++;
|
4 * ctx->num_extra_edges,
|
||||||
}
|
write_graph_chunk_extra_edges);
|
||||||
if (ctx->num_extra_edges) {
|
|
||||||
chunks[num_chunks].id = GRAPH_CHUNKID_EXTRAEDGES;
|
|
||||||
chunks[num_chunks].size = 4 * ctx->num_extra_edges;
|
|
||||||
chunks[num_chunks].write_fn = write_graph_chunk_extra_edges;
|
|
||||||
num_chunks++;
|
|
||||||
}
|
|
||||||
if (ctx->changed_paths) {
|
if (ctx->changed_paths) {
|
||||||
chunks[num_chunks].id = GRAPH_CHUNKID_BLOOMINDEXES;
|
add_chunk(cf, GRAPH_CHUNKID_BLOOMINDEXES,
|
||||||
chunks[num_chunks].size = sizeof(uint32_t) * ctx->commits.nr;
|
sizeof(uint32_t) * ctx->commits.nr,
|
||||||
chunks[num_chunks].write_fn = write_graph_chunk_bloom_indexes;
|
write_graph_chunk_bloom_indexes);
|
||||||
num_chunks++;
|
add_chunk(cf, GRAPH_CHUNKID_BLOOMDATA,
|
||||||
chunks[num_chunks].id = GRAPH_CHUNKID_BLOOMDATA;
|
sizeof(uint32_t) * 3
|
||||||
chunks[num_chunks].size = sizeof(uint32_t) * 3
|
+ ctx->total_bloom_filter_data_size,
|
||||||
+ ctx->total_bloom_filter_data_size;
|
write_graph_chunk_bloom_data);
|
||||||
chunks[num_chunks].write_fn = write_graph_chunk_bloom_data;
|
|
||||||
num_chunks++;
|
|
||||||
}
|
}
|
||||||
if (ctx->num_commit_graphs_after > 1) {
|
if (ctx->num_commit_graphs_after > 1)
|
||||||
chunks[num_chunks].id = GRAPH_CHUNKID_BASE;
|
add_chunk(cf, GRAPH_CHUNKID_BASE,
|
||||||
chunks[num_chunks].size = hashsz * (ctx->num_commit_graphs_after - 1);
|
hashsz * (ctx->num_commit_graphs_after - 1),
|
||||||
chunks[num_chunks].write_fn = write_graph_chunk_base;
|
write_graph_chunk_base);
|
||||||
num_chunks++;
|
|
||||||
}
|
|
||||||
|
|
||||||
chunks[num_chunks].id = 0;
|
|
||||||
chunks[num_chunks].size = 0;
|
|
||||||
|
|
||||||
hashwrite_be32(f, GRAPH_SIGNATURE);
|
hashwrite_be32(f, GRAPH_SIGNATURE);
|
||||||
|
|
||||||
hashwrite_u8(f, GRAPH_VERSION);
|
hashwrite_u8(f, GRAPH_VERSION);
|
||||||
hashwrite_u8(f, oid_version());
|
hashwrite_u8(f, oid_version());
|
||||||
hashwrite_u8(f, num_chunks);
|
hashwrite_u8(f, get_num_chunks(cf));
|
||||||
hashwrite_u8(f, ctx->num_commit_graphs_after - 1);
|
hashwrite_u8(f, ctx->num_commit_graphs_after - 1);
|
||||||
|
|
||||||
chunk_offset = 8 + (num_chunks + 1) * GRAPH_CHUNKLOOKUP_WIDTH;
|
|
||||||
for (i = 0; i <= num_chunks; i++) {
|
|
||||||
uint32_t chunk_write[3];
|
|
||||||
|
|
||||||
chunk_write[0] = htonl(chunks[i].id);
|
|
||||||
chunk_write[1] = htonl(chunk_offset >> 32);
|
|
||||||
chunk_write[2] = htonl(chunk_offset & 0xffffffff);
|
|
||||||
hashwrite(f, chunk_write, 12);
|
|
||||||
|
|
||||||
chunk_offset += chunks[i].size;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ctx->report_progress) {
|
if (ctx->report_progress) {
|
||||||
strbuf_addf(&progress_title,
|
strbuf_addf(&progress_title,
|
||||||
Q_("Writing out commit graph in %d pass",
|
Q_("Writing out commit graph in %d pass",
|
||||||
@ -1905,17 +1869,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
|
|||||||
num_chunks * ctx->commits.nr);
|
num_chunks * ctx->commits.nr);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < num_chunks; i++) {
|
write_chunkfile(cf, ctx);
|
||||||
uint64_t start_offset = f->total + f->offset;
|
|
||||||
|
|
||||||
if (chunks[i].write_fn(f, ctx))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (f->total + f->offset != start_offset + chunks[i].size)
|
|
||||||
BUG("expected to write %"PRId64" bytes to chunk %"PRIx32", but wrote %"PRId64" instead",
|
|
||||||
chunks[i].size, chunks[i].id,
|
|
||||||
f->total + f->offset - start_offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
stop_progress(&ctx->progress);
|
stop_progress(&ctx->progress);
|
||||||
strbuf_release(&progress_title);
|
strbuf_release(&progress_title);
|
||||||
@ -1932,6 +1886,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
|
|||||||
|
|
||||||
close_commit_graph(ctx->r->objects);
|
close_commit_graph(ctx->r->objects);
|
||||||
finalize_hashfile(f, file_hash.hash, CSUM_HASH_IN_STREAM | CSUM_FSYNC);
|
finalize_hashfile(f, file_hash.hash, CSUM_HASH_IN_STREAM | CSUM_FSYNC);
|
||||||
|
free_chunkfile(cf);
|
||||||
|
|
||||||
if (ctx->split) {
|
if (ctx->split) {
|
||||||
FILE *chainf = fdopen_lock_file(&lk, "w");
|
FILE *chainf = fdopen_lock_file(&lk, "w");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user