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 /commit.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 'commit.c')
| -rw-r--r-- | commit.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -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); +} |
