diff options
| author | Junio C Hamano <gitster@pobox.com> | 2026-01-12 05:19:52 -0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-01-12 05:19:52 -0800 |
| commit | 3235ef374ea9808002b3304036c1b31965033ea0 (patch) | |
| tree | 2f82cb718b5447a6021308b4d905c2e8e8c4de22 /midx-write.c | |
| parent | 0320bcd743ccf9e707b45c84761e94e9ca72f710 (diff) | |
| parent | 0e445956f4c9b6d079feb5ed831f018c857b955b (diff) | |
| download | git-3235ef374ea9808002b3304036c1b31965033ea0.tar.xz | |
Merge branch 'rs/commit-stack'
Code clean-up, unifying various hand-rolled "list of commit
objects" and use the commit_stack API.
* rs/commit-stack:
commit-reach: use commit_stack
commit-graph: use commit_stack
commit: add commit_stack_grow()
shallow: use commit_stack
pack-bitmap-write: use commit_stack
commit: add commit_stack_init()
test-reach: use commit_stack
remote: use commit_stack for src_commits
remote: use commit_stack for sent_tips
remote: use commit_stack for local_commits
name-rev: use commit_stack
midx: use commit_stack
log: use commit_stack
revision: export commit_stack
Diffstat (limited to 'midx-write.c')
| -rw-r--r-- | midx-write.c | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/midx-write.c b/midx-write.c index ce459b02c3..87b97c7087 100644 --- a/midx-write.c +++ b/midx-write.c @@ -723,9 +723,7 @@ static int add_ref_to_pending(const struct reference *ref, void *cb_data) } struct bitmap_commit_cb { - struct commit **commits; - size_t commits_nr, commits_alloc; - + struct commit_stack *commits; struct write_midx_context *ctx; }; @@ -745,8 +743,7 @@ static void bitmap_show_commit(struct commit *commit, void *_data) if (pos < 0) return; - ALLOC_GROW(data->commits, data->commits_nr + 1, data->commits_alloc); - data->commits[data->commits_nr++] = commit; + commit_stack_push(data->commits, commit); } static int read_refs_snapshot(const char *refs_snapshot, @@ -784,17 +781,15 @@ static int read_refs_snapshot(const char *refs_snapshot, return 0; } -static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr_p, - const char *refs_snapshot, - struct write_midx_context *ctx) +static void find_commits_for_midx_bitmap(struct commit_stack *commits, + const char *refs_snapshot, + struct write_midx_context *ctx) { struct rev_info revs; - struct bitmap_commit_cb cb = {0}; + struct bitmap_commit_cb cb = { .commits = commits, .ctx = ctx }; trace2_region_enter("midx", "find_commits_for_midx_bitmap", ctx->repo); - cb.ctx = ctx; - repo_init_revisions(ctx->repo, &revs, NULL); if (refs_snapshot) { read_refs_snapshot(refs_snapshot, &revs); @@ -823,14 +818,10 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr die(_("revision walk setup failed")); traverse_commit_list(&revs, bitmap_show_commit, NULL, &cb); - if (indexed_commits_nr_p) - *indexed_commits_nr_p = cb.commits_nr; release_revisions(&revs); trace2_region_leave("midx", "find_commits_for_midx_bitmap", ctx->repo); - - return cb.commits; } static int write_midx_bitmap(struct write_midx_context *ctx, @@ -1447,15 +1438,14 @@ static int write_midx_internal(struct odb_source *source, if (flags & MIDX_WRITE_BITMAP) { struct packing_data pdata; - struct commit **commits; - uint32_t commits_nr; + struct commit_stack commits = COMMIT_STACK_INIT; if (!ctx.entries_nr) BUG("cannot write a bitmap without any objects"); prepare_midx_packing_data(&pdata, &ctx); - commits = find_commits_for_midx_bitmap(&commits_nr, refs_snapshot, &ctx); + find_commits_for_midx_bitmap(&commits, refs_snapshot, &ctx); /* * The previous steps translated the information from @@ -1466,17 +1456,16 @@ static int write_midx_internal(struct odb_source *source, FREE_AND_NULL(ctx.entries); ctx.entries_nr = 0; - if (write_midx_bitmap(&ctx, - midx_hash, &pdata, commits, commits_nr, - flags) < 0) { + if (write_midx_bitmap(&ctx, midx_hash, &pdata, + commits.items, commits.nr, flags) < 0) { error(_("could not write multi-pack bitmap")); clear_packing_data(&pdata); - free(commits); + commit_stack_clear(&commits); goto cleanup; } clear_packing_data(&pdata); - free(commits); + commit_stack_clear(&commits); } /* * NOTE: Do not use ctx.entries beyond this point, since it might |
