git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chandra Pratap <chandrapratap3519@gmail.com>
To: git@vger.kernel.org
Cc: Chandra Pratap <chandrapratap3519@gmail.com>,
	Patrick Steinhardt <ps@pks.im>,
	Christian Couder <chriscool@tuxfamily.org>
Subject: [PATCH v2 3/4] t-reftable-readwrite: use 'for' in place of infinite 'while' loops
Date: Fri,  9 Aug 2024 16:35:43 +0530	[thread overview]
Message-ID: <20240809111312.4401-4-chandrapratap3519@gmail.com> (raw)
In-Reply-To: <20240809111312.4401-1-chandrapratap3519@gmail.com>

Using a for loop with an empty conditional statement is more concise
and easier to read than an infinite 'while' loop in instances
where we need a loop variable. Hence, replace such instances of a
'while' loop with the equivalent 'for' loop.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
---
 t/unit-tests/t-reftable-readwrite.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/t/unit-tests/t-reftable-readwrite.c b/t/unit-tests/t-reftable-readwrite.c
index e90f2bf9de..7daf28ec6d 100644
--- a/t/unit-tests/t-reftable-readwrite.c
+++ b/t/unit-tests/t-reftable-readwrite.c
@@ -268,15 +268,13 @@ static void t_log_write_read(void)
 	err = reftable_iterator_seek_log(&it, "");
 	check(!err);
 
-	i = 0;
-	while (1) {
+	for (i = 0; ; i++) {
 		int err = reftable_iterator_next_log(&it, &log);
 		if (err > 0)
 			break;
 		check(!err);
 		check_str(names[i], log.refname);
 		check_int(i, ==, log.update_index);
-		i++;
 		reftable_log_record_release(&log);
 	}
 
@@ -374,7 +372,7 @@ static void t_table_read_write_sequential(void)
 	err = reftable_iterator_seek_ref(&it, "");
 	check(!err);
 
-	while (1) {
+	for (j = 0; ; j++) {
 		struct reftable_ref_record ref = { 0 };
 		int r = reftable_iterator_next_ref(&it, &ref);
 		check_int(r, >=, 0);
@@ -382,8 +380,6 @@ static void t_table_read_write_sequential(void)
 			break;
 		check_str(names[j], ref.refname);
 		check_int(update_index, ==, ref.update_index);
-
-		j++;
 		reftable_ref_record_release(&ref);
 	}
 	check_int(j, ==, N);
@@ -589,15 +585,13 @@ static void t_table_refs_for(int indexed)
 	err = reftable_reader_refs_for(&rd, &it, want_hash);
 	check(!err);
 
-	j = 0;
-	while (1) {
+	for (j = 0; ; j++) {
 		int err = reftable_iterator_next_ref(&it, &ref);
 		check_int(err, >=, 0);
 		if (err > 0)
 			break;
 		check_int(j, <, want_names_len);
 		check_str(ref.refname, want_names[j]);
-		j++;
 		reftable_ref_record_release(&ref);
 	}
 	check_int(j, ==, want_names_len);
-- 
2.45.GIT


  parent reply	other threads:[~2024-08-09 11:13 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-07 14:11 [GSoC][PATCH 0/5] t: port reftable/readwrite_test.c to the unit testing framework Chandra Pratap
2024-08-07 14:11 ` [PATCH 1/5] t: move " Chandra Pratap
2024-08-07 14:11 ` [PATCH 2/5] t-reftable-readwrite: use free_names() instead of a for loop Chandra Pratap
2024-08-07 14:11 ` [PATCH 3/5] t-reftable-readwrite: use 'for' in place of infinite 'while' loops Chandra Pratap
2024-08-07 14:12 ` [PATCH 4/5] t-reftable-readwrite: add test for known error Chandra Pratap
2024-08-07 14:12 ` [PATCH 5/5] t-reftable-readwrite: add tests for print functions Chandra Pratap
2024-08-08  8:12   ` Patrick Steinhardt
2024-08-08 12:00     ` Patrick Steinhardt
2024-08-08 14:25       ` Chandra Pratap
2024-08-09 16:56     ` Junio C Hamano
2024-08-09 11:05 ` [GSoC][PATCH v2 0/4] t: port reftable/readwrite_test.c to the unit testing framework Chandra Pratap
2024-08-09 11:05   ` [PATCH v2 1/4] t: move " Chandra Pratap
2024-08-09 18:12     ` Junio C Hamano
2024-08-12 14:50       ` Chandra Pratap
2024-08-09 11:05   ` [PATCH v2 2/4] t-reftable-readwrite: use free_names() instead of a for loop Chandra Pratap
2024-08-09 18:57     ` Junio C Hamano
2024-08-10  5:50       ` Chandra Pratap
2024-08-10  6:10         ` Junio C Hamano
2024-08-09 11:05   ` Chandra Pratap [this message]
2024-08-09 19:06     ` [PATCH v2 3/4] t-reftable-readwrite: use 'for' in place of infinite 'while' loops Junio C Hamano
2024-08-09 11:05   ` [PATCH v2 4/4] t-reftable-readwrite: add test for known error Chandra Pratap
2024-08-13 14:34   ` [GSoC][PATCH v3 0/4] t: port reftable/readwrite_test.c to the unit testing framework Chandra Pratap
2024-08-13 14:34     ` [PATCH v3 1/4] t: move " Chandra Pratap
2024-08-13 22:33       ` Josh Steadmon
2024-08-14 11:48         ` Chandra Pratap
2024-08-14 13:08         ` Patrick Steinhardt
2024-08-13 14:34     ` [PATCH v3 2/4] t-reftable-readwrite: use free_names() instead of a for loop Chandra Pratap
2024-08-13 14:34     ` [PATCH v3 3/4] t-reftable-readwrite: use 'for' in place of infinite 'while' loops Chandra Pratap
2024-08-13 14:34     ` [PATCH v3 4/4] t-reftable-readwrite: add test for known error Chandra Pratap
2024-08-13 17:10     ` [GSoC][PATCH v3 0/4] t: port reftable/readwrite_test.c to the unit testing framework Junio C Hamano

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=20240809111312.4401-4-chandrapratap3519@gmail.com \
    --to=chandrapratap3519@gmail.com \
    --cc=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).