remote: use commit_stack for local_commits
Replace a commit array implementation with commit_stack. 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
06e1f6467ee3dd92ceb894fd584173271a8aa577
1 file changed
+6
-33
remote.c
+6
-33
@@ -2544,36 +2544,9 @@ static int remote_tracking(struct remote *remote, const char *refname,
2544
return 0;
2545
}
2546
2547
-/*
2548
- * The struct "reflog_commit_array" and related helper functions
2549
- * are used for collecting commits into an array during reflog
2550
- * traversals in "check_and_collect_until()".
2551
- */
2552
-struct reflog_commit_array {
2553
- struct commit **item;
2554
- size_t nr, alloc;
2555
-};
2556
-
2557
-#define REFLOG_COMMIT_ARRAY_INIT { 0 }
2558
-
2559
-/* Append a commit to the array. */
2560
-static void append_commit(struct reflog_commit_array *arr,
2561
- struct commit *commit)
2562
-{
2563
- ALLOC_GROW(arr->item, arr->nr + 1, arr->alloc);
2564
- arr->item[arr->nr++] = commit;
2565
-}
2566
-
2567
-/* Free and reset the array. */
2568
-static void free_commit_array(struct reflog_commit_array *arr)
2569
-{
2570
- FREE_AND_NULL(arr->item);
2571
- arr->nr = arr->alloc = 0;
2572
-}
2573
-
2547
struct check_and_collect_until_cb_data {
2548
struct commit *remote_commit;
2576
- struct reflog_commit_array *local_commits;
2549
+ struct commit_stack *local_commits;
2550
timestamp_t remote_reflog_timestamp;
2551
};
2552
@@ -2605,7 +2578,7 @@ static int check_and_collect_until(const char *refname UNUSED,
2578
return 1;
2579
2580
if ((commit = lookup_commit_reference(the_repository, n_oid)))
2608
- append_commit(cb->local_commits, commit);
2581
+ commit_stack_push(cb->local_commits, commit);
2582
2583
/*
2584
* If the reflog entry timestamp is older than the remote ref's
@@ -2633,7 +2606,7 @@ static int is_reachable_in_reflog(const char *local, const struct ref *remote)
2606
struct commit *commit;
2607
struct commit **chunk;
2608
struct check_and_collect_until_cb_data cb;
2636
- struct reflog_commit_array arr = REFLOG_COMMIT_ARRAY_INIT;
2609
+ struct commit_stack arr = COMMIT_STACK_INIT;
2610
size_t size = 0;
2611
int ret = 0;
2612
@@ -2664,8 +2637,8 @@ static int is_reachable_in_reflog(const char *local, const struct ref *remote)
2637
* Check if the remote commit is reachable from any
2638
* of the commits in the collected array, in batches.
2639
*/
2667
- for (chunk = arr.item; chunk < arr.item + arr.nr; chunk += size) {
2668
- size = arr.item + arr.nr - chunk;
2640
+ for (chunk = arr.items; chunk < arr.items + arr.nr; chunk += size) {
2641
+ size = arr.items + arr.nr - chunk;
2642
if (MERGE_BASES_BATCH_SIZE < size)
2643
size = MERGE_BASES_BATCH_SIZE;
2644
@@ -2674,7 +2647,7 @@ static int is_reachable_in_reflog(const char *local, const struct ref *remote)
2647
}
2648
2649
cleanup_return:
2677
- free_commit_array(&arr);
2650
+ commit_stack_clear(&arr);
2651
return ret;
2652
}
2653