]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t-reftable-readwrite: use 'for' in place of infinite 'while' loops
authorChandra Pratap <chandrapratap3519@gmail.com>
Tue, 13 Aug 2024 14:34:49 +0000 (20:04 +0530)
committerJunio C Hamano <gitster@pobox.com>
Tue, 13 Aug 2024 17:08:03 +0000 (10:08 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/unit-tests/t-reftable-readwrite.c

index 8e546b0dd689cc757134e6442b2093b1c7e36edf..9a05dde9d6d39dfbb8c714a01fb98a1abc387ce8 100644 (file)
@@ -269,15 +269,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);
        }
 
@@ -375,7 +373,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);
@@ -383,8 +381,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);
@@ -590,15 +586,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);