#include "progress.h"
#include "bloom.h"
#include "commit-slab.h"
+#include "shallow.h"
void git_test_write_commit_graph_or_die(void)
{
if (data + graph_size - chunk_lookup <
GRAPH_CHUNKLOOKUP_WIDTH) {
error(_("commit-graph chunk lookup table entry missing; file may be incomplete"));
- free(graph);
- return NULL;
+ goto free_and_return;
}
chunk_id = get_be32(chunk_lookup + 0);
if (chunk_offset > graph_size - the_hash_algo->rawsz) {
error(_("commit-graph improper chunk offset %08x%08x"), (uint32_t)(chunk_offset >> 32),
(uint32_t)chunk_offset);
- free(graph);
- return NULL;
+ goto free_and_return;
}
switch (chunk_id) {
if (chunk_repeated) {
error(_("commit-graph chunk id %08x appears multiple times"), chunk_id);
- free(graph);
- return NULL;
+ goto free_and_return;
}
if (last_chunk_id == GRAPH_CHUNKID_OIDLOOKUP)
/* We need both the bloom chunks to exist together. Else ignore the data */
graph->chunk_bloom_indexes = NULL;
graph->chunk_bloom_data = NULL;
- graph->bloom_filter_settings = NULL;
+ FREE_AND_NULL(graph->bloom_filter_settings);
}
hashcpy(graph->oid.hash, graph->data + graph->data_len - graph->hash_len);
- if (verify_commit_graph_lite(graph)) {
- free(graph);
- return NULL;
- }
+ if (verify_commit_graph_lite(graph))
+ goto free_and_return;
return graph;
+
+free_and_return:
+ free(graph->bloom_filter_settings);
+ free(graph);
+ return NULL;
}
static struct commit_graph *load_commit_graph_one(const char *graph_file,
unsigned append:1,
report_progress:1,
split:1,
- check_oids:1,
changed_paths:1,
order_by_pack:1;
stop_progress(&progress);
}
+struct refs_cb_data {
+ struct oidset *commits;
+ struct progress *progress;
+};
+
static int add_ref_to_set(const char *refname,
const struct object_id *oid,
int flags, void *cb_data)
{
- struct oidset *commits = (struct oidset *)cb_data;
+ struct object_id peeled;
+ struct refs_cb_data *data = (struct refs_cb_data *)cb_data;
+
+ if (!peel_ref(refname, &peeled))
+ oid = &peeled;
+ if (oid_object_info(the_repository, oid, NULL) == OBJ_COMMIT)
+ oidset_insert(data->commits, oid);
+
+ display_progress(data->progress, oidset_size(data->commits));
- oidset_insert(commits, oid);
return 0;
}
const struct split_commit_graph_opts *split_opts)
{
struct oidset commits = OIDSET_INIT;
+ struct refs_cb_data data;
int result;
- for_each_ref(add_ref_to_set, &commits);
+ memset(&data, 0, sizeof(data));
+ data.commits = &commits;
+ if (flags & COMMIT_GRAPH_WRITE_PROGRESS)
+ data.progress = start_delayed_progress(
+ _("Collecting referenced commits"), 0);
+
+ for_each_ref(add_ref_to_set, &data);
result = write_commit_graph(odb, NULL, &commits,
flags, split_opts);
oidset_clear(&commits);
+ if (data.progress)
+ stop_progress(&data.progress);
return result;
}
static int fill_oids_from_commits(struct write_commit_graph_context *ctx,
struct oidset *commits)
{
- uint32_t i = 0;
- struct strbuf progress_title = STRBUF_INIT;
struct oidset_iter iter;
struct object_id *oid;
if (!oidset_size(commits))
return 0;
- if (ctx->report_progress) {
- strbuf_addf(&progress_title,
- Q_("Finding commits for commit graph from %d ref",
- "Finding commits for commit graph from %d refs",
- oidset_size(commits)),
- oidset_size(commits));
- ctx->progress = start_delayed_progress(
- progress_title.buf,
- oidset_size(commits));
- }
-
oidset_iter_init(commits, &iter);
while ((oid = oidset_iter_next(&iter))) {
- struct commit *result;
-
- display_progress(ctx->progress, ++i);
-
- result = lookup_commit_reference_gently(ctx->r, oid, 1);
- if (result) {
- ALLOC_GROW(ctx->oids.list, ctx->oids.nr + 1, ctx->oids.alloc);
- oidcpy(&ctx->oids.list[ctx->oids.nr], &(result->object.oid));
- ctx->oids.nr++;
- } else if (ctx->check_oids) {
- error(_("invalid commit object id: %s"),
- oid_to_hex(oid));
- return -1;
- }
+ ALLOC_GROW(ctx->oids.list, ctx->oids.nr + 1, ctx->oids.alloc);
+ oidcpy(&ctx->oids.list[ctx->oids.nr], oid);
+ ctx->oids.nr++;
}
- stop_progress(&ctx->progress);
- strbuf_release(&progress_title);
-
return 0;
}
ctx->append = flags & COMMIT_GRAPH_WRITE_APPEND ? 1 : 0;
ctx->report_progress = flags & COMMIT_GRAPH_WRITE_PROGRESS ? 1 : 0;
ctx->split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0;
- ctx->check_oids = flags & COMMIT_GRAPH_WRITE_CHECK_OIDS ? 1 : 0;
ctx->split_opts = split_opts;
ctx->changed_paths = flags & COMMIT_GRAPH_WRITE_BLOOM_FILTERS ? 1 : 0;
ctx->total_bloom_filter_data_size = 0;