revision: export commit_stack
Dynamic arrays of commit pointers are used in several places. Some of them use a custom struct to hold array, item count and capacity, others have them as separate variables linked by a common name part. Pick one succinct, clean implementation -- commit_stack -- and convert the different variants to it to reduce code duplication. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Dec 24, 2025 at 18:03 UTC
d8a17ef09b8d9fdeb7d22cbc926cbebf3d8a58c9
3 files changed
+27
-23
commit.c
+17
@@ -1981,3 +1981,20 @@ int run_commit_hook(int editor_is_used, const char *index_file,
1981
opt.invoked_hook = invoked_hook;
1982
return run_hooks_opt(the_repository, name, &opt);
1983
}
1984
+
1985
+void commit_stack_push(struct commit_stack *stack, struct commit *commit)
1986
+{
1987
+ ALLOC_GROW(stack->items, stack->nr + 1, stack->alloc);
1988
+ stack->items[stack->nr++] = commit;
1989
+}
1990
+
1991
+struct commit *commit_stack_pop(struct commit_stack *stack)
1992
+{
1993
+ return stack->nr ? stack->items[--stack->nr] : NULL;
1994
+}
1995
+
1996
+void commit_stack_clear(struct commit_stack *stack)
1997
+{
1998
+ FREE_AND_NULL(stack->items);
1999
+ stack->nr = stack->alloc = 0;
2000
+}
commit.h
+10
@@ -381,4 +381,14 @@ int parse_buffer_signed_by_header(const char *buffer,
381
const struct git_hash_algo *algop);
382
int add_header_signature(struct strbuf *buf, struct strbuf *sig, const struct git_hash_algo *algo);
383
384
+struct commit_stack {
385
+ struct commit **items;
386
+ size_t nr, alloc;
387
+};
388
+#define COMMIT_STACK_INIT { 0 }
389
+
390
+void commit_stack_push(struct commit_stack *, struct commit *);
391
+struct commit *commit_stack_pop(struct commit_stack *);
392
+void commit_stack_clear(struct commit_stack *);
393
+
394
#endif /* COMMIT_H */
revision.c
-23
@@ -250,29 +250,6 @@ void mark_trees_uninteresting_sparse(struct repository *r,
250
paths_and_oids_clear(&map);
251
}
252
253
-struct commit_stack {
254
- struct commit **items;
255
- size_t nr, alloc;
256
-};
257
-#define COMMIT_STACK_INIT { 0 }
258
-
259
-static void commit_stack_push(struct commit_stack *stack, struct commit *commit)
260
-{
261
- ALLOC_GROW(stack->items, stack->nr + 1, stack->alloc);
262
- stack->items[stack->nr++] = commit;
263
-}
264
-
265
-static struct commit *commit_stack_pop(struct commit_stack *stack)
266
-{
267
- return stack->nr ? stack->items[--stack->nr] : NULL;
268
-}
269
-
270
-static void commit_stack_clear(struct commit_stack *stack)
271
-{
272
- FREE_AND_NULL(stack->items);
273
- stack->nr = stack->alloc = 0;
274
-}
275
-
253
static void mark_one_parent_uninteresting(struct rev_info *revs, struct commit *commit,
254
struct commit_stack *pending)
255
{