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
This commit is contained in:
Junio C Hamano
2026-01-12 05:19:52 -08:00
13 changed files with 184 additions and 247 deletions

View File

@@ -1984,3 +1984,31 @@ int run_commit_hook(int editor_is_used, const char *index_file,
opt.invoked_hook = invoked_hook;
return run_hooks_opt(the_repository, name, &opt);
}
void commit_stack_init(struct commit_stack *stack)
{
stack->items = NULL;
stack->nr = stack->alloc = 0;
}
void commit_stack_grow(struct commit_stack *stack, size_t extra)
{
ALLOC_GROW(stack->items, st_add(stack->nr, extra), stack->alloc);
}
void commit_stack_push(struct commit_stack *stack, struct commit *commit)
{
commit_stack_grow(stack, 1);
stack->items[stack->nr++] = commit;
}
struct commit *commit_stack_pop(struct commit_stack *stack)
{
return stack->nr ? stack->items[--stack->nr] : NULL;
}
void commit_stack_clear(struct commit_stack *stack)
{
free(stack->items);
commit_stack_init(stack);
}