public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: "René Scharfe" <l.s.r@web•de>
To: git@vger•kernel.org
Subject: [PATCH 08/14] test-reach: use commit_stack
Date: Wed, 24 Dec 2025 18:03:21 +0100	[thread overview]
Message-ID: <20251224170327.68049-9-l.s.r@web.de> (raw)
In-Reply-To: <20251224170327.68049-1-l.s.r@web.de>

Use commit_stack instead of open-coding it.

Signed-off-by: René Scharfe <l.s.r@web•de>
---
 t/helper/test-reach.c | 34 ++++++++++++++--------------------
 1 file changed, 14 insertions(+), 20 deletions(-)

diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c
index c58c93800f..feabeb29c2 100644
--- a/t/helper/test-reach.c
+++ b/t/helper/test-reach.c
@@ -34,8 +34,8 @@ int cmd__reach(int ac, const char **av)
 	struct commit *A, *B;
 	struct commit_list *X, *Y;
 	struct object_array X_obj = OBJECT_ARRAY_INIT;
-	struct commit **X_array, **Y_array;
-	size_t X_nr, X_alloc, Y_nr, Y_alloc;
+	struct commit_stack X_stack = COMMIT_STACK_INIT;
+	struct commit_stack Y_stack = COMMIT_STACK_INIT;
 	struct strbuf buf = STRBUF_INIT;
 	struct repository *r = the_repository;
 
@@ -46,10 +46,6 @@ int cmd__reach(int ac, const char **av)
 
 	A = B = NULL;
 	X = Y = NULL;
-	X_nr = Y_nr = 0;
-	X_alloc = Y_alloc = 16;
-	ALLOC_ARRAY(X_array, X_alloc);
-	ALLOC_ARRAY(Y_array, Y_alloc);
 
 	while (strbuf_getline(&buf, stdin) != EOF) {
 		struct object_id oid;
@@ -88,15 +84,13 @@ int cmd__reach(int ac, const char **av)
 
 			case 'X':
 				commit_list_insert(c, &X);
-				ALLOC_GROW(X_array, X_nr + 1, X_alloc);
-				X_array[X_nr++] = c;
+				commit_stack_push(&X_stack, c);
 				add_object_array(orig, NULL, &X_obj);
 				break;
 
 			case 'Y':
 				commit_list_insert(c, &Y);
-				ALLOC_GROW(Y_array, Y_nr + 1, Y_alloc);
-				Y_array[Y_nr++] = c;
+				commit_stack_push(&Y_stack, c);
 				break;
 
 			default:
@@ -112,16 +106,16 @@ int cmd__reach(int ac, const char **av)
 		       repo_in_merge_bases(the_repository, A, B));
 	else if (!strcmp(av[1], "in_merge_bases_many"))
 		printf("%s(A,X):%d\n", av[1],
-		       repo_in_merge_bases_many(the_repository, A, X_nr, X_array, 0));
+		       repo_in_merge_bases_many(the_repository, A, X_stack.nr, X_stack.items, 0));
 	else if (!strcmp(av[1], "is_descendant_of"))
 		printf("%s(A,X):%d\n", av[1], repo_is_descendant_of(r, A, X));
 	else if (!strcmp(av[1], "get_branch_base_for_tip"))
-		printf("%s(A,X):%d\n", av[1], get_branch_base_for_tip(r, A, X_array, X_nr));
+		printf("%s(A,X):%d\n", av[1], get_branch_base_for_tip(r, A, X_stack.items, X_stack.nr));
 	else if (!strcmp(av[1], "get_merge_bases_many")) {
 		struct commit_list *list = NULL;
 		if (repo_get_merge_bases_many(the_repository,
-					      A, X_nr,
-					      X_array,
+					      A, X_stack.nr,
+					      X_stack.items,
 					      &list) < 0)
 			exit(128);
 		printf("%s(A,X):\n", av[1]);
@@ -159,8 +153,8 @@ int cmd__reach(int ac, const char **av)
 		const int reachable_flag = 1;
 		int count = 0;
 		struct commit_list *current;
-		struct commit_list *list = get_reachable_subset(X_array, X_nr,
-								Y_array, Y_nr,
+		struct commit_list *list = get_reachable_subset(X_stack.items, X_stack.nr,
+								Y_stack.items, Y_stack.nr,
 								reachable_flag);
 		printf("get_reachable_subset(X,Y)\n");
 		for (current = list; current; current = current->next) {
@@ -169,8 +163,8 @@ int cmd__reach(int ac, const char **av)
 				    oid_to_hex(&list->item->object.oid));
 			count++;
 		}
-		for (size_t i = 0; i < Y_nr; i++) {
-			if (Y_array[i]->object.flags & reachable_flag)
+		for (size_t i = 0; i < Y_stack.nr; i++) {
+			if (Y_stack.items[i]->object.flags & reachable_flag)
 				count--;
 		}
 
@@ -185,7 +179,7 @@ int cmd__reach(int ac, const char **av)
 	strbuf_release(&buf);
 	free_commit_list(X);
 	free_commit_list(Y);
-	free(X_array);
-	free(Y_array);
+	commit_stack_clear(&X_stack);
+	commit_stack_clear(&Y_stack);
 	return 0;
 }
-- 
2.52.0


  parent reply	other threads:[~2025-12-24 17:03 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-24 17:03 [PATCH 00/14] export and use commit_stack René Scharfe
2025-12-24 17:03 ` [PATCH 01/14] revision: export commit_stack René Scharfe
2025-12-24 17:03 ` [PATCH 02/14] log: use commit_stack René Scharfe
2025-12-24 17:03 ` [PATCH 03/14] midx: " René Scharfe
2025-12-24 17:03 ` [PATCH 04/14] name-rev: " René Scharfe
2025-12-24 17:03 ` [PATCH 05/14] remote: use commit_stack for local_commits René Scharfe
2025-12-24 17:03 ` [PATCH 06/14] remote: use commit_stack for sent_tips René Scharfe
2025-12-24 17:03 ` [PATCH 07/14] remote: use commit_stack for src_commits René Scharfe
2025-12-24 17:03 ` René Scharfe [this message]
2025-12-24 17:03 ` [PATCH 09/14] commit: add commit_stack_init() René Scharfe
2025-12-24 17:03 ` [PATCH 10/14] pack-bitmap-write: use commit_stack René Scharfe
2025-12-24 17:03 ` [PATCH 11/14] shallow: " René Scharfe
2025-12-24 17:03 ` [PATCH 12/14] commit: add commit_stack_grow() René Scharfe
2025-12-24 17:03 ` [PATCH 13/14] commit-graph: use commit_stack René Scharfe
2025-12-24 17:03 ` [PATCH 14/14] commit-reach: " René Scharfe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251224170327.68049-9-l.s.r@web.de \
    --to=l.s.r@web$(echo .)de \
    --cc=git@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox