{"thread":{"id":"61595","subject":"[GSoC][PATCH 0/6] t: port reftable/pq_test.c to the unit testing","startedAt":"2024-06-06T07:57:13Z","lastAt":"2024-08-01T16:08:08Z","messageCount":78,"participants":["Chandra Pratap","Christian Couder","Patrick Steinhardt","Junio C Hamano","Kristoffer Haugsbakk"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"496444","messageId":"20240606075601.6989-1-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":null,"subject":"[GSoC][PATCH 0/6] t: port reftable/pq_test.c to the unit testing","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-06T07:40:44Z","receivedAt":"2024-06-06T07:57:13Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"In the recent codebase update (commit 8bf6fbd, 2023-12-09), a new unit\ntesting framework written entirely in C was introduced to the Git project\naimed at simplifying testing and reducing test run times.\nCurrently, tests for the reftable refs-backend are performed by a custom\ntesting framework defined by reftable/test_framework.{c, h}. Port\nreftable/pq_test.c to the unit testing framework and improve upon\nthe ported test.\n\nThe first patch in the series is preparatory cleanup, the second patch\nmoves the test to the unit testing framework, and the rest of the patches\nimprove upon the ported test.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n\nCI/PR: https://github.com/gitgitgadget/git/pull/1745\n\nChandra Pratap (6):\nreftable: clean up reftable/pq.c\nt: move reftable/pq_test.c to the unit testing framework\nt-reftable-pq: make merged_iter_pqueue_check() static\nt-reftable-pq: make merged_iter_pqueue_check() callable\nt-reftable-pq: add test for index based comparison\nt-reftable-pq: add tests for merged_iter_pqueue_top()\n\n"},{"id":"496445","messageId":"20240606075601.6989-2-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240606075601.6989-1-chandrapratap3519@gmail.com","subject":"[GSoC][PATCH 1/6] reftable: clean up reftable/pq.c","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-06T07:40:45Z","receivedAt":"2024-06-06T07:57:15Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"According to Documentation/CodingGuidelines, control-flow statements\nwith a single line as their body must omit curly braces. Make\nreftable/pq.c conform to this guideline. Besides that, remove\nunnecessary newlines and variable assignment.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n reftable/pq.c | 18 ++++--------------\n 1 file changed, 4 insertions(+), 14 deletions(-)\n\ndiff --git a/reftable/pq.c b/reftable/pq.c\nindex 7fb45d8c60..0401c47068 100644\n--- a/reftable/pq.c\n+++ b/reftable/pq.c\n@@ -27,22 +27,16 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n \tpq->heap[0] = pq->heap[pq->len - 1];\n \tpq->len--;\n \n-\ti = 0;\n \twhile (i < pq->len) {\n \t\tint min = i;\n \t\tint j = 2 * i + 1;\n \t\tint k = 2 * i + 2;\n-\t\tif (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i])) {\n+\t\tif (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tmin = j;\n-\t\t}\n-\t\tif (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min])) {\n+\t\tif (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min]))\n \t\t\tmin = k;\n-\t\t}\n-\n-\t\tif (min == i) {\n+\t\tif (min == i)\n \t\t\tbreak;\n-\t\t}\n-\n \t\tSWAP(pq->heap[i], pq->heap[min]);\n \t\ti = min;\n \t}\n@@ -53,19 +47,15 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e)\n {\n \tint i = 0;\n-\n \tREFTABLE_ALLOC_GROW(pq->heap, pq->len + 1, pq->cap);\n \tpq->heap[pq->len++] = *e;\n \n \ti = pq->len - 1;\n \twhile (i > 0) {\n \t\tint j = (i - 1) / 2;\n-\t\tif (pq_less(&pq->heap[j], &pq->heap[i])) {\n+\t\tif (pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tbreak;\n-\t\t}\n-\n \t\tSWAP(pq->heap[j], pq->heap[i]);\n-\n \t\ti = j;\n \t}\n }\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"496446","messageId":"20240606075601.6989-3-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240606075601.6989-1-chandrapratap3519@gmail.com","subject":"[GSoC][PATCH 2/6] t: move reftable/pq_test.c to the unit testing framework","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-06T07:40:46Z","receivedAt":"2024-06-06T07:57:18Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"reftable/pq_test.c exercises a priority queue defined by\nreftable/pq.{c, h}. Migrate reftable/pq_test.c to the unit\ntesting framework. Migration involves refactoring the tests\nto use the unit testing framework instead of reftable's test\nframework.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n Makefile                                      |  2 +-\n t/helper/test-reftable.c                      |  1 -\n .../pq_test.c => t/unit-tests/t-reftable-pq.c | 35 ++++++++-----------\n 3 files changed, 15 insertions(+), 23 deletions(-)\n rename reftable/pq_test.c => t/unit-tests/t-reftable-pq.c (64%)\n\ndiff --git a/Makefile b/Makefile\nindex 59d98ba688..1cabe4cc69 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1336,6 +1336,7 @@ THIRD_PARTY_SOURCES += sha1dc/%\n UNIT_TEST_PROGRAMS += t-ctype\n UNIT_TEST_PROGRAMS += t-mem-pool\n UNIT_TEST_PROGRAMS += t-prio-queue\n+UNIT_TEST_PROGRAMS += t-reftable-pq\n UNIT_TEST_PROGRAMS += t-strbuf\n UNIT_TEST_PROGRAMS += t-strcmp-offset\n UNIT_TEST_PROGRAMS += t-trailer\n@@ -2675,7 +2676,6 @@ REFTABLE_TEST_OBJS += reftable/basics_test.o\n REFTABLE_TEST_OBJS += reftable/block_test.o\n REFTABLE_TEST_OBJS += reftable/dump.o\n REFTABLE_TEST_OBJS += reftable/merged_test.o\n-REFTABLE_TEST_OBJS += reftable/pq_test.o\n REFTABLE_TEST_OBJS += reftable/record_test.o\n REFTABLE_TEST_OBJS += reftable/readwrite_test.o\n REFTABLE_TEST_OBJS += reftable/stack_test.o\ndiff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c\nindex bae731669c..86a2b0f91a 100644\n--- a/t/helper/test-reftable.c\n+++ b/t/helper/test-reftable.c\n@@ -9,7 +9,6 @@ int cmd__reftable(int argc, const char **argv)\n \trecord_test_main(argc, argv);\n \tblock_test_main(argc, argv);\n \ttree_test_main(argc, argv);\n-\tpq_test_main(argc, argv);\n \treadwrite_test_main(argc, argv);\n \tmerged_test_main(argc, argv);\n \tstack_test_main(argc, argv);\ndiff --git a/reftable/pq_test.c b/t/unit-tests/t-reftable-pq.c\nsimilarity index 64%\nrename from reftable/pq_test.c\nrename to t/unit-tests/t-reftable-pq.c\nindex b7d3c80cc7..dcde73de66 100644\n--- a/reftable/pq_test.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -6,35 +6,28 @@ license that can be found in the LICENSE file or at\n https://developers.google.com/open-source/licenses/bsd\n */\n \n-#include \"system.h\"\n-\n-#include \"basics.h\"\n-#include \"constants.h\"\n-#include \"pq.h\"\n-#include \"record.h\"\n-#include \"reftable-tests.h\"\n-#include \"test_framework.h\"\n+#include \"test-lib.h\"\n+#include \"reftable/constants.h\"\n+#include \"reftable/pq.h\"\n \n void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n {\n-\tint i;\n-\tfor (i = 1; i < pq.len; i++) {\n+\tfor (int i = 1; i < pq.len; i++) {\n \t\tint parent = (i - 1) / 2;\n-\n-\t\tEXPECT(pq_less(&pq.heap[parent], &pq.heap[i]));\n+\t\tcheck(pq_less(&pq.heap[parent], &pq.heap[i]));\n \t}\n }\n \n static void test_pq(void)\n {\n-\tstruct merged_iter_pqueue pq = { NULL };\n+\tstruct merged_iter_pqueue pq = { 0 };\n \tstruct reftable_record recs[54];\n-\tint N = ARRAY_SIZE(recs) - 1, i;\n+\tsize_t N = ARRAY_SIZE(recs) - 1, i;\n \tchar *last = NULL;\n \n \tfor (i = 0; i < N; i++) {\n \t\tstruct strbuf refname = STRBUF_INIT;\n-\t\tstrbuf_addf(&refname, \"%02d\", i);\n+\t\tstrbuf_addf(&refname, \"%02ld\", (long)i);\n \n \t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n \t\trecs[i].u.ref.refname = strbuf_detach(&refname, NULL);\n@@ -48,7 +41,6 @@ static void test_pq(void)\n \n \t\tmerged_iter_pqueue_add(&pq, &e);\n \t\tmerged_iter_pqueue_check(pq);\n-\n \t\ti = (i * 7) % N;\n \t} while (i != 1);\n \n@@ -56,9 +48,9 @@ static void test_pq(void)\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n \t\tmerged_iter_pqueue_check(pq);\n \n-\t\tEXPECT(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n+\t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tif (last)\n-\t\t\tEXPECT(strcmp(last, e.rec->u.ref.refname) < 0);\n+\t\t\tcheck_int(strcmp(last, e.rec->u.ref.refname), <, 0);\n \t\tlast = e.rec->u.ref.refname;\n \t}\n \n@@ -67,8 +59,9 @@ static void test_pq(void)\n \tmerged_iter_pqueue_release(&pq);\n }\n \n-int pq_test_main(int argc, const char *argv[])\n+int cmd_main(int argc, const char *argv[])\n {\n-\tRUN_TEST(test_pq);\n-\treturn 0;\n+\tTEST(test_pq(), \"pq works\");\n+\n+\treturn test_done();\n }\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"496447","messageId":"20240606075601.6989-4-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240606075601.6989-1-chandrapratap3519@gmail.com","subject":"[GSoC][PATCH 3/6] t-reftable-pq: make merged_iter_pqueue_check() static","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-06T07:40:47Z","receivedAt":"2024-06-06T07:57:21Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"merged_iter_pqueue_check() is a function previously defined in\nreftable/pq_test.c (now t/unit-tests/t-reftable-pq.c) and used in\nthe testing of a priority queue as defined by reftable/pq.{c, h}.\nAs such, this function is only called by reftable/pq_test.c and it\nmakes little sense to expose it to non-testing code via reftable/pq.h.\n\nHence, make this function static and remove its prototype from\nreftable/pq.h.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n reftable/pq.h                | 1 -\n t/unit-tests/t-reftable-pq.c | 2 +-\n 2 files changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/reftable/pq.h b/reftable/pq.h\nindex f796c23179..707bd26767 100644\n--- a/reftable/pq.h\n+++ b/reftable/pq.h\n@@ -22,7 +22,6 @@ struct merged_iter_pqueue {\n \tsize_t cap;\n };\n \n-void merged_iter_pqueue_check(struct merged_iter_pqueue pq);\n struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq);\n void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e);\n void merged_iter_pqueue_release(struct merged_iter_pqueue *pq);\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex dcde73de66..5c5a4ecdc5 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -10,7 +10,7 @@ license that can be found in the LICENSE file or at\n #include \"reftable/constants.h\"\n #include \"reftable/pq.h\"\n \n-void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n+static void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n {\n \tfor (int i = 1; i < pq.len; i++) {\n \t\tint parent = (i - 1) / 2;\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"496448","messageId":"20240606075601.6989-5-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240606075601.6989-1-chandrapratap3519@gmail.com","subject":"[GSoC][PATCH 4/6] t-reftable-pq: make merged_iter_pqueue_check() callable by reference","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-06T07:40:48Z","receivedAt":"2024-06-06T07:57:24Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"merged_iter_pqueue_check() checks the validity of a priority queue\nrepresented by a merged_iter_pqueue struct by asserting the\nparent-child relation in the struct's heap. Explicity passing a\nstruct to this function means a copy of the entire struct is created,\nwhich is inefficient.\n\nMake the function accept a pointer to the struct instead. This is\nsafe to do since the function doesn't modify the struct in any way.\nMake the function parameter 'const' to assert immutability.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n t/unit-tests/t-reftable-pq.c | 10 +++++-----\n 1 file changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex 5c5a4ecdc5..30bf9cb492 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -10,11 +10,11 @@ license that can be found in the LICENSE file or at\n #include \"reftable/constants.h\"\n #include \"reftable/pq.h\"\n \n-static void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n+static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n {\n-\tfor (int i = 1; i < pq.len; i++) {\n+\tfor (int i = 1; i < pq->len; i++) {\n \t\tint parent = (i - 1) / 2;\n-\t\tcheck(pq_less(&pq.heap[parent], &pq.heap[i]));\n+\t\tcheck(pq_less(&pq->heap[parent], &pq->heap[i]));\n \t}\n }\n \n@@ -40,13 +40,13 @@ static void test_pq(void)\n \t\t};\n \n \t\tmerged_iter_pqueue_add(&pq, &e);\n-\t\tmerged_iter_pqueue_check(pq);\n+\t\tmerged_iter_pqueue_check(&pq);\n \t\ti = (i * 7) % N;\n \t} while (i != 1);\n \n \twhile (!merged_iter_pqueue_is_empty(pq)) {\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n-\t\tmerged_iter_pqueue_check(pq);\n+\t\tmerged_iter_pqueue_check(&pq);\n \n \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tif (last)\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"496449","messageId":"20240606075601.6989-6-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240606075601.6989-1-chandrapratap3519@gmail.com","subject":"[GSoC][PATCH 5/6] t-reftable-pq: add test for index based comparison","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-06T07:40:49Z","receivedAt":"2024-06-06T07:57:27Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"When comparing two entries, the priority queue as defined by\nreftable/pq.{c, h} first compares the entries on the basis of\ntheir ref-record's keys. If the keys turn out to be equal, the\ncomparison is then made on the basis of their update indices\n(which are never equal).\n\nIn the current testing setup, only the case for comparison on\nthe basis of ref-record's keys is exercised. Add a test for\nindex-based comparison as well. Rename the existing test to\nreflect its nature of only testing record-based comparison.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n t/unit-tests/t-reftable-pq.c | 44 ++++++++++++++++++++++++++++++++++--\n 1 file changed, 42 insertions(+), 2 deletions(-)\n\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex 30bf9cb492..6f6bf58307 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -18,7 +18,7 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n \t}\n }\n \n-static void test_pq(void)\n+static void test_pq_record(void)\n {\n \tstruct merged_iter_pqueue pq = { 0 };\n \tstruct reftable_record recs[54];\n@@ -59,9 +59,49 @@ static void test_pq(void)\n \tmerged_iter_pqueue_release(&pq);\n }\n \n+\n+static void test_pq_index(void)\n+{\n+\tstruct merged_iter_pqueue pq = { 0 };\n+\tstruct reftable_record recs[14];\n+\tchar *last = NULL;\n+\tsize_t N = ARRAY_SIZE(recs), i;\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n+\t\trecs[i].u.ref.refname = xstrdup(\"refs/heads/master\");\n+\t}\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\tstruct pq_entry e = {\n+\t\t\t.rec = &recs[i],\n+\t\t\t.index = i,\n+\t\t};\n+\n+\t\tmerged_iter_pqueue_add(&pq, &e);\n+\t\tmerged_iter_pqueue_check(&pq);\n+\t}\n+\n+\tfor (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) {\n+\t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n+\t\tmerged_iter_pqueue_check(&pq);\n+\n+\t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n+\t\tcheck_int(e.index, ==, i);\n+\t\tif (last)\n+\t\t\tcheck_str(last, e.rec->u.ref.refname);\n+\t\tlast = e.rec->u.ref.refname;\n+\t}\n+\n+\tfor (i = 0; i < N; i++)\n+\t\treftable_record_release(&recs[i]);\n+\tmerged_iter_pqueue_release(&pq);\n+}\n+\n int cmd_main(int argc, const char *argv[])\n {\n-\tTEST(test_pq(), \"pq works\");\n+\tTEST(test_pq_record(), \"pq works with record-based comparison\");\n+\tTEST(test_pq_index(), \"pq works with index-based comparison\");\n \n \treturn test_done();\n }\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"496450","messageId":"20240606075601.6989-7-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240606075601.6989-1-chandrapratap3519@gmail.com","subject":"[GSoC][PATCH 6/6] t-reftable-pq: add tests for merged_iter_pqueue_top()","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-06T07:40:50Z","receivedAt":"2024-06-06T07:57:30Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"merged_iter_pqueue_top() as defined by reftable/pq.{c, h} returns\nthe element at the top of a priority-queue's heap without removing\nit. Since there are no tests for this function in the existing\nsetup, add tests for the same.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n t/unit-tests/t-reftable-pq.c | 49 +++++++++++++++++++++++++++++++++++-\n 1 file changed, 48 insertions(+), 1 deletion(-)\n\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex 6f6bf58307..768337912f 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -18,6 +18,11 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n \t}\n }\n \n+static int pq_entry_equal(struct pq_entry *a, struct pq_entry *b)\n+{\n+\treturn !reftable_record_cmp(a->rec, b->rec) && (a->index == b->index);\n+}\n+\n static void test_pq_record(void)\n {\n \tstruct merged_iter_pqueue pq = { 0 };\n@@ -45,9 +50,11 @@ static void test_pq_record(void)\n \t} while (i != 1);\n \n \twhile (!merged_iter_pqueue_is_empty(pq)) {\n+\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n \t\tmerged_iter_pqueue_check(&pq);\n \n+\t\tcheck(pq_entry_equal(&top, &e));\n \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tif (last)\n \t\t\tcheck_int(strcmp(last, e.rec->u.ref.refname), <, 0);\n@@ -59,7 +66,6 @@ static void test_pq_record(void)\n \tmerged_iter_pqueue_release(&pq);\n }\n \n-\n static void test_pq_index(void)\n {\n \tstruct merged_iter_pqueue pq = { 0 };\n@@ -83,9 +89,11 @@ static void test_pq_index(void)\n \t}\n \n \tfor (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) {\n+\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n \t\tmerged_iter_pqueue_check(&pq);\n \n+\t\tcheck(pq_entry_equal(&top, &e));\n \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tcheck_int(e.index, ==, i);\n \t\tif (last)\n@@ -98,10 +106,49 @@ static void test_pq_index(void)\n \tmerged_iter_pqueue_release(&pq);\n }\n \n+static void test_merged_iter_pqueue_top(void)\n+{\n+\tstruct merged_iter_pqueue pq = { 0 };\n+\tstruct reftable_record recs[14];\n+\tsize_t N = ARRAY_SIZE(recs), i;\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n+\t\trecs[i].u.ref.refname = xstrdup(\"refs/heads/master\");\n+\t}\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\tstruct pq_entry e = {\n+\t\t\t.rec = &recs[i],\n+\t\t\t.index = i,\n+\t\t};\n+\n+\t\tmerged_iter_pqueue_add(&pq, &e);\n+\t\tmerged_iter_pqueue_check(&pq);\n+\t}\n+\n+\twhile (!merged_iter_pqueue_is_empty(pq)) {\n+\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n+\t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n+\n+\t\tmerged_iter_pqueue_check(&pq);\n+\t\tcheck(pq_entry_equal(&top, &e));\n+\t\tfor (i = 0; i < pq.len; i++) {\n+\t\t\tcheck(pq_less(&top, &pq.heap[i]));\n+\t\t\tcheck_int(top.index, >, i);\n+\t\t}\n+\t}\n+\n+\tfor (i = 0; i < N; i++)\n+\t\treftable_record_release(&recs[i]);\n+\tmerged_iter_pqueue_release(&pq);\n+}\n+\n int cmd_main(int argc, const char *argv[])\n {\n \tTEST(test_pq_record(), \"pq works with record-based comparison\");\n \tTEST(test_pq_index(), \"pq works with index-based comparison\");\n+\tTEST(test_merged_iter_pqueue_top(), \"merged_iter_pqueue_top works\");\n \n \treturn test_done();\n }\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"496469","messageId":"CAP8UFD3SZ6z35QOqDpVowtBKiH53GR_0Ok3Jq=6dvaxaDv444A@mail.gmail.com","threadId":"61595","inReplyTo":"20240606075601.6989-2-chandrapratap3519@gmail.com","subject":"Re: [GSoC][PATCH 1/6] reftable: clean up reftable/pq.c","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2024-06-06T08:51:00Z","receivedAt":"2024-06-06T08:51:14Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Thu, Jun 6, 2024 at 9:57 AM Chandra Pratap\n<chandrapratap3519@gmail.com> wrote:\n>\n> According to Documentation/CodingGuidelines, control-flow statements\n> with a single line as their body must omit curly braces. Make\n> reftable/pq.c conform to this guideline. Besides that, remove\n> unnecessary newlines and variable assignment.\n\nA commit subject like \"reftable/pq: remove unnecessary curly braces\"\nmight be a bit more specific.\n"},{"id":"496482","messageId":"CA+J6zkTMgvvSbUC5t39s4U80MAk+og5ENQf3StdJ2-MM82MAZA@mail.gmail.com","threadId":"61595","inReplyTo":"CAP8UFD3SZ6z35QOqDpVowtBKiH53GR_0Ok3Jq=6dvaxaDv444A@mail.gmail.com","subject":"Re: [GSoC][PATCH 1/6] reftable: clean up reftable/pq.c","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-06T10:07:35Z","receivedAt":"2024-06-06T10:07:47Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"On Thu, 6 Jun 2024 at 14:21, Christian Couder\n<christian.couder@gmail.com> wrote:\n>\n> On Thu, Jun 6, 2024 at 9:57 AM Chandra Pratap\n> <chandrapratap3519@gmail.com> wrote:\n> >\n> > According to Documentation/CodingGuidelines, control-flow statements\n> > with a single line as their body must omit curly braces. Make\n> > reftable/pq.c conform to this guideline. Besides that, remove\n> > unnecessary newlines and variable assignment.\n>\n> A commit subject like \"reftable/pq: remove unnecessary curly braces\"\n> might be a bit more specific.\n\nThere are other forms of cleanup also being performed, like removing\nunnecessary newlines and variable assignment. Would it still be okay\nto sweep it all under 'removing unnecessary braces'?\n"},{"id":"496515","messageId":"ZmGiH5fxkrby0JyQ@tanuki","threadId":"61595","inReplyTo":"20240606075601.6989-3-chandrapratap3519@gmail.com","subject":"Re: [GSoC][PATCH 2/6] t: move reftable/pq_test.c to the unit testing framework","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-06-06T11:48:47Z","receivedAt":"2024-06-06T11:48:54Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Jun 06, 2024 at 01:10:46PM +0530, Chandra Pratap wrote:\n> reftable/pq_test.c exercises a priority queue defined by\n> reftable/pq.{c, h}. Migrate reftable/pq_test.c to the unit\n> testing framework. Migration involves refactoring the tests\n> to use the unit testing framework instead of reftable's test\n> framework.\n> \n> Mentored-by: Patrick Steinhardt <ps@pks.im>\n> Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n> Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n> ---\n>  Makefile                                      |  2 +-\n>  t/helper/test-reftable.c                      |  1 -\n>  .../pq_test.c => t/unit-tests/t-reftable-pq.c | 35 ++++++++-----------\n>  3 files changed, 15 insertions(+), 23 deletions(-)\n>  rename reftable/pq_test.c => t/unit-tests/t-reftable-pq.c (64%)\n> \n> diff --git a/Makefile b/Makefile\n> index 59d98ba688..1cabe4cc69 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -1336,6 +1336,7 @@ THIRD_PARTY_SOURCES += sha1dc/%\n>  UNIT_TEST_PROGRAMS += t-ctype\n>  UNIT_TEST_PROGRAMS += t-mem-pool\n>  UNIT_TEST_PROGRAMS += t-prio-queue\n> +UNIT_TEST_PROGRAMS += t-reftable-pq\n>  UNIT_TEST_PROGRAMS += t-strbuf\n>  UNIT_TEST_PROGRAMS += t-strcmp-offset\n>  UNIT_TEST_PROGRAMS += t-trailer\n> @@ -2675,7 +2676,6 @@ REFTABLE_TEST_OBJS += reftable/basics_test.o\n>  REFTABLE_TEST_OBJS += reftable/block_test.o\n>  REFTABLE_TEST_OBJS += reftable/dump.o\n>  REFTABLE_TEST_OBJS += reftable/merged_test.o\n> -REFTABLE_TEST_OBJS += reftable/pq_test.o\n>  REFTABLE_TEST_OBJS += reftable/record_test.o\n>  REFTABLE_TEST_OBJS += reftable/readwrite_test.o\n>  REFTABLE_TEST_OBJS += reftable/stack_test.o\n> diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c\n> index bae731669c..86a2b0f91a 100644\n> --- a/t/helper/test-reftable.c\n> +++ b/t/helper/test-reftable.c\n> @@ -9,7 +9,6 @@ int cmd__reftable(int argc, const char **argv)\n>  \trecord_test_main(argc, argv);\n>  \tblock_test_main(argc, argv);\n>  \ttree_test_main(argc, argv);\n> -\tpq_test_main(argc, argv);\n>  \treadwrite_test_main(argc, argv);\n>  \tmerged_test_main(argc, argv);\n>  \tstack_test_main(argc, argv);\n> diff --git a/reftable/pq_test.c b/t/unit-tests/t-reftable-pq.c\n> similarity index 64%\n> rename from reftable/pq_test.c\n> rename to t/unit-tests/t-reftable-pq.c\n> index b7d3c80cc7..dcde73de66 100644\n> --- a/reftable/pq_test.c\n> +++ b/t/unit-tests/t-reftable-pq.c\n> @@ -6,35 +6,28 @@ license that can be found in the LICENSE file or at\n>  https://developers.google.com/open-source/licenses/bsd\n>  */\n>  \n> -#include \"system.h\"\n> -\n> -#include \"basics.h\"\n> -#include \"constants.h\"\n> -#include \"pq.h\"\n> -#include \"record.h\"\n> -#include \"reftable-tests.h\"\n> -#include \"test_framework.h\"\n> +#include \"test-lib.h\"\n> +#include \"reftable/constants.h\"\n> +#include \"reftable/pq.h\"\n>  \n>  void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n>  {\n> -\tint i;\n> -\tfor (i = 1; i < pq.len; i++) {\n> +\tfor (int i = 1; i < pq.len; i++) {\n\nIf we're changing this already, then we can also convert it to `size_t\ni` while at it to match the type of `pq.len`.\n\n>  \t\tint parent = (i - 1) / 2;\n> -\n> -\t\tEXPECT(pq_less(&pq.heap[parent], &pq.heap[i]));\n> +\t\tcheck(pq_less(&pq.heap[parent], &pq.heap[i]));\n>  \t}\n>  }\n>  \n>  static void test_pq(void)\n>  {\n> -\tstruct merged_iter_pqueue pq = { NULL };\n> +\tstruct merged_iter_pqueue pq = { 0 };\n>  \tstruct reftable_record recs[54];\n> -\tint N = ARRAY_SIZE(recs) - 1, i;\n> +\tsize_t N = ARRAY_SIZE(recs) - 1, i;\n>  \tchar *last = NULL;\n>  \n>  \tfor (i = 0; i < N; i++) {\n>  \t\tstruct strbuf refname = STRBUF_INIT;\n> -\t\tstrbuf_addf(&refname, \"%02d\", i);\n> +\t\tstrbuf_addf(&refname, \"%02ld\", (long)i);\n\nThis should rather be:\n\n    strubf_addf(&refname, \"%02\"PRIuMAX, (uintmax_t) i);\n\nThis is splitting hairs though as it does not matter in practice. But\nI'd either drop this change to convert `N` and `i` to become a `size_t`,\nor I'd do it correctly.\n\n>  \t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n>  \t\trecs[i].u.ref.refname = strbuf_detach(&refname, NULL);\n> @@ -48,7 +41,6 @@ static void test_pq(void)\n>  \n>  \t\tmerged_iter_pqueue_add(&pq, &e);\n>  \t\tmerged_iter_pqueue_check(pq);\n> -\n>  \t\ti = (i * 7) % N;\n>  \t} while (i != 1);\n\nThis removed newline is of dubious value, but I guess that's\nsubjective.\n\nPatrick\n"},{"id":"496516","messageId":"ZmGiJHeyWO4X-mev@tanuki","threadId":"61595","inReplyTo":"20240606075601.6989-5-chandrapratap3519@gmail.com","subject":"Re: [GSoC][PATCH 4/6] t-reftable-pq: make merged_iter_pqueue_check() callable by reference","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-06-06T11:48:52Z","receivedAt":"2024-06-06T11:48:56Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Jun 06, 2024 at 01:10:48PM +0530, Chandra Pratap wrote:\n> diff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\n> index 5c5a4ecdc5..30bf9cb492 100644\n> --- a/t/unit-tests/t-reftable-pq.c\n> +++ b/t/unit-tests/t-reftable-pq.c\n> @@ -10,11 +10,11 @@ license that can be found in the LICENSE file or at\n>  #include \"reftable/constants.h\"\n>  #include \"reftable/pq.h\"\n>  \n> -static void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n> +static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n>  {\n> -\tfor (int i = 1; i < pq.len; i++) {\n> +\tfor (int i = 1; i < pq->len; i++) {\n\nNit: we might also change this to `size_t i` while at it. I know that\nthese changes are not super popular, but I eventually want Git to\ncompile cleanly with `-Wsign-conversion`. So the more issues we fix\nwhile at it, the smaller the patch series for this needs to be.\n\nPatrick\n"},{"id":"496517","messageId":"ZmGiK9aiSaXX8nXR@tanuki","threadId":"61595","inReplyTo":"20240606075601.6989-6-chandrapratap3519@gmail.com","subject":"Re: [GSoC][PATCH 5/6] t-reftable-pq: add test for index based comparison","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-06-06T11:48:59Z","receivedAt":"2024-06-06T11:49:03Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Jun 06, 2024 at 01:10:49PM +0530, Chandra Pratap wrote:\n> diff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\n> index 30bf9cb492..6f6bf58307 100644\n> --- a/t/unit-tests/t-reftable-pq.c\n> +++ b/t/unit-tests/t-reftable-pq.c\n> @@ -18,7 +18,7 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n>  \t}\n>  }\n>  \n> -static void test_pq(void)\n> +static void test_pq_record(void)\n>  {\n>  \tstruct merged_iter_pqueue pq = { 0 };\n>  \tstruct reftable_record recs[54];\n> @@ -59,9 +59,49 @@ static void test_pq(void)\n>  \tmerged_iter_pqueue_release(&pq);\n>  }\n>  \n> +\n\nNit: there's an extraneous empty line here.\n\nOther than that this patch looks good to me.\n\nPatrick\n"},{"id":"496518","messageId":"ZmGiMPHyVufQYKwY@tanuki","threadId":"61595","inReplyTo":"20240606075601.6989-7-chandrapratap3519@gmail.com","subject":"Re: [GSoC][PATCH 6/6] t-reftable-pq: add tests for merged_iter_pqueue_top()","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-06-06T11:49:04Z","receivedAt":"2024-06-06T11:49:08Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Jun 06, 2024 at 01:10:50PM +0530, Chandra Pratap wrote:\n> @@ -59,7 +66,6 @@ static void test_pq_record(void)\n>  \tmerged_iter_pqueue_release(&pq);\n>  }\n>  \n> -\n>  static void test_pq_index(void)\n>  {\n>  \tstruct merged_iter_pqueue pq = { 0 };\n\nAh, you drop the newline here. This should probably be part of the\npreceding commit.\n\n> @@ -98,10 +106,49 @@ static void test_pq_index(void)\n>  \tmerged_iter_pqueue_release(&pq);\n>  }\n>  \n> +static void test_merged_iter_pqueue_top(void)\n> +{\n> +\tstruct merged_iter_pqueue pq = { 0 };\n> +\tstruct reftable_record recs[14];\n> +\tsize_t N = ARRAY_SIZE(recs), i;\n> +\n> +\tfor (i = 0; i < N; i++) {\n> +\t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n> +\t\trecs[i].u.ref.refname = xstrdup(\"refs/heads/master\");\n> +\t}\n> +\n> +\tfor (i = 0; i < N; i++) {\n> +\t\tstruct pq_entry e = {\n> +\t\t\t.rec = &recs[i],\n> +\t\t\t.index = i,\n> +\t\t};\n> +\n> +\t\tmerged_iter_pqueue_add(&pq, &e);\n> +\t\tmerged_iter_pqueue_check(&pq);\n> +\t}\n> +\n> +\twhile (!merged_iter_pqueue_is_empty(pq)) {\n> +\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n> +\t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n> +\n> +\t\tmerged_iter_pqueue_check(&pq);\n> +\t\tcheck(pq_entry_equal(&top, &e));\n\nDo we also want to check that `top` is equal to the expected entry in\n`recs`?\n\nPatrick\n"},{"id":"496528","messageId":"20240606154712.15935-1-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240606075601.6989-1-chandrapratap3519@gmail.com","subject":"[GSoC][PATCH v2 0/6] t: port reftable/pq_test.c to the unit testing","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-06T15:23:36Z","receivedAt":"2024-06-06T15:48:14Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"In the recent codebase update (commit 8bf6fbd, 2023-12-09), a new unit\ntesting framework written entirely in C was introduced to the Git project\naimed at simplifying testing and reducing test run times.\nCurrently, tests for the reftable refs-backend are performed by a custom\ntesting framework defined by reftable/test_framework.{c, h}. Port\nreftable/pq_test.c to the unit testing framework and improve upon\nthe ported test.\n\nThe first patch in the series is preparatory cleanup, the second patch\nmoves the test to the unit testing framework, and the rest of the patches\nimprove upon the ported test.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n\n---\nChanges in v2:\n- Change data type of index variable 'i' to 'size_t' from 'int'\n- Use correct format specifier for 'size_t' types\n- Improve the test for merged_iter_pqueue_top() by asserting equality\n  between 'top.rec' and the corresponding record in 'recs' array\n\nCI/PR for v2: https://github.com/gitgitgadget/git/pull/1745\n\nChandra Pratap (6):\nreftable: clean up reftable/pq.c\nt: move reftable/pq_test.c to the unit testing framework\nt-reftable-pq: make merged_iter_pqueue_check() static\nt-reftable-pq: make merged_iter_pqueue_check() callable\nt-reftable-pq: add test for index based comparison\nt-reftable-pq: add tests for merged_iter_pqueue_top()\n\nMakefile                     |   2 +-\nreftable/pq.c                |  18 +++--------\nreftable/pq.h                |   1 -\nreftable/pq_test.c           |  74 ----------------------------\nt/helper/test-reftable.c     |   1 -\nt/unit-tests/t-reftable-pq.c | 155 +++++++++++++++++++++++++++++++++++++++++++++\n6 files changed, 160 insertions(+), 91 deletions(-)\n\n\nRange-diff against v1:\n1:  f18b610f63 ! 1:  f24dc84877 t: move reftable/pq_test.c to the unit testing framework\n    @@ t/unit-tests/t-reftable-pq.c: license that can be found in the LICENSE file or a\n      {\n     -\tint i;\n     -\tfor (i = 1; i < pq.len; i++) {\n    -+\tfor (int i = 1; i < pq.len; i++) {\n    - \t\tint parent = (i - 1) / 2;\n    +-\t\tint parent = (i - 1) / 2;\n     -\n     -\t\tEXPECT(pq_less(&pq.heap[parent], &pq.heap[i]));\n    ++\tfor (size_t i = 1; i < pq.len; i++) {\n    ++\t\tsize_t parent = (i - 1) / 2;\n     +\t\tcheck(pq_less(&pq.heap[parent], &pq.heap[i]));\n      \t}\n      }\n    @@ t/unit-tests/t-reftable-pq.c: license that can be found in the LICENSE file or a\n      \tfor (i = 0; i < N; i++) {\n      \t\tstruct strbuf refname = STRBUF_INIT;\n     -\t\tstrbuf_addf(&refname, \"%02d\", i);\n    -+\t\tstrbuf_addf(&refname, \"%02ld\", (long)i);\n    ++\t\tstrbuf_addf(&refname, \"%02\"PRIuMAX, (uintmax_t)i);\n\n      \t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n      \t\trecs[i].u.ref.refname = strbuf_detach(&refname, NULL);\n2:  798e0adfeb ! 2:  ce42fd1288 t-reftable-pq: make merged_iter_pqueue_check() static\n    @@ t/unit-tests/t-reftable-pq.c: license that can be found in the LICENSE file or a\n     -void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n     +static void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n      {\n    - \tfor (int i = 1; i < pq.len; i++) {\n    - \t\tint parent = (i - 1) / 2;\n    + \tfor (size_t i = 1; i < pq.len; i++) {\n    + \t\tsize_t parent = (i - 1) / 2;\n3:  8412672105 ! 3:  226d72aa6a t-reftable-pq: make merged_iter_pqueue_check() callable by reference\n    @@ t/unit-tests/t-reftable-pq.c: license that can be found in the LICENSE file or a\n     -static void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n     +static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n      {\n    --\tfor (int i = 1; i < pq.len; i++) {\n    -+\tfor (int i = 1; i < pq->len; i++) {\n    - \t\tint parent = (i - 1) / 2;\n    +-\tfor (size_t i = 1; i < pq.len; i++) {\n    ++\tfor (size_t i = 1; i < pq->len; i++) {\n    + \t\tsize_t parent = (i - 1) / 2;\n     -\t\tcheck(pq_less(&pq.heap[parent], &pq.heap[i]));\n     +\t\tcheck(pq_less(&pq->heap[parent], &pq->heap[i]));\n      \t}\n4:  2ef5b8b0b1 ! 4:  00cb440f11 t-reftable-pq: add test for index based comparison\n    @@ t/unit-tests/t-reftable-pq.c: static void test_pq(void)\n      \tmerged_iter_pqueue_release(&pq);\n      }\n\n    -+\n     +static void test_pq_index(void)\n     +{\n     +\tstruct merged_iter_pqueue pq = { 0 };\n5:  838e67d2a3 ! 5:  dd44486c28 t-reftable-pq: add tests for merged_iter_pqueue_top()\n    @@ t/unit-tests/t-reftable-pq.c: static void test_pq_record(void)\n      \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n      \t\tif (last)\n      \t\t\tcheck_int(strcmp(last, e.rec->u.ref.refname), <, 0);\n    -@@ t/unit-tests/t-reftable-pq.c: static void test_pq_record(void)\n    - \tmerged_iter_pqueue_release(&pq);\n    - }\n    -\n    --\n    - static void test_pq_index(void)\n    - {\n    - \tstruct merged_iter_pqueue pq = { 0 };\n     @@ t/unit-tests/t-reftable-pq.c: static void test_pq_index(void)\n      \t}\n\n    @@ t/unit-tests/t-reftable-pq.c: static void test_pq_index(void)\n     +\t\tmerged_iter_pqueue_check(&pq);\n     +\t}\n     +\n    -+\twhile (!merged_iter_pqueue_is_empty(pq)) {\n    ++\tfor (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) {\n     +\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n     +\t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n     +\n     +\t\tmerged_iter_pqueue_check(&pq);\n     +\t\tcheck(pq_entry_equal(&top, &e));\n    -+\t\tfor (i = 0; i < pq.len; i++) {\n    -+\t\t\tcheck(pq_less(&top, &pq.heap[i]));\n    -+\t\t\tcheck_int(top.index, >, i);\n    ++\t\tcheck(reftable_record_equal(top.rec, &recs[i], GIT_SHA1_RAWSZ));\n    ++\t\tfor (size_t j = 0; i < pq.len; j++) {\n    ++\t\t\tcheck(pq_less(&top, &pq.heap[j]));\n    ++\t\t\tcheck_int(top.index, >, j);\n     +\t\t}\n     +\t}\n     +\n"},{"id":"496529","messageId":"20240606154712.15935-2-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240606154712.15935-1-chandrapratap3519@gmail.com","subject":"[GSoC][PATCH v2 1/6] reftable: clean up reftable/pq.c","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-06T15:23:37Z","receivedAt":"2024-06-06T15:48:17Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"According to Documentation/CodingGuidelines, control-flow statements\nwith a single line as their body must omit curly braces. Make\nreftable/pq.c conform to this guideline. Besides that, remove\nunnecessary newlines and variable assignment.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n reftable/pq.c | 18 ++++--------------\n 1 file changed, 4 insertions(+), 14 deletions(-)\n\ndiff --git a/reftable/pq.c b/reftable/pq.c\nindex 7fb45d8c60..0401c47068 100644\n--- a/reftable/pq.c\n+++ b/reftable/pq.c\n@@ -27,22 +27,16 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n \tpq->heap[0] = pq->heap[pq->len - 1];\n \tpq->len--;\n \n-\ti = 0;\n \twhile (i < pq->len) {\n \t\tint min = i;\n \t\tint j = 2 * i + 1;\n \t\tint k = 2 * i + 2;\n-\t\tif (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i])) {\n+\t\tif (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tmin = j;\n-\t\t}\n-\t\tif (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min])) {\n+\t\tif (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min]))\n \t\t\tmin = k;\n-\t\t}\n-\n-\t\tif (min == i) {\n+\t\tif (min == i)\n \t\t\tbreak;\n-\t\t}\n-\n \t\tSWAP(pq->heap[i], pq->heap[min]);\n \t\ti = min;\n \t}\n@@ -53,19 +47,15 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e)\n {\n \tint i = 0;\n-\n \tREFTABLE_ALLOC_GROW(pq->heap, pq->len + 1, pq->cap);\n \tpq->heap[pq->len++] = *e;\n \n \ti = pq->len - 1;\n \twhile (i > 0) {\n \t\tint j = (i - 1) / 2;\n-\t\tif (pq_less(&pq->heap[j], &pq->heap[i])) {\n+\t\tif (pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tbreak;\n-\t\t}\n-\n \t\tSWAP(pq->heap[j], pq->heap[i]);\n-\n \t\ti = j;\n \t}\n }\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"496530","messageId":"20240606154712.15935-3-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240606154712.15935-1-chandrapratap3519@gmail.com","subject":"[GSoC][PATCH v2 2/6] t: move reftable/pq_test.c to the unit testing framework","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-06T15:23:38Z","receivedAt":"2024-06-06T15:48:23Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"reftable/pq_test.c exercises a priority queue defined by\nreftable/pq.{c, h}. Migrate reftable/pq_test.c to the unit\ntesting framework. Migration involves refactoring the tests\nto use the unit testing framework instead of reftable's test\nframework.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n Makefile                                      |  2 +-\n t/helper/test-reftable.c                      |  1 -\n .../pq_test.c => t/unit-tests/t-reftable-pq.c | 37 ++++++++-----------\n 3 files changed, 16 insertions(+), 24 deletions(-)\n rename reftable/pq_test.c => t/unit-tests/t-reftable-pq.c (62%)\n\ndiff --git a/Makefile b/Makefile\nindex 59d98ba688..1cabe4cc69 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1336,6 +1336,7 @@ THIRD_PARTY_SOURCES += sha1dc/%\n UNIT_TEST_PROGRAMS += t-ctype\n UNIT_TEST_PROGRAMS += t-mem-pool\n UNIT_TEST_PROGRAMS += t-prio-queue\n+UNIT_TEST_PROGRAMS += t-reftable-pq\n UNIT_TEST_PROGRAMS += t-strbuf\n UNIT_TEST_PROGRAMS += t-strcmp-offset\n UNIT_TEST_PROGRAMS += t-trailer\n@@ -2675,7 +2676,6 @@ REFTABLE_TEST_OBJS += reftable/basics_test.o\n REFTABLE_TEST_OBJS += reftable/block_test.o\n REFTABLE_TEST_OBJS += reftable/dump.o\n REFTABLE_TEST_OBJS += reftable/merged_test.o\n-REFTABLE_TEST_OBJS += reftable/pq_test.o\n REFTABLE_TEST_OBJS += reftable/record_test.o\n REFTABLE_TEST_OBJS += reftable/readwrite_test.o\n REFTABLE_TEST_OBJS += reftable/stack_test.o\ndiff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c\nindex bae731669c..86a2b0f91a 100644\n--- a/t/helper/test-reftable.c\n+++ b/t/helper/test-reftable.c\n@@ -9,7 +9,6 @@ int cmd__reftable(int argc, const char **argv)\n \trecord_test_main(argc, argv);\n \tblock_test_main(argc, argv);\n \ttree_test_main(argc, argv);\n-\tpq_test_main(argc, argv);\n \treadwrite_test_main(argc, argv);\n \tmerged_test_main(argc, argv);\n \tstack_test_main(argc, argv);\ndiff --git a/reftable/pq_test.c b/t/unit-tests/t-reftable-pq.c\nsimilarity index 62%\nrename from reftable/pq_test.c\nrename to t/unit-tests/t-reftable-pq.c\nindex b7d3c80cc7..a47a9473f3 100644\n--- a/reftable/pq_test.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -6,35 +6,28 @@ license that can be found in the LICENSE file or at\n https://developers.google.com/open-source/licenses/bsd\n */\n \n-#include \"system.h\"\n-\n-#include \"basics.h\"\n-#include \"constants.h\"\n-#include \"pq.h\"\n-#include \"record.h\"\n-#include \"reftable-tests.h\"\n-#include \"test_framework.h\"\n+#include \"test-lib.h\"\n+#include \"reftable/constants.h\"\n+#include \"reftable/pq.h\"\n \n void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n {\n-\tint i;\n-\tfor (i = 1; i < pq.len; i++) {\n-\t\tint parent = (i - 1) / 2;\n-\n-\t\tEXPECT(pq_less(&pq.heap[parent], &pq.heap[i]));\n+\tfor (size_t i = 1; i < pq.len; i++) {\n+\t\tsize_t parent = (i - 1) / 2;\n+\t\tcheck(pq_less(&pq.heap[parent], &pq.heap[i]));\n \t}\n }\n \n static void test_pq(void)\n {\n-\tstruct merged_iter_pqueue pq = { NULL };\n+\tstruct merged_iter_pqueue pq = { 0 };\n \tstruct reftable_record recs[54];\n-\tint N = ARRAY_SIZE(recs) - 1, i;\n+\tsize_t N = ARRAY_SIZE(recs) - 1, i;\n \tchar *last = NULL;\n \n \tfor (i = 0; i < N; i++) {\n \t\tstruct strbuf refname = STRBUF_INIT;\n-\t\tstrbuf_addf(&refname, \"%02d\", i);\n+\t\tstrbuf_addf(&refname, \"%02\"PRIuMAX, (uintmax_t)i);\n \n \t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n \t\trecs[i].u.ref.refname = strbuf_detach(&refname, NULL);\n@@ -48,7 +41,6 @@ static void test_pq(void)\n \n \t\tmerged_iter_pqueue_add(&pq, &e);\n \t\tmerged_iter_pqueue_check(pq);\n-\n \t\ti = (i * 7) % N;\n \t} while (i != 1);\n \n@@ -56,9 +48,9 @@ static void test_pq(void)\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n \t\tmerged_iter_pqueue_check(pq);\n \n-\t\tEXPECT(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n+\t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tif (last)\n-\t\t\tEXPECT(strcmp(last, e.rec->u.ref.refname) < 0);\n+\t\t\tcheck_int(strcmp(last, e.rec->u.ref.refname), <, 0);\n \t\tlast = e.rec->u.ref.refname;\n \t}\n \n@@ -67,8 +59,9 @@ static void test_pq(void)\n \tmerged_iter_pqueue_release(&pq);\n }\n \n-int pq_test_main(int argc, const char *argv[])\n+int cmd_main(int argc, const char *argv[])\n {\n-\tRUN_TEST(test_pq);\n-\treturn 0;\n+\tTEST(test_pq(), \"pq works\");\n+\n+\treturn test_done();\n }\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"496531","messageId":"20240606154712.15935-4-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240606154712.15935-1-chandrapratap3519@gmail.com","subject":"[GSoC][PATCH v2 3/6] t-reftable-pq: make merged_iter_pqueue_check() static","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-06T15:23:39Z","receivedAt":"2024-06-06T15:48:26Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"merged_iter_pqueue_check() is a function previously defined in\nreftable/pq_test.c (now t/unit-tests/t-reftable-pq.c) and used in\nthe testing of a priority queue as defined by reftable/pq.{c, h}.\nAs such, this function is only called by reftable/pq_test.c and it\nmakes little sense to expose it to non-testing code via reftable/pq.h.\n\nHence, make this function static and remove its prototype from\nreftable/pq.h.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n reftable/pq.h                | 1 -\n t/unit-tests/t-reftable-pq.c | 2 +-\n 2 files changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/reftable/pq.h b/reftable/pq.h\nindex f796c23179..707bd26767 100644\n--- a/reftable/pq.h\n+++ b/reftable/pq.h\n@@ -22,7 +22,6 @@ struct merged_iter_pqueue {\n \tsize_t cap;\n };\n \n-void merged_iter_pqueue_check(struct merged_iter_pqueue pq);\n struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq);\n void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e);\n void merged_iter_pqueue_release(struct merged_iter_pqueue *pq);\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex a47a9473f3..7d151f8582 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -10,7 +10,7 @@ license that can be found in the LICENSE file or at\n #include \"reftable/constants.h\"\n #include \"reftable/pq.h\"\n \n-void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n+static void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n {\n \tfor (size_t i = 1; i < pq.len; i++) {\n \t\tsize_t parent = (i - 1) / 2;\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"496532","messageId":"20240606154712.15935-5-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240606154712.15935-1-chandrapratap3519@gmail.com","subject":"[GSoC][PATCH v2 4/6] t-reftable-pq: make merged_iter_pqueue_check() callable by reference","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-06T15:23:40Z","receivedAt":"2024-06-06T15:48:30Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"merged_iter_pqueue_check() checks the validity of a priority queue\nrepresented by a merged_iter_pqueue struct by asserting the\nparent-child relation in the struct's heap. Explicity passing a\nstruct to this function means a copy of the entire struct is created,\nwhich is inefficient.\n\nMake the function accept a pointer to the struct instead. This is\nsafe to do since the function doesn't modify the struct in any way.\nMake the function parameter 'const' to assert immutability.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n t/unit-tests/t-reftable-pq.c | 10 +++++-----\n 1 file changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex 7d151f8582..774c4194e5 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -10,11 +10,11 @@ license that can be found in the LICENSE file or at\n #include \"reftable/constants.h\"\n #include \"reftable/pq.h\"\n \n-static void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n+static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n {\n-\tfor (size_t i = 1; i < pq.len; i++) {\n+\tfor (size_t i = 1; i < pq->len; i++) {\n \t\tsize_t parent = (i - 1) / 2;\n-\t\tcheck(pq_less(&pq.heap[parent], &pq.heap[i]));\n+\t\tcheck(pq_less(&pq->heap[parent], &pq->heap[i]));\n \t}\n }\n \n@@ -40,13 +40,13 @@ static void test_pq(void)\n \t\t};\n \n \t\tmerged_iter_pqueue_add(&pq, &e);\n-\t\tmerged_iter_pqueue_check(pq);\n+\t\tmerged_iter_pqueue_check(&pq);\n \t\ti = (i * 7) % N;\n \t} while (i != 1);\n \n \twhile (!merged_iter_pqueue_is_empty(pq)) {\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n-\t\tmerged_iter_pqueue_check(pq);\n+\t\tmerged_iter_pqueue_check(&pq);\n \n \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tif (last)\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"496533","messageId":"20240606154712.15935-6-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240606154712.15935-1-chandrapratap3519@gmail.com","subject":"[GSoC][PATCH v2 5/6] t-reftable-pq: add test for index based comparison","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-06T15:23:41Z","receivedAt":"2024-06-06T15:48:34Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"When comparing two entries, the priority queue as defined by\nreftable/pq.{c, h} first compares the entries on the basis of\ntheir ref-record's keys. If the keys turn out to be equal, the\ncomparison is then made on the basis of their update indices\n(which are never equal).\n\nIn the current testing setup, only the case for comparison on\nthe basis of ref-record's keys is exercised. Add a test for\nindex-based comparison as well. Rename the existing test to\nreflect its nature of only testing record-based comparison.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n t/unit-tests/t-reftable-pq.c | 43 ++++++++++++++++++++++++++++++++++--\n 1 file changed, 41 insertions(+), 2 deletions(-)\n\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex 774c4194e5..e114a8cb0f 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -18,7 +18,7 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n \t}\n }\n \n-static void test_pq(void)\n+static void test_pq_record(void)\n {\n \tstruct merged_iter_pqueue pq = { 0 };\n \tstruct reftable_record recs[54];\n@@ -59,9 +59,48 @@ static void test_pq(void)\n \tmerged_iter_pqueue_release(&pq);\n }\n \n+static void test_pq_index(void)\n+{\n+\tstruct merged_iter_pqueue pq = { 0 };\n+\tstruct reftable_record recs[14];\n+\tchar *last = NULL;\n+\tsize_t N = ARRAY_SIZE(recs), i;\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n+\t\trecs[i].u.ref.refname = xstrdup(\"refs/heads/master\");\n+\t}\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\tstruct pq_entry e = {\n+\t\t\t.rec = &recs[i],\n+\t\t\t.index = i,\n+\t\t};\n+\n+\t\tmerged_iter_pqueue_add(&pq, &e);\n+\t\tmerged_iter_pqueue_check(&pq);\n+\t}\n+\n+\tfor (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) {\n+\t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n+\t\tmerged_iter_pqueue_check(&pq);\n+\n+\t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n+\t\tcheck_int(e.index, ==, i);\n+\t\tif (last)\n+\t\t\tcheck_str(last, e.rec->u.ref.refname);\n+\t\tlast = e.rec->u.ref.refname;\n+\t}\n+\n+\tfor (i = 0; i < N; i++)\n+\t\treftable_record_release(&recs[i]);\n+\tmerged_iter_pqueue_release(&pq);\n+}\n+\n int cmd_main(int argc, const char *argv[])\n {\n-\tTEST(test_pq(), \"pq works\");\n+\tTEST(test_pq_record(), \"pq works with record-based comparison\");\n+\tTEST(test_pq_index(), \"pq works with index-based comparison\");\n \n \treturn test_done();\n }\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"496534","messageId":"20240606154712.15935-7-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240606154712.15935-1-chandrapratap3519@gmail.com","subject":"[GSoC][PATCH v2 6/6] t-reftable-pq: add tests for merged_iter_pqueue_top()","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-06T15:23:42Z","receivedAt":"2024-06-06T15:48:37Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"merged_iter_pqueue_top() as defined by reftable/pq.{c, h} returns\nthe element at the top of a priority-queue's heap without removing\nit. Since there are no tests for this function in the existing\nsetup, add tests for the same.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n t/unit-tests/t-reftable-pq.c | 49 ++++++++++++++++++++++++++++++++++++\n 1 file changed, 49 insertions(+)\n\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex e114a8cb0f..0e93cc97b1 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -18,6 +18,11 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n \t}\n }\n \n+static int pq_entry_equal(struct pq_entry *a, struct pq_entry *b)\n+{\n+\treturn !reftable_record_cmp(a->rec, b->rec) && (a->index == b->index);\n+}\n+\n static void test_pq_record(void)\n {\n \tstruct merged_iter_pqueue pq = { 0 };\n@@ -45,9 +50,11 @@ static void test_pq_record(void)\n \t} while (i != 1);\n \n \twhile (!merged_iter_pqueue_is_empty(pq)) {\n+\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n \t\tmerged_iter_pqueue_check(&pq);\n \n+\t\tcheck(pq_entry_equal(&top, &e));\n \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tif (last)\n \t\t\tcheck_int(strcmp(last, e.rec->u.ref.refname), <, 0);\n@@ -82,9 +89,11 @@ static void test_pq_index(void)\n \t}\n \n \tfor (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) {\n+\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n \t\tmerged_iter_pqueue_check(&pq);\n \n+\t\tcheck(pq_entry_equal(&top, &e));\n \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tcheck_int(e.index, ==, i);\n \t\tif (last)\n@@ -97,10 +106,50 @@ static void test_pq_index(void)\n \tmerged_iter_pqueue_release(&pq);\n }\n \n+static void test_merged_iter_pqueue_top(void)\n+{\n+\tstruct merged_iter_pqueue pq = { 0 };\n+\tstruct reftable_record recs[14];\n+\tsize_t N = ARRAY_SIZE(recs), i;\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n+\t\trecs[i].u.ref.refname = xstrdup(\"refs/heads/master\");\n+\t}\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\tstruct pq_entry e = {\n+\t\t\t.rec = &recs[i],\n+\t\t\t.index = i,\n+\t\t};\n+\n+\t\tmerged_iter_pqueue_add(&pq, &e);\n+\t\tmerged_iter_pqueue_check(&pq);\n+\t}\n+\n+\tfor (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) {\n+\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n+\t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n+\n+\t\tmerged_iter_pqueue_check(&pq);\n+\t\tcheck(pq_entry_equal(&top, &e));\n+\t\tcheck(reftable_record_equal(top.rec, &recs[i], GIT_SHA1_RAWSZ));\n+\t\tfor (size_t j = 0; i < pq.len; j++) {\n+\t\t\tcheck(pq_less(&top, &pq.heap[j]));\n+\t\t\tcheck_int(top.index, >, j);\n+\t\t}\n+\t}\n+\n+\tfor (i = 0; i < N; i++)\n+\t\treftable_record_release(&recs[i]);\n+\tmerged_iter_pqueue_release(&pq);\n+}\n+\n int cmd_main(int argc, const char *argv[])\n {\n \tTEST(test_pq_record(), \"pq works with record-based comparison\");\n \tTEST(test_pq_index(), \"pq works with index-based comparison\");\n+\tTEST(test_merged_iter_pqueue_top(), \"merged_iter_pqueue_top works\");\n \n \treturn test_done();\n }\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"496541","messageId":"CAP8UFD3xepwyjo1c7LvazpNr-M1BDgUBMbjghgtHbyv0syP6mw@mail.gmail.com","threadId":"61595","inReplyTo":"CA+J6zkTMgvvSbUC5t39s4U80MAk+og5ENQf3StdJ2-MM82MAZA@mail.gmail.com","subject":"Re: [GSoC][PATCH 1/6] reftable: clean up reftable/pq.c","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2024-06-06T16:23:57Z","receivedAt":"2024-06-06T16:24:11Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Thu, Jun 6, 2024 at 12:07 PM Chandra Pratap\n<chandrapratap3519@gmail.com> wrote:\n>\n> On Thu, 6 Jun 2024 at 14:21, Christian Couder\n> <christian.couder@gmail.com> wrote:\n> >\n> > On Thu, Jun 6, 2024 at 9:57 AM Chandra Pratap\n> > <chandrapratap3519@gmail.com> wrote:\n> > >\n> > > According to Documentation/CodingGuidelines, control-flow statements\n> > > with a single line as their body must omit curly braces. Make\n> > > reftable/pq.c conform to this guideline. Besides that, remove\n> > > unnecessary newlines and variable assignment.\n> >\n> > A commit subject like \"reftable/pq: remove unnecessary curly braces\"\n> > might be a bit more specific.\n>\n> There are other forms of cleanup also being performed, like removing\n> unnecessary newlines and variable assignment. Would it still be okay\n> to sweep it all under 'removing unnecessary braces'?\n\nI think the removal of unnecessary braces is the main change and other\nchanges are made while at it, so I think it's Ok.\n"},{"id":"496758","messageId":"ZmatCKg6gbN3Aran@tanuki","threadId":"61595","inReplyTo":"20240606154712.15935-2-chandrapratap3519@gmail.com","subject":"Re: [GSoC][PATCH v2 1/6] reftable: clean up reftable/pq.c","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-06-10T07:36:40Z","receivedAt":"2024-06-10T07:36:45Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Jun 06, 2024 at 08:53:37PM +0530, Chandra Pratap wrote:\n> According to Documentation/CodingGuidelines, control-flow statements\n> with a single line as their body must omit curly braces. Make\n> reftable/pq.c conform to this guideline. Besides that, remove\n> unnecessary newlines and variable assignment.\n> \n> Mentored-by: Patrick Steinhardt <ps@pks.im>\n> Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n> Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n> ---\n>  reftable/pq.c | 18 ++++--------------\n>  1 file changed, 4 insertions(+), 14 deletions(-)\n> \n> diff --git a/reftable/pq.c b/reftable/pq.c\n> index 7fb45d8c60..0401c47068 100644\n> --- a/reftable/pq.c\n> +++ b/reftable/pq.c\n> @@ -27,22 +27,16 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n>  \tpq->heap[0] = pq->heap[pq->len - 1];\n>  \tpq->len--;\n>  \n> -\ti = 0;\n>  \twhile (i < pq->len) {\n>  \t\tint min = i;\n>  \t\tint j = 2 * i + 1;\n>  \t\tint k = 2 * i + 2;\n> -\t\tif (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i])) {\n> +\t\tif (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i]))\n>  \t\t\tmin = j;\n> -\t\t}\n> -\t\tif (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min])) {\n> +\t\tif (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min]))\n>  \t\t\tmin = k;\n> -\t\t}\n> -\n> -\t\tif (min == i) {\n> +\t\tif (min == i)\n>  \t\t\tbreak;\n> -\t\t}\n> -\n>  \t\tSWAP(pq->heap[i], pq->heap[min]);\n>  \t\ti = min;\n>  \t}\n> @@ -53,19 +47,15 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n>  void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e)\n>  {\n>  \tint i = 0;\n> -\n\nNit: I think this newline is helpful as it delimits the variable\ndeclarations from the actual code.\n\nI wonder whether we should also change the type of `i` to `size_t` while\nat it, as `pq->len` is of type `size_t, as well (and further up in the\nother test). It does mean that we have to add an explicit check whether\n`pq->len == 0`, but that isn't all that bad.\n\nIn any case, if we want to do such a change, it should probably be in a\nseparate commit.\n\n>  \tREFTABLE_ALLOC_GROW(pq->heap, pq->len + 1, pq->cap);\n>  \tpq->heap[pq->len++] = *e;\n>  \n>  \ti = pq->len - 1;\n>  \twhile (i > 0) {\n>  \t\tint j = (i - 1) / 2;\n\nThe type of `j` is wrong, as well.\n\nOther than that this patch series looks good to me, thanks.\n\nPatrick\n"},{"id":"496844","messageId":"20240611083157.9876-1-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240606154712.15935-1-chandrapratap3519@gmail.com","subject":"[GSoC][PATCH v3 0/7] t: port reftable/pq_test.c to the unit testing framework","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-11T08:19:17Z","receivedAt":"2024-06-11T08:32:46Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"In the recent codebase update (commit 8bf6fbd, 2023-12-09), a new unit\ntesting framework written entirely in C was introduced to the Git project\naimed at simplifying testing and reducing test run times.\nCurrently, tests for the reftable refs-backend are performed by a custom\ntesting framework defined by reftable/test_framework.{c, h}. Port\nreftable/pq_test.c to the unit testing framework and improve upon\nthe ported test.\n\nThe first two patches in the series are preparatory cleanup, the third patch\nmoves the test to the unit testing framework, and the rest of the patches\nimprove upon the ported test.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n\n---\nChanges in v3:\n- Add another cleanup patch for reftable/pq.c\n- Change the commit title of the first patch\n- Re-introduce a lost newline in the first patch\n\nCI/PR for v3: https://github.com/gitgitgadget/git/pull/1745\n\nChandra Pratap(7):\nreftable: remove unncessary curly braces in reftable/pq.c\nreftable: change the type of array indices to 'size_t' in\nt: move reftable/pq_test.c to the unit testing framework\nt-reftable-pq: make merged_iter_pqueue_check() static\nt-reftable-pq: make merged_iter_pqueue_check() callable\nt-reftable-pq: add test for index based comparison\nt-reftable-pq: add tests for merged_iter_pqueue_top()\n\nMakefile                     |   2 +-\nreftable/pq.c                |  29 +++--------\nreftable/pq.h                |   1 -\nreftable/pq_test.c           |  74 ----------------------------\nt/helper/test-reftable.c     |   1 -\nt/unit-tests/t-reftable-pq.c | 155 +++++++++++++++++++++++++++++++++++++++++++++\n6 files changed, 166 insertions(+), 96 deletions(-)\n\nRange-diff against v2:\n1:  9ac1035c07 ! 1:  d3c5605ea2 reftable: clean up reftable/pq.c\n    @@ Metadata\n     Author: Chandra Pratap <chandrapratap3519@gmail.com>\n     \n      ## Commit message ##\n    -    reftable: clean up reftable/pq.c\n    +    reftable: remove unncessary curly braces in reftable/pq.c\n     \n         According to Documentation/CodingGuidelines, control-flow statements\n         with a single line as their body must omit curly braces. Make\n    @@ reftable/pq.c: struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pque\n      \t\tSWAP(pq->heap[i], pq->heap[min]);\n      \t\ti = min;\n      \t}\n    -@@ reftable/pq.c: struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n    - void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e)\n    - {\n    - \tint i = 0;\n    --\n    - \tREFTABLE_ALLOC_GROW(pq->heap, pq->len + 1, pq->cap);\n    - \tpq->heap[pq->len++] = *e;\n    - \n    +@@ reftable/pq.c: void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry\n      \ti = pq->len - 1;\n      \twhile (i > 0) {\n      \t\tint j = (i - 1) / 2;\n-:  ---------- > 2:  1873fb02ce reftable: change the type of array indices to 'size_t' in reftable/pq.c\n2:  f24dc84877 = 3:  3cccf8266a t: move reftable/pq_test.c to the unit testing framework\n3:  ce42fd1288 = 4:  4b63849694 t-reftable-pq: make merged_iter_pqueue_check() static\n4:  226d72aa6a = 5:  3698a7189f t-reftable-pq: make merged_iter_pqueue_check() callable by reference\n5:  00cb440f11 = 6:  d58c8f709e t-reftable-pq: add test for index based comparison\n6:  dd44486c28 = 7:  69521f0ff7 t-reftable-pq: add tests for merged_iter_pqueue_top()\n\n"},{"id":"496845","messageId":"20240611083157.9876-2-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240611083157.9876-1-chandrapratap3519@gmail.com","subject":"[PATCH v3 1/7] reftable: remove unncessary curly braces in reftable/pq.c","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-11T08:19:18Z","receivedAt":"2024-06-11T08:32:49Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"According to Documentation/CodingGuidelines, control-flow statements\nwith a single line as their body must omit curly braces. Make\nreftable/pq.c conform to this guideline. Besides that, remove\nunnecessary newlines and variable assignment.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n reftable/pq.c | 17 ++++-------------\n 1 file changed, 4 insertions(+), 13 deletions(-)\n\ndiff --git a/reftable/pq.c b/reftable/pq.c\nindex 7fb45d8c60..1a180c5fa6 100644\n--- a/reftable/pq.c\n+++ b/reftable/pq.c\n@@ -27,22 +27,16 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n \tpq->heap[0] = pq->heap[pq->len - 1];\n \tpq->len--;\n \n-\ti = 0;\n \twhile (i < pq->len) {\n \t\tint min = i;\n \t\tint j = 2 * i + 1;\n \t\tint k = 2 * i + 2;\n-\t\tif (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i])) {\n+\t\tif (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tmin = j;\n-\t\t}\n-\t\tif (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min])) {\n+\t\tif (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min]))\n \t\t\tmin = k;\n-\t\t}\n-\n-\t\tif (min == i) {\n+\t\tif (min == i)\n \t\t\tbreak;\n-\t\t}\n-\n \t\tSWAP(pq->heap[i], pq->heap[min]);\n \t\ti = min;\n \t}\n@@ -60,12 +54,9 @@ void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry\n \ti = pq->len - 1;\n \twhile (i > 0) {\n \t\tint j = (i - 1) / 2;\n-\t\tif (pq_less(&pq->heap[j], &pq->heap[i])) {\n+\t\tif (pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tbreak;\n-\t\t}\n-\n \t\tSWAP(pq->heap[j], pq->heap[i]);\n-\n \t\ti = j;\n \t}\n }\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"496846","messageId":"20240611083157.9876-3-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240611083157.9876-1-chandrapratap3519@gmail.com","subject":"[PATCH v3 2/7] reftable: change the type of array indices to 'size_t' in reftable/pq.c","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-11T08:19:19Z","receivedAt":"2024-06-11T08:32:52Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"Mentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n reftable/pq.c | 12 ++++++------\n 1 file changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/reftable/pq.c b/reftable/pq.c\nindex 1a180c5fa6..2b5b7d1c0e 100644\n--- a/reftable/pq.c\n+++ b/reftable/pq.c\n@@ -22,15 +22,15 @@ int pq_less(struct pq_entry *a, struct pq_entry *b)\n \n struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n {\n-\tint i = 0;\n+\tsize_t i = 0;\n \tstruct pq_entry e = pq->heap[0];\n \tpq->heap[0] = pq->heap[pq->len - 1];\n \tpq->len--;\n \n \twhile (i < pq->len) {\n-\t\tint min = i;\n-\t\tint j = 2 * i + 1;\n-\t\tint k = 2 * i + 2;\n+\t\tsize_t min = i;\n+\t\tsize_t j = 2 * i + 1;\n+\t\tsize_t k = 2 * i + 2;\n \t\tif (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tmin = j;\n \t\tif (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min]))\n@@ -46,14 +46,14 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n \n void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e)\n {\n-\tint i = 0;\n+\tsize_t i = 0;\n \n \tREFTABLE_ALLOC_GROW(pq->heap, pq->len + 1, pq->cap);\n \tpq->heap[pq->len++] = *e;\n \n \ti = pq->len - 1;\n \twhile (i > 0) {\n-\t\tint j = (i - 1) / 2;\n+\t\tsize_t j = (i - 1) / 2;\n \t\tif (pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tbreak;\n \t\tSWAP(pq->heap[j], pq->heap[i]);\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"496847","messageId":"20240611083157.9876-4-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240611083157.9876-1-chandrapratap3519@gmail.com","subject":"[PATCH v3 3/7] t: move reftable/pq_test.c to the unit testing framework","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-11T08:19:20Z","receivedAt":"2024-06-11T08:32:55Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"reftable/pq_test.c exercises a priority queue defined by\nreftable/pq.{c, h}. Migrate reftable/pq_test.c to the unit\ntesting framework. Migration involves refactoring the tests\nto use the unit testing framework instead of reftable's test\nframework.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n Makefile                                      |  2 +-\n t/helper/test-reftable.c                      |  1 -\n .../pq_test.c => t/unit-tests/t-reftable-pq.c | 37 ++++++++-----------\n 3 files changed, 16 insertions(+), 24 deletions(-)\n rename reftable/pq_test.c => t/unit-tests/t-reftable-pq.c (62%)\n\ndiff --git a/Makefile b/Makefile\nindex 59d98ba688..1cabe4cc69 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1336,6 +1336,7 @@ THIRD_PARTY_SOURCES += sha1dc/%\n UNIT_TEST_PROGRAMS += t-ctype\n UNIT_TEST_PROGRAMS += t-mem-pool\n UNIT_TEST_PROGRAMS += t-prio-queue\n+UNIT_TEST_PROGRAMS += t-reftable-pq\n UNIT_TEST_PROGRAMS += t-strbuf\n UNIT_TEST_PROGRAMS += t-strcmp-offset\n UNIT_TEST_PROGRAMS += t-trailer\n@@ -2675,7 +2676,6 @@ REFTABLE_TEST_OBJS += reftable/basics_test.o\n REFTABLE_TEST_OBJS += reftable/block_test.o\n REFTABLE_TEST_OBJS += reftable/dump.o\n REFTABLE_TEST_OBJS += reftable/merged_test.o\n-REFTABLE_TEST_OBJS += reftable/pq_test.o\n REFTABLE_TEST_OBJS += reftable/record_test.o\n REFTABLE_TEST_OBJS += reftable/readwrite_test.o\n REFTABLE_TEST_OBJS += reftable/stack_test.o\ndiff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c\nindex bae731669c..86a2b0f91a 100644\n--- a/t/helper/test-reftable.c\n+++ b/t/helper/test-reftable.c\n@@ -9,7 +9,6 @@ int cmd__reftable(int argc, const char **argv)\n \trecord_test_main(argc, argv);\n \tblock_test_main(argc, argv);\n \ttree_test_main(argc, argv);\n-\tpq_test_main(argc, argv);\n \treadwrite_test_main(argc, argv);\n \tmerged_test_main(argc, argv);\n \tstack_test_main(argc, argv);\ndiff --git a/reftable/pq_test.c b/t/unit-tests/t-reftable-pq.c\nsimilarity index 62%\nrename from reftable/pq_test.c\nrename to t/unit-tests/t-reftable-pq.c\nindex b7d3c80cc7..a47a9473f3 100644\n--- a/reftable/pq_test.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -6,35 +6,28 @@ license that can be found in the LICENSE file or at\n https://developers.google.com/open-source/licenses/bsd\n */\n \n-#include \"system.h\"\n-\n-#include \"basics.h\"\n-#include \"constants.h\"\n-#include \"pq.h\"\n-#include \"record.h\"\n-#include \"reftable-tests.h\"\n-#include \"test_framework.h\"\n+#include \"test-lib.h\"\n+#include \"reftable/constants.h\"\n+#include \"reftable/pq.h\"\n \n void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n {\n-\tint i;\n-\tfor (i = 1; i < pq.len; i++) {\n-\t\tint parent = (i - 1) / 2;\n-\n-\t\tEXPECT(pq_less(&pq.heap[parent], &pq.heap[i]));\n+\tfor (size_t i = 1; i < pq.len; i++) {\n+\t\tsize_t parent = (i - 1) / 2;\n+\t\tcheck(pq_less(&pq.heap[parent], &pq.heap[i]));\n \t}\n }\n \n static void test_pq(void)\n {\n-\tstruct merged_iter_pqueue pq = { NULL };\n+\tstruct merged_iter_pqueue pq = { 0 };\n \tstruct reftable_record recs[54];\n-\tint N = ARRAY_SIZE(recs) - 1, i;\n+\tsize_t N = ARRAY_SIZE(recs) - 1, i;\n \tchar *last = NULL;\n \n \tfor (i = 0; i < N; i++) {\n \t\tstruct strbuf refname = STRBUF_INIT;\n-\t\tstrbuf_addf(&refname, \"%02d\", i);\n+\t\tstrbuf_addf(&refname, \"%02\"PRIuMAX, (uintmax_t)i);\n \n \t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n \t\trecs[i].u.ref.refname = strbuf_detach(&refname, NULL);\n@@ -48,7 +41,6 @@ static void test_pq(void)\n \n \t\tmerged_iter_pqueue_add(&pq, &e);\n \t\tmerged_iter_pqueue_check(pq);\n-\n \t\ti = (i * 7) % N;\n \t} while (i != 1);\n \n@@ -56,9 +48,9 @@ static void test_pq(void)\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n \t\tmerged_iter_pqueue_check(pq);\n \n-\t\tEXPECT(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n+\t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tif (last)\n-\t\t\tEXPECT(strcmp(last, e.rec->u.ref.refname) < 0);\n+\t\t\tcheck_int(strcmp(last, e.rec->u.ref.refname), <, 0);\n \t\tlast = e.rec->u.ref.refname;\n \t}\n \n@@ -67,8 +59,9 @@ static void test_pq(void)\n \tmerged_iter_pqueue_release(&pq);\n }\n \n-int pq_test_main(int argc, const char *argv[])\n+int cmd_main(int argc, const char *argv[])\n {\n-\tRUN_TEST(test_pq);\n-\treturn 0;\n+\tTEST(test_pq(), \"pq works\");\n+\n+\treturn test_done();\n }\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"496848","messageId":"20240611083157.9876-5-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240611083157.9876-1-chandrapratap3519@gmail.com","subject":"[PATCH v3 4/7] t-reftable-pq: make merged_iter_pqueue_check() static","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-11T08:19:21Z","receivedAt":"2024-06-11T08:32:58Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"merged_iter_pqueue_check() is a function previously defined in\nreftable/pq_test.c (now t/unit-tests/t-reftable-pq.c) and used in\nthe testing of a priority queue as defined by reftable/pq.{c, h}.\nAs such, this function is only called by reftable/pq_test.c and it\nmakes little sense to expose it to non-testing code via reftable/pq.h.\n\nHence, make this function static and remove its prototype from\nreftable/pq.h.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n reftable/pq.h                | 1 -\n t/unit-tests/t-reftable-pq.c | 2 +-\n 2 files changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/reftable/pq.h b/reftable/pq.h\nindex f796c23179..707bd26767 100644\n--- a/reftable/pq.h\n+++ b/reftable/pq.h\n@@ -22,7 +22,6 @@ struct merged_iter_pqueue {\n \tsize_t cap;\n };\n \n-void merged_iter_pqueue_check(struct merged_iter_pqueue pq);\n struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq);\n void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e);\n void merged_iter_pqueue_release(struct merged_iter_pqueue *pq);\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex a47a9473f3..7d151f8582 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -10,7 +10,7 @@ license that can be found in the LICENSE file or at\n #include \"reftable/constants.h\"\n #include \"reftable/pq.h\"\n \n-void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n+static void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n {\n \tfor (size_t i = 1; i < pq.len; i++) {\n \t\tsize_t parent = (i - 1) / 2;\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"496849","messageId":"20240611083157.9876-6-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240611083157.9876-1-chandrapratap3519@gmail.com","subject":"[PATCH v3 5/7] t-reftable-pq: make merged_iter_pqueue_check() callable by reference","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-11T08:19:22Z","receivedAt":"2024-06-11T08:33:00Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"merged_iter_pqueue_check() checks the validity of a priority queue\nrepresented by a merged_iter_pqueue struct by asserting the\nparent-child relation in the struct's heap. Explicity passing a\nstruct to this function means a copy of the entire struct is created,\nwhich is inefficient.\n\nMake the function accept a pointer to the struct instead. This is\nsafe to do since the function doesn't modify the struct in any way.\nMake the function parameter 'const' to assert immutability.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n t/unit-tests/t-reftable-pq.c | 10 +++++-----\n 1 file changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex 7d151f8582..774c4194e5 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -10,11 +10,11 @@ license that can be found in the LICENSE file or at\n #include \"reftable/constants.h\"\n #include \"reftable/pq.h\"\n \n-static void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n+static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n {\n-\tfor (size_t i = 1; i < pq.len; i++) {\n+\tfor (size_t i = 1; i < pq->len; i++) {\n \t\tsize_t parent = (i - 1) / 2;\n-\t\tcheck(pq_less(&pq.heap[parent], &pq.heap[i]));\n+\t\tcheck(pq_less(&pq->heap[parent], &pq->heap[i]));\n \t}\n }\n \n@@ -40,13 +40,13 @@ static void test_pq(void)\n \t\t};\n \n \t\tmerged_iter_pqueue_add(&pq, &e);\n-\t\tmerged_iter_pqueue_check(pq);\n+\t\tmerged_iter_pqueue_check(&pq);\n \t\ti = (i * 7) % N;\n \t} while (i != 1);\n \n \twhile (!merged_iter_pqueue_is_empty(pq)) {\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n-\t\tmerged_iter_pqueue_check(pq);\n+\t\tmerged_iter_pqueue_check(&pq);\n \n \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tif (last)\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"496850","messageId":"20240611083157.9876-7-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240611083157.9876-1-chandrapratap3519@gmail.com","subject":"[PATCH v3 6/7] t-reftable-pq: add test for index based comparison","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-11T08:19:23Z","receivedAt":"2024-06-11T08:33:03Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"When comparing two entries, the priority queue as defined by\nreftable/pq.{c, h} first compares the entries on the basis of\ntheir ref-record's keys. If the keys turn out to be equal, the\ncomparison is then made on the basis of their update indices\n(which are never equal).\n\nIn the current testing setup, only the case for comparison on\nthe basis of ref-record's keys is exercised. Add a test for\nindex-based comparison as well. Rename the existing test to\nreflect its nature of only testing record-based comparison.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n t/unit-tests/t-reftable-pq.c | 43 ++++++++++++++++++++++++++++++++++--\n 1 file changed, 41 insertions(+), 2 deletions(-)\n\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex 774c4194e5..e114a8cb0f 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -18,7 +18,7 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n \t}\n }\n \n-static void test_pq(void)\n+static void test_pq_record(void)\n {\n \tstruct merged_iter_pqueue pq = { 0 };\n \tstruct reftable_record recs[54];\n@@ -59,9 +59,48 @@ static void test_pq(void)\n \tmerged_iter_pqueue_release(&pq);\n }\n \n+static void test_pq_index(void)\n+{\n+\tstruct merged_iter_pqueue pq = { 0 };\n+\tstruct reftable_record recs[14];\n+\tchar *last = NULL;\n+\tsize_t N = ARRAY_SIZE(recs), i;\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n+\t\trecs[i].u.ref.refname = xstrdup(\"refs/heads/master\");\n+\t}\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\tstruct pq_entry e = {\n+\t\t\t.rec = &recs[i],\n+\t\t\t.index = i,\n+\t\t};\n+\n+\t\tmerged_iter_pqueue_add(&pq, &e);\n+\t\tmerged_iter_pqueue_check(&pq);\n+\t}\n+\n+\tfor (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) {\n+\t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n+\t\tmerged_iter_pqueue_check(&pq);\n+\n+\t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n+\t\tcheck_int(e.index, ==, i);\n+\t\tif (last)\n+\t\t\tcheck_str(last, e.rec->u.ref.refname);\n+\t\tlast = e.rec->u.ref.refname;\n+\t}\n+\n+\tfor (i = 0; i < N; i++)\n+\t\treftable_record_release(&recs[i]);\n+\tmerged_iter_pqueue_release(&pq);\n+}\n+\n int cmd_main(int argc, const char *argv[])\n {\n-\tTEST(test_pq(), \"pq works\");\n+\tTEST(test_pq_record(), \"pq works with record-based comparison\");\n+\tTEST(test_pq_index(), \"pq works with index-based comparison\");\n \n \treturn test_done();\n }\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"496851","messageId":"20240611083157.9876-8-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240611083157.9876-1-chandrapratap3519@gmail.com","subject":"[PATCH v3 7/7] t-reftable-pq: add tests for merged_iter_pqueue_top()","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-11T08:19:24Z","receivedAt":"2024-06-11T08:33:06Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"merged_iter_pqueue_top() as defined by reftable/pq.{c, h} returns\nthe element at the top of a priority-queue's heap without removing\nit. Since there are no tests for this function in the existing\nsetup, add tests for the same.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n t/unit-tests/t-reftable-pq.c | 49 ++++++++++++++++++++++++++++++++++++\n 1 file changed, 49 insertions(+)\n\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex e114a8cb0f..0e93cc97b1 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -18,6 +18,11 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n \t}\n }\n \n+static int pq_entry_equal(struct pq_entry *a, struct pq_entry *b)\n+{\n+\treturn !reftable_record_cmp(a->rec, b->rec) && (a->index == b->index);\n+}\n+\n static void test_pq_record(void)\n {\n \tstruct merged_iter_pqueue pq = { 0 };\n@@ -45,9 +50,11 @@ static void test_pq_record(void)\n \t} while (i != 1);\n \n \twhile (!merged_iter_pqueue_is_empty(pq)) {\n+\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n \t\tmerged_iter_pqueue_check(&pq);\n \n+\t\tcheck(pq_entry_equal(&top, &e));\n \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tif (last)\n \t\t\tcheck_int(strcmp(last, e.rec->u.ref.refname), <, 0);\n@@ -82,9 +89,11 @@ static void test_pq_index(void)\n \t}\n \n \tfor (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) {\n+\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n \t\tmerged_iter_pqueue_check(&pq);\n \n+\t\tcheck(pq_entry_equal(&top, &e));\n \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tcheck_int(e.index, ==, i);\n \t\tif (last)\n@@ -97,10 +106,50 @@ static void test_pq_index(void)\n \tmerged_iter_pqueue_release(&pq);\n }\n \n+static void test_merged_iter_pqueue_top(void)\n+{\n+\tstruct merged_iter_pqueue pq = { 0 };\n+\tstruct reftable_record recs[14];\n+\tsize_t N = ARRAY_SIZE(recs), i;\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n+\t\trecs[i].u.ref.refname = xstrdup(\"refs/heads/master\");\n+\t}\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\tstruct pq_entry e = {\n+\t\t\t.rec = &recs[i],\n+\t\t\t.index = i,\n+\t\t};\n+\n+\t\tmerged_iter_pqueue_add(&pq, &e);\n+\t\tmerged_iter_pqueue_check(&pq);\n+\t}\n+\n+\tfor (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) {\n+\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n+\t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n+\n+\t\tmerged_iter_pqueue_check(&pq);\n+\t\tcheck(pq_entry_equal(&top, &e));\n+\t\tcheck(reftable_record_equal(top.rec, &recs[i], GIT_SHA1_RAWSZ));\n+\t\tfor (size_t j = 0; i < pq.len; j++) {\n+\t\t\tcheck(pq_less(&top, &pq.heap[j]));\n+\t\t\tcheck_int(top.index, >, j);\n+\t\t}\n+\t}\n+\n+\tfor (i = 0; i < N; i++)\n+\t\treftable_record_release(&recs[i]);\n+\tmerged_iter_pqueue_release(&pq);\n+}\n+\n int cmd_main(int argc, const char *argv[])\n {\n \tTEST(test_pq_record(), \"pq works with record-based comparison\");\n \tTEST(test_pq_index(), \"pq works with index-based comparison\");\n+\tTEST(test_merged_iter_pqueue_top(), \"merged_iter_pqueue_top works\");\n \n \treturn test_done();\n }\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"496856","messageId":"ZmgSluRGk-J_1K1w@tanuki","threadId":"61595","inReplyTo":"20240611083157.9876-3-chandrapratap3519@gmail.com","subject":"Re: [PATCH v3 2/7] reftable: change the type of array indices to 'size_t' in reftable/pq.c","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-06-11T09:02:14Z","receivedAt":"2024-06-11T09:02:21Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Tue, Jun 11, 2024 at 01:49:19PM +0530, Chandra Pratap wrote:\n\nThis commit is missing a commit message. The important information that\nthe reader needs to understand this change is that `pq->len` is of type\n`size_t`, as well. So that information should probably go in here.\n\nOther than that this patch series looks good to me, thanks!\n\nPatrick\n\n> Mentored-by: Patrick Steinhardt <ps@pks.im>\n> Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n> Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n> ---\n>  reftable/pq.c | 12 ++++++------\n>  1 file changed, 6 insertions(+), 6 deletions(-)\n> \n> diff --git a/reftable/pq.c b/reftable/pq.c\n> index 1a180c5fa6..2b5b7d1c0e 100644\n> --- a/reftable/pq.c\n> +++ b/reftable/pq.c\n> @@ -22,15 +22,15 @@ int pq_less(struct pq_entry *a, struct pq_entry *b)\n>  \n>  struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n>  {\n> -\tint i = 0;\n> +\tsize_t i = 0;\n>  \tstruct pq_entry e = pq->heap[0];\n>  \tpq->heap[0] = pq->heap[pq->len - 1];\n>  \tpq->len--;\n>  \n>  \twhile (i < pq->len) {\n> -\t\tint min = i;\n> -\t\tint j = 2 * i + 1;\n> -\t\tint k = 2 * i + 2;\n> +\t\tsize_t min = i;\n> +\t\tsize_t j = 2 * i + 1;\n> +\t\tsize_t k = 2 * i + 2;\n>  \t\tif (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i]))\n>  \t\t\tmin = j;\n>  \t\tif (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min]))\n> @@ -46,14 +46,14 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n>  \n>  void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e)\n>  {\n> -\tint i = 0;\n> +\tsize_t i = 0;\n>  \n>  \tREFTABLE_ALLOC_GROW(pq->heap, pq->len + 1, pq->cap);\n>  \tpq->heap[pq->len++] = *e;\n>  \n>  \ti = pq->len - 1;\n>  \twhile (i > 0) {\n> -\t\tint j = (i - 1) / 2;\n> +\t\tsize_t j = (i - 1) / 2;\n>  \t\tif (pq_less(&pq->heap[j], &pq->heap[i]))\n>  \t\t\tbreak;\n>  \t\tSWAP(pq->heap[j], pq->heap[i]);\n> -- \n> 2.45.2.404.g9eaef5822c\n> \n"},{"id":"497152","messageId":"20240614095136.12052-1-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240611083157.9876-1-chandrapratap3519@gmail.com","subject":"[GSoC][PATCH v4 0/7] t: port reftable/pq_test.c to the unit testing framework","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-14T09:48:00Z","receivedAt":"2024-06-14T09:52:02Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"In the recent codebase update (commit 8bf6fbd, 2023-12-09), a new unit\ntesting framework written entirely in C was introduced to the Git project\naimed at simplifying testing and reducing test run times.\nCurrently, tests for the reftable refs-backend are performed by a custom\ntesting framework defined by reftable/test_framework.{c, h}. Port\nreftable/pq_test.c to the unit testing framework and improve upon\nthe ported test.\n\nThe first two patches in the series are preparatory cleanup, the third patch\nmoves the test to the unit testing framework, and the rest of the patches\nimprove upon the ported test.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n\n---\nChanges in v4:\n- Add a commit message for the second patch\n\nCI/PR for v4: https://github.com/gitgitgadget/git/pull/1745\n\nChandra Pratap(7):\nreftable: remove unncessary curly braces in reftable/pq.c\nreftable: change the type of array indices to 'size_t' in\nt: move reftable/pq_test.c to the unit testing framework\nt-reftable-pq: make merged_iter_pqueue_check() static\nt-reftable-pq: make merged_iter_pqueue_check() callable\nt-reftable-pq: add test for index based comparison\nt-reftable-pq: add tests for merged_iter_pqueue_top()\n\nMakefile                     |   2 +-\nreftable/pq.c                |  29 +++--------\nreftable/pq.h                |   1 -\nreftable/pq_test.c           |  74 ----------------------------\nt/helper/test-reftable.c     |   1 -\nt/unit-tests/t-reftable-pq.c | 155 +++++++++++++++++++++++++++++++++++++++++++++\n6 files changed, 166 insertions(+), 96 deletions(-)\n\nRange-diff against v3:\n1:  3c333e7770 ! 1:  1873fb02ce reftable: change the type of array indices to 'size_t' in reftable/pq.c\n    @@ Metadata\n      ## Commit message ##\n         reftable: change the type of array indices to 'size_t' in reftable/pq.c\n     \n    +    The variables 'i', 'j', 'k' and 'min' are used as indices for\n    +    'pq->heap', which is an array. Additionally, 'pq->len' is of\n    +    type 'size_t' and is often used to assign values to these\n    +    variables. Hence, change the type of these variables from 'int'\n    +    to 'size_t'.\n    +\n         Mentored-by: Patrick Steinhardt <ps@pks.im>\n         Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n         Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n2:  bf547f705a = 2:  3cccf8266a t: move reftable/pq_test.c to the unit testing framework\n3:  7dd3a2b27f = 3:  4b63849694 t-reftable-pq: make merged_iter_pqueue_check() static\n4:  c803e7adfc = 4:  3698a7189f t-reftable-pq: make merged_iter_pqueue_check() callable by reference\n5:  0b03f3567d = 5:  d58c8f709e t-reftable-pq: add test for index based comparison\n6:  0cdfa6221e = 6:  69521f0ff7 t-reftable-pq: add tests for merged_iter_pqueue_top()\n"},{"id":"497153","messageId":"20240614095136.12052-2-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240614095136.12052-1-chandrapratap3519@gmail.com","subject":"[PATCH v4 1/7] reftable: remove unncessary curly braces in reftable/pq.c","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-14T09:48:01Z","receivedAt":"2024-06-14T09:52:05Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"According to Documentation/CodingGuidelines, control-flow statements\nwith a single line as their body must omit curly braces. Make\nreftable/pq.c conform to this guideline. Besides that, remove\nunnecessary newlines and variable assignment.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n reftable/pq.c | 17 ++++-------------\n 1 file changed, 4 insertions(+), 13 deletions(-)\n\ndiff --git a/reftable/pq.c b/reftable/pq.c\nindex 7fb45d8c60..1a180c5fa6 100644\n--- a/reftable/pq.c\n+++ b/reftable/pq.c\n@@ -27,22 +27,16 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n \tpq->heap[0] = pq->heap[pq->len - 1];\n \tpq->len--;\n \n-\ti = 0;\n \twhile (i < pq->len) {\n \t\tint min = i;\n \t\tint j = 2 * i + 1;\n \t\tint k = 2 * i + 2;\n-\t\tif (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i])) {\n+\t\tif (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tmin = j;\n-\t\t}\n-\t\tif (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min])) {\n+\t\tif (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min]))\n \t\t\tmin = k;\n-\t\t}\n-\n-\t\tif (min == i) {\n+\t\tif (min == i)\n \t\t\tbreak;\n-\t\t}\n-\n \t\tSWAP(pq->heap[i], pq->heap[min]);\n \t\ti = min;\n \t}\n@@ -60,12 +54,9 @@ void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry\n \ti = pq->len - 1;\n \twhile (i > 0) {\n \t\tint j = (i - 1) / 2;\n-\t\tif (pq_less(&pq->heap[j], &pq->heap[i])) {\n+\t\tif (pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tbreak;\n-\t\t}\n-\n \t\tSWAP(pq->heap[j], pq->heap[i]);\n-\n \t\ti = j;\n \t}\n }\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"497154","messageId":"20240614095136.12052-3-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240614095136.12052-1-chandrapratap3519@gmail.com","subject":"[PATCH v4 2/7] reftable: change the type of array indices to 'size_t' in reftable/pq.c","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-14T09:48:02Z","receivedAt":"2024-06-14T09:52:07Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"The variables 'i', 'j', 'k' and 'min' are used as indices for\n'pq->heap', which is an array. Additionally, 'pq->len' is of\ntype 'size_t' and is often used to assign values to these\nvariables. Hence, change the type of these variables from 'int'\nto 'size_t'.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n reftable/pq.c | 12 ++++++------\n 1 file changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/reftable/pq.c b/reftable/pq.c\nindex 1a180c5fa6..2b5b7d1c0e 100644\n--- a/reftable/pq.c\n+++ b/reftable/pq.c\n@@ -22,15 +22,15 @@ int pq_less(struct pq_entry *a, struct pq_entry *b)\n \n struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n {\n-\tint i = 0;\n+\tsize_t i = 0;\n \tstruct pq_entry e = pq->heap[0];\n \tpq->heap[0] = pq->heap[pq->len - 1];\n \tpq->len--;\n \n \twhile (i < pq->len) {\n-\t\tint min = i;\n-\t\tint j = 2 * i + 1;\n-\t\tint k = 2 * i + 2;\n+\t\tsize_t min = i;\n+\t\tsize_t j = 2 * i + 1;\n+\t\tsize_t k = 2 * i + 2;\n \t\tif (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tmin = j;\n \t\tif (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min]))\n@@ -46,14 +46,14 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n \n void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e)\n {\n-\tint i = 0;\n+\tsize_t i = 0;\n \n \tREFTABLE_ALLOC_GROW(pq->heap, pq->len + 1, pq->cap);\n \tpq->heap[pq->len++] = *e;\n \n \ti = pq->len - 1;\n \twhile (i > 0) {\n-\t\tint j = (i - 1) / 2;\n+\t\tsize_t j = (i - 1) / 2;\n \t\tif (pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tbreak;\n \t\tSWAP(pq->heap[j], pq->heap[i]);\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"497155","messageId":"20240614095136.12052-4-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240614095136.12052-1-chandrapratap3519@gmail.com","subject":"[PATCH v4 3/7] t: move reftable/pq_test.c to the unit testing framework","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-14T09:48:03Z","receivedAt":"2024-06-14T09:52:11Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"reftable/pq_test.c exercises a priority queue defined by\nreftable/pq.{c, h}. Migrate reftable/pq_test.c to the unit\ntesting framework. Migration involves refactoring the tests\nto use the unit testing framework instead of reftable's test\nframework.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n Makefile                                      |  2 +-\n t/helper/test-reftable.c                      |  1 -\n .../pq_test.c => t/unit-tests/t-reftable-pq.c | 37 ++++++++-----------\n 3 files changed, 16 insertions(+), 24 deletions(-)\n rename reftable/pq_test.c => t/unit-tests/t-reftable-pq.c (62%)\n\ndiff --git a/Makefile b/Makefile\nindex 59d98ba688..1cabe4cc69 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1336,6 +1336,7 @@ THIRD_PARTY_SOURCES += sha1dc/%\n UNIT_TEST_PROGRAMS += t-ctype\n UNIT_TEST_PROGRAMS += t-mem-pool\n UNIT_TEST_PROGRAMS += t-prio-queue\n+UNIT_TEST_PROGRAMS += t-reftable-pq\n UNIT_TEST_PROGRAMS += t-strbuf\n UNIT_TEST_PROGRAMS += t-strcmp-offset\n UNIT_TEST_PROGRAMS += t-trailer\n@@ -2675,7 +2676,6 @@ REFTABLE_TEST_OBJS += reftable/basics_test.o\n REFTABLE_TEST_OBJS += reftable/block_test.o\n REFTABLE_TEST_OBJS += reftable/dump.o\n REFTABLE_TEST_OBJS += reftable/merged_test.o\n-REFTABLE_TEST_OBJS += reftable/pq_test.o\n REFTABLE_TEST_OBJS += reftable/record_test.o\n REFTABLE_TEST_OBJS += reftable/readwrite_test.o\n REFTABLE_TEST_OBJS += reftable/stack_test.o\ndiff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c\nindex bae731669c..86a2b0f91a 100644\n--- a/t/helper/test-reftable.c\n+++ b/t/helper/test-reftable.c\n@@ -9,7 +9,6 @@ int cmd__reftable(int argc, const char **argv)\n \trecord_test_main(argc, argv);\n \tblock_test_main(argc, argv);\n \ttree_test_main(argc, argv);\n-\tpq_test_main(argc, argv);\n \treadwrite_test_main(argc, argv);\n \tmerged_test_main(argc, argv);\n \tstack_test_main(argc, argv);\ndiff --git a/reftable/pq_test.c b/t/unit-tests/t-reftable-pq.c\nsimilarity index 62%\nrename from reftable/pq_test.c\nrename to t/unit-tests/t-reftable-pq.c\nindex b7d3c80cc7..a47a9473f3 100644\n--- a/reftable/pq_test.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -6,35 +6,28 @@ license that can be found in the LICENSE file or at\n https://developers.google.com/open-source/licenses/bsd\n */\n \n-#include \"system.h\"\n-\n-#include \"basics.h\"\n-#include \"constants.h\"\n-#include \"pq.h\"\n-#include \"record.h\"\n-#include \"reftable-tests.h\"\n-#include \"test_framework.h\"\n+#include \"test-lib.h\"\n+#include \"reftable/constants.h\"\n+#include \"reftable/pq.h\"\n \n void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n {\n-\tint i;\n-\tfor (i = 1; i < pq.len; i++) {\n-\t\tint parent = (i - 1) / 2;\n-\n-\t\tEXPECT(pq_less(&pq.heap[parent], &pq.heap[i]));\n+\tfor (size_t i = 1; i < pq.len; i++) {\n+\t\tsize_t parent = (i - 1) / 2;\n+\t\tcheck(pq_less(&pq.heap[parent], &pq.heap[i]));\n \t}\n }\n \n static void test_pq(void)\n {\n-\tstruct merged_iter_pqueue pq = { NULL };\n+\tstruct merged_iter_pqueue pq = { 0 };\n \tstruct reftable_record recs[54];\n-\tint N = ARRAY_SIZE(recs) - 1, i;\n+\tsize_t N = ARRAY_SIZE(recs) - 1, i;\n \tchar *last = NULL;\n \n \tfor (i = 0; i < N; i++) {\n \t\tstruct strbuf refname = STRBUF_INIT;\n-\t\tstrbuf_addf(&refname, \"%02d\", i);\n+\t\tstrbuf_addf(&refname, \"%02\"PRIuMAX, (uintmax_t)i);\n \n \t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n \t\trecs[i].u.ref.refname = strbuf_detach(&refname, NULL);\n@@ -48,7 +41,6 @@ static void test_pq(void)\n \n \t\tmerged_iter_pqueue_add(&pq, &e);\n \t\tmerged_iter_pqueue_check(pq);\n-\n \t\ti = (i * 7) % N;\n \t} while (i != 1);\n \n@@ -56,9 +48,9 @@ static void test_pq(void)\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n \t\tmerged_iter_pqueue_check(pq);\n \n-\t\tEXPECT(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n+\t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tif (last)\n-\t\t\tEXPECT(strcmp(last, e.rec->u.ref.refname) < 0);\n+\t\t\tcheck_int(strcmp(last, e.rec->u.ref.refname), <, 0);\n \t\tlast = e.rec->u.ref.refname;\n \t}\n \n@@ -67,8 +59,9 @@ static void test_pq(void)\n \tmerged_iter_pqueue_release(&pq);\n }\n \n-int pq_test_main(int argc, const char *argv[])\n+int cmd_main(int argc, const char *argv[])\n {\n-\tRUN_TEST(test_pq);\n-\treturn 0;\n+\tTEST(test_pq(), \"pq works\");\n+\n+\treturn test_done();\n }\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"497156","messageId":"20240614095136.12052-5-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240614095136.12052-1-chandrapratap3519@gmail.com","subject":"[PATCH v4 4/7] t-reftable-pq: make merged_iter_pqueue_check() static","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-14T09:48:04Z","receivedAt":"2024-06-14T09:52:13Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"merged_iter_pqueue_check() is a function previously defined in\nreftable/pq_test.c (now t/unit-tests/t-reftable-pq.c) and used in\nthe testing of a priority queue as defined by reftable/pq.{c, h}.\nAs such, this function is only called by reftable/pq_test.c and it\nmakes little sense to expose it to non-testing code via reftable/pq.h.\n\nHence, make this function static and remove its prototype from\nreftable/pq.h.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n reftable/pq.h                | 1 -\n t/unit-tests/t-reftable-pq.c | 2 +-\n 2 files changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/reftable/pq.h b/reftable/pq.h\nindex f796c23179..707bd26767 100644\n--- a/reftable/pq.h\n+++ b/reftable/pq.h\n@@ -22,7 +22,6 @@ struct merged_iter_pqueue {\n \tsize_t cap;\n };\n \n-void merged_iter_pqueue_check(struct merged_iter_pqueue pq);\n struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq);\n void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e);\n void merged_iter_pqueue_release(struct merged_iter_pqueue *pq);\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex a47a9473f3..7d151f8582 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -10,7 +10,7 @@ license that can be found in the LICENSE file or at\n #include \"reftable/constants.h\"\n #include \"reftable/pq.h\"\n \n-void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n+static void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n {\n \tfor (size_t i = 1; i < pq.len; i++) {\n \t\tsize_t parent = (i - 1) / 2;\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"497157","messageId":"20240614095136.12052-6-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240614095136.12052-1-chandrapratap3519@gmail.com","subject":"[PATCH v4 5/7] t-reftable-pq: make merged_iter_pqueue_check() callable by reference","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-14T09:48:05Z","receivedAt":"2024-06-14T09:52:17Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"merged_iter_pqueue_check() checks the validity of a priority queue\nrepresented by a merged_iter_pqueue struct by asserting the\nparent-child relation in the struct's heap. Explicity passing a\nstruct to this function means a copy of the entire struct is created,\nwhich is inefficient.\n\nMake the function accept a pointer to the struct instead. This is\nsafe to do since the function doesn't modify the struct in any way.\nMake the function parameter 'const' to assert immutability.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n t/unit-tests/t-reftable-pq.c | 10 +++++-----\n 1 file changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex 7d151f8582..774c4194e5 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -10,11 +10,11 @@ license that can be found in the LICENSE file or at\n #include \"reftable/constants.h\"\n #include \"reftable/pq.h\"\n \n-static void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n+static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n {\n-\tfor (size_t i = 1; i < pq.len; i++) {\n+\tfor (size_t i = 1; i < pq->len; i++) {\n \t\tsize_t parent = (i - 1) / 2;\n-\t\tcheck(pq_less(&pq.heap[parent], &pq.heap[i]));\n+\t\tcheck(pq_less(&pq->heap[parent], &pq->heap[i]));\n \t}\n }\n \n@@ -40,13 +40,13 @@ static void test_pq(void)\n \t\t};\n \n \t\tmerged_iter_pqueue_add(&pq, &e);\n-\t\tmerged_iter_pqueue_check(pq);\n+\t\tmerged_iter_pqueue_check(&pq);\n \t\ti = (i * 7) % N;\n \t} while (i != 1);\n \n \twhile (!merged_iter_pqueue_is_empty(pq)) {\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n-\t\tmerged_iter_pqueue_check(pq);\n+\t\tmerged_iter_pqueue_check(&pq);\n \n \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tif (last)\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"497158","messageId":"20240614095136.12052-7-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240614095136.12052-1-chandrapratap3519@gmail.com","subject":"[PATCH v4 6/7] t-reftable-pq: add test for index based comparison","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-14T09:48:06Z","receivedAt":"2024-06-14T09:52:20Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"When comparing two entries, the priority queue as defined by\nreftable/pq.{c, h} first compares the entries on the basis of\ntheir ref-record's keys. If the keys turn out to be equal, the\ncomparison is then made on the basis of their update indices\n(which are never equal).\n\nIn the current testing setup, only the case for comparison on\nthe basis of ref-record's keys is exercised. Add a test for\nindex-based comparison as well. Rename the existing test to\nreflect its nature of only testing record-based comparison.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n t/unit-tests/t-reftable-pq.c | 43 ++++++++++++++++++++++++++++++++++--\n 1 file changed, 41 insertions(+), 2 deletions(-)\n\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex 774c4194e5..e114a8cb0f 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -18,7 +18,7 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n \t}\n }\n \n-static void test_pq(void)\n+static void test_pq_record(void)\n {\n \tstruct merged_iter_pqueue pq = { 0 };\n \tstruct reftable_record recs[54];\n@@ -59,9 +59,48 @@ static void test_pq(void)\n \tmerged_iter_pqueue_release(&pq);\n }\n \n+static void test_pq_index(void)\n+{\n+\tstruct merged_iter_pqueue pq = { 0 };\n+\tstruct reftable_record recs[14];\n+\tchar *last = NULL;\n+\tsize_t N = ARRAY_SIZE(recs), i;\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n+\t\trecs[i].u.ref.refname = xstrdup(\"refs/heads/master\");\n+\t}\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\tstruct pq_entry e = {\n+\t\t\t.rec = &recs[i],\n+\t\t\t.index = i,\n+\t\t};\n+\n+\t\tmerged_iter_pqueue_add(&pq, &e);\n+\t\tmerged_iter_pqueue_check(&pq);\n+\t}\n+\n+\tfor (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) {\n+\t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n+\t\tmerged_iter_pqueue_check(&pq);\n+\n+\t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n+\t\tcheck_int(e.index, ==, i);\n+\t\tif (last)\n+\t\t\tcheck_str(last, e.rec->u.ref.refname);\n+\t\tlast = e.rec->u.ref.refname;\n+\t}\n+\n+\tfor (i = 0; i < N; i++)\n+\t\treftable_record_release(&recs[i]);\n+\tmerged_iter_pqueue_release(&pq);\n+}\n+\n int cmd_main(int argc, const char *argv[])\n {\n-\tTEST(test_pq(), \"pq works\");\n+\tTEST(test_pq_record(), \"pq works with record-based comparison\");\n+\tTEST(test_pq_index(), \"pq works with index-based comparison\");\n \n \treturn test_done();\n }\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"497159","messageId":"20240614095136.12052-8-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240614095136.12052-1-chandrapratap3519@gmail.com","subject":"[PATCH v4 7/7] t-reftable-pq: add tests for merged_iter_pqueue_top()","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-06-14T09:48:07Z","receivedAt":"2024-06-14T09:52:23Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"merged_iter_pqueue_top() as defined by reftable/pq.{c, h} returns\nthe element at the top of a priority-queue's heap without removing\nit. Since there are no tests for this function in the existing\nsetup, add tests for the same.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n t/unit-tests/t-reftable-pq.c | 49 ++++++++++++++++++++++++++++++++++++\n 1 file changed, 49 insertions(+)\n\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex e114a8cb0f..0e93cc97b1 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -18,6 +18,11 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n \t}\n }\n \n+static int pq_entry_equal(struct pq_entry *a, struct pq_entry *b)\n+{\n+\treturn !reftable_record_cmp(a->rec, b->rec) && (a->index == b->index);\n+}\n+\n static void test_pq_record(void)\n {\n \tstruct merged_iter_pqueue pq = { 0 };\n@@ -45,9 +50,11 @@ static void test_pq_record(void)\n \t} while (i != 1);\n \n \twhile (!merged_iter_pqueue_is_empty(pq)) {\n+\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n \t\tmerged_iter_pqueue_check(&pq);\n \n+\t\tcheck(pq_entry_equal(&top, &e));\n \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tif (last)\n \t\t\tcheck_int(strcmp(last, e.rec->u.ref.refname), <, 0);\n@@ -82,9 +89,11 @@ static void test_pq_index(void)\n \t}\n \n \tfor (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) {\n+\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n \t\tmerged_iter_pqueue_check(&pq);\n \n+\t\tcheck(pq_entry_equal(&top, &e));\n \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tcheck_int(e.index, ==, i);\n \t\tif (last)\n@@ -97,10 +106,50 @@ static void test_pq_index(void)\n \tmerged_iter_pqueue_release(&pq);\n }\n \n+static void test_merged_iter_pqueue_top(void)\n+{\n+\tstruct merged_iter_pqueue pq = { 0 };\n+\tstruct reftable_record recs[14];\n+\tsize_t N = ARRAY_SIZE(recs), i;\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n+\t\trecs[i].u.ref.refname = xstrdup(\"refs/heads/master\");\n+\t}\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\tstruct pq_entry e = {\n+\t\t\t.rec = &recs[i],\n+\t\t\t.index = i,\n+\t\t};\n+\n+\t\tmerged_iter_pqueue_add(&pq, &e);\n+\t\tmerged_iter_pqueue_check(&pq);\n+\t}\n+\n+\tfor (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) {\n+\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n+\t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n+\n+\t\tmerged_iter_pqueue_check(&pq);\n+\t\tcheck(pq_entry_equal(&top, &e));\n+\t\tcheck(reftable_record_equal(top.rec, &recs[i], GIT_SHA1_RAWSZ));\n+\t\tfor (size_t j = 0; i < pq.len; j++) {\n+\t\t\tcheck(pq_less(&top, &pq.heap[j]));\n+\t\t\tcheck_int(top.index, >, j);\n+\t\t}\n+\t}\n+\n+\tfor (i = 0; i < N; i++)\n+\t\treftable_record_release(&recs[i]);\n+\tmerged_iter_pqueue_release(&pq);\n+}\n+\n int cmd_main(int argc, const char *argv[])\n {\n \tTEST(test_pq_record(), \"pq works with record-based comparison\");\n \tTEST(test_pq_index(), \"pq works with index-based comparison\");\n+\tTEST(test_merged_iter_pqueue_top(), \"merged_iter_pqueue_top works\");\n \n \treturn test_done();\n }\n-- \n2.45.2.404.g9eaef5822c\n\n"},{"id":"497181","messageId":"xmqqo783fmo9.fsf@gitster.g","threadId":"61595","inReplyTo":"20240614095136.12052-1-chandrapratap3519@gmail.com","subject":"Re: [GSoC][PATCH v4 0/7] t: port reftable/pq_test.c to the unit testing framework","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-06-14T17:40:06Z","receivedAt":"2024-06-14T17:40:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Chandra Pratap <chandrapratap3519@gmail.com> writes:\n\n> In the recent codebase update (commit 8bf6fbd, 2023-12-09), a new unit\n> testing framework written entirely in C was introduced to the Git project\n> aimed at simplifying testing and reducing test run times.\n> Currently, tests for the reftable refs-backend are performed by a custom\n> testing framework defined by reftable/test_framework.{c, h}. Port\n> reftable/pq_test.c to the unit testing framework and improve upon\n> the ported test.\n>\n> The first two patches in the series are preparatory cleanup, the third patch\n> moves the test to the unit testing framework, and the rest of the patches\n> improve upon the ported test.\n>\n> Mentored-by: Patrick Steinhardt <ps@pks.im>\n> Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n> Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n>\n> ---\n> Changes in v4:\n> - Add a commit message for the second patch\n>\n> CI/PR for v4: https://github.com/gitgitgadget/git/pull/1745\n\nHmph.\n\nA larger question is how pristine we want to keep the \"imported\nsource\" that is reftable/* stuff.\n\nObviously we are getting rid of some parts of it (like pq_test.c\nhere) so our \"fork\" will no longer be usable, without pulling some\nof the stuff our project offers from outside that directory, by\noutside people.  This concern is shared with other topics we saw\nrecently to move the unit tests bundled with the reftable library to\nt/unit-tests/.\n\nBut this series brings in another twist that makes it a larger\nquestion.  If we are willing to butcher our copy of reftable library\nto a shape that cannot be reused by outside folks, do we still want\nto use reftable/pq.c instead of getting rid of it and use the other\nprio queue implementation we use elsewhere in our system?  If that\nwill be the longer term direction we want to go, then porting the\nunit tests for reftable/pq.c may end up being a wasted effort.\n\nSo, I dunno.\n\n> Chandra Pratap(7):\n> reftable: remove unncessary curly braces in reftable/pq.c\n> reftable: change the type of array indices to 'size_t' in\n> t: move reftable/pq_test.c to the unit testing framework\n> t-reftable-pq: make merged_iter_pqueue_check() static\n> t-reftable-pq: make merged_iter_pqueue_check() callable\n> t-reftable-pq: add test for index based comparison\n> t-reftable-pq: add tests for merged_iter_pqueue_top()\n>\n> Makefile                     |   2 +-\n> reftable/pq.c                |  29 +++--------\n> reftable/pq.h                |   1 -\n> reftable/pq_test.c           |  74 ----------------------------\n> t/helper/test-reftable.c     |   1 -\n> t/unit-tests/t-reftable-pq.c | 155 +++++++++++++++++++++++++++++++++++++++++++++\n> 6 files changed, 166 insertions(+), 96 deletions(-)\n>\n> Range-diff against v3:\n> 1:  3c333e7770 ! 1:  1873fb02ce reftable: change the type of array indices to 'size_t' in reftable/pq.c\n>     @@ Metadata\n>       ## Commit message ##\n>          reftable: change the type of array indices to 'size_t' in reftable/pq.c\n>      \n>     +    The variables 'i', 'j', 'k' and 'min' are used as indices for\n>     +    'pq->heap', which is an array. Additionally, 'pq->len' is of\n>     +    type 'size_t' and is often used to assign values to these\n>     +    variables. Hence, change the type of these variables from 'int'\n>     +    to 'size_t'.\n>     +\n>          Mentored-by: Patrick Steinhardt <ps@pks.im>\n>          Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n>          Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n> 2:  bf547f705a = 2:  3cccf8266a t: move reftable/pq_test.c to the unit testing framework\n> 3:  7dd3a2b27f = 3:  4b63849694 t-reftable-pq: make merged_iter_pqueue_check() static\n> 4:  c803e7adfc = 4:  3698a7189f t-reftable-pq: make merged_iter_pqueue_check() callable by reference\n> 5:  0b03f3567d = 5:  d58c8f709e t-reftable-pq: add test for index based comparison\n> 6:  0cdfa6221e = 6:  69521f0ff7 t-reftable-pq: add tests for merged_iter_pqueue_top()\n"},{"id":"499163","messageId":"20240723143032.4261-1-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240614095136.12052-1-chandrapratap3519@gmail.com","subject":"[GSoC][PATCH v5 0/7] t: port reftable/pq_test.c to the unit testing framework","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-07-23T14:17:10Z","receivedAt":"2024-07-23T14:33:08Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"The reftable library comes with self tests, which are exercised\nas part of the usual end-to-end tests and are designed to\nobserve the end-user visible effects of Git commands. What it\nexercises, however, is a better match for the unit-testing\nframework, merged at 8bf6fbd0 (Merge branch 'js/doc-unit-tests',\n2023-12-09), which is designed to observe how low level\nimplementation details, at the level of sequences of individual\nfunction calls, behave.\n\nHence, port reftable/pq_test.c to the unit testing framework and\nimprove upon the ported test. The first two patches in the series\nare preparatory cleanup, the third patch moves the test to the unit\ntesting framework, and the rest of the patches improve upon the\nported test.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n\n---\nChanges in v5:\n- Rebase the branch on top of the  latest master branch\n- Rename tests according to unit-tests' conventions\n- remove 'pq_test_main()' from reftable/reftable-test.h\n\nCI/PR for v5: https://github.com/gitgitgadget/git/pull/1745\n\nChandra Pratap(7):\nreftable: remove unncessary curly braces in reftable/pq.c\nreftable: change the type of array indices to 'size_t' in reftable/pq.c\nt: move reftable/pq_test.c to the unit testing framework\nt-reftable-pq: make merged_iter_pqueue_check() static\nt-reftable-pq: make merged_iter_pqueue_check() callable by reference\nt-reftable-pq: add test for index based comparison\nt-reftable-pq: add tests for merged_iter_pqueue_top()\n\nMakefile                     |   2 +-\nreftable/pq.c                |  29 +++-----\nreftable/pq.h                |   1 -\nreftable/pq_test.c           |  74 ---------------------\nreftable/reftable-tests.h    |   1 -\nt/helper/test-reftable.c     |   1 -\nt/unit-tests/t-reftable-pq.c | 155 +++++++++++++++++++++++++++++++++++++++++++\n7 files changed, 166 insertions(+), 97 deletions(-)\n\nRange-diff against v4:\n<rebase commits>\n  1:  d3c5605ea2 = 382:  acd9d26aaf reftable: remove unncessary curly braces in reftable/pq.c\n  2:  3c333e7770 = 383:  2e0986207b reftable: change the type of array indices to 'size_t' in reftable/pq.c\n  3:  bf547f705a ! 384:  df06b6d604 t: move reftable/pq_test.c to the unit testing framework\n    @@ Commit message\n         t: move reftable/pq_test.c to the unit testing framework\n\n         reftable/pq_test.c exercises a priority queue defined by\n    -    reftable/pq.{c, h}. Migrate reftable/pq_test.c to the unit\n    -    testing framework. Migration involves refactoring the tests\n    -    to use the unit testing framework instead of reftable's test\n    -    framework.\n    +    reftable/pq.{c, h}. Migrate reftable/pq_test.c to the unit testing\n    +    framework. Migration involves refactoring the tests to use the unit\n    +    testing framework instead of reftable's test framework, and\n    +    renaming the tests to align with unit-tests' standards.\n\n         Mentored-by: Patrick Steinhardt <ps@pks.im>\n         Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n         Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n\n      ## Makefile ##\n    -@@ Makefile: THIRD_PARTY_SOURCES += sha1dc/%\n    - UNIT_TEST_PROGRAMS += t-ctype\n    - UNIT_TEST_PROGRAMS += t-mem-pool\n    +@@ Makefile: UNIT_TEST_PROGRAMS += t-oidmap\n    + UNIT_TEST_PROGRAMS += t-oidtree\n      UNIT_TEST_PROGRAMS += t-prio-queue\n    + UNIT_TEST_PROGRAMS += t-reftable-basics\n     +UNIT_TEST_PROGRAMS += t-reftable-pq\n    + UNIT_TEST_PROGRAMS += t-reftable-record\n      UNIT_TEST_PROGRAMS += t-strbuf\n      UNIT_TEST_PROGRAMS += t-strcmp-offset\n    - UNIT_TEST_PROGRAMS += t-trailer\n    -@@ Makefile: REFTABLE_TEST_OBJS += reftable/basics_test.o\n    +@@ Makefile: REFTABLE_OBJS += reftable/writer.o\n      REFTABLE_TEST_OBJS += reftable/block_test.o\n      REFTABLE_TEST_OBJS += reftable/dump.o\n      REFTABLE_TEST_OBJS += reftable/merged_test.o\n     -REFTABLE_TEST_OBJS += reftable/pq_test.o\n    - REFTABLE_TEST_OBJS += reftable/record_test.o\n      REFTABLE_TEST_OBJS += reftable/readwrite_test.o\n      REFTABLE_TEST_OBJS += reftable/stack_test.o\n    + REFTABLE_TEST_OBJS += reftable/test_framework.o\n    +\n    + ## reftable/reftable-tests.h ##\n    +@@ reftable/reftable-tests.h: license that can be found in the LICENSE file or at\n    + int basics_test_main(int argc, const char **argv);\n    + int block_test_main(int argc, const char **argv);\n    + int merged_test_main(int argc, const char **argv);\n    +-int pq_test_main(int argc, const char **argv);\n    + int record_test_main(int argc, const char **argv);\n    + int readwrite_test_main(int argc, const char **argv);\n    + int stack_test_main(int argc, const char **argv);\n\n      ## t/helper/test-reftable.c ##\n     @@ t/helper/test-reftable.c: int cmd__reftable(int argc, const char **argv)\n    - \trecord_test_main(argc, argv);\n    + \t/* test from simple to complex. */\n      \tblock_test_main(argc, argv);\n      \ttree_test_main(argc, argv);\n     -\tpq_test_main(argc, argv);\n    @@ t/unit-tests/t-reftable-pq.c: license that can be found in the LICENSE file or a\n      \t}\n      }\n\n    - static void test_pq(void)\n    +-static void test_pq(void)\n    ++static void t_pq(void)\n      {\n     -\tstruct merged_iter_pqueue pq = { NULL };\n     +\tstruct merged_iter_pqueue pq = { 0 };\n    @@ t/unit-tests/t-reftable-pq.c: static void test_pq(void)\n      {\n     -\tRUN_TEST(test_pq);\n     -\treturn 0;\n    -+\tTEST(test_pq(), \"pq works\");\n    ++\tTEST(t_pq(), \"pq works\");\n     +\n     +\treturn test_done();\n      }\n  4:  7dd3a2b27f = 385:  40745ab18e t-reftable-pq: make merged_iter_pqueue_check() static\n  5:  c803e7adfc ! 386:  ee8432ac4a t-reftable-pq: make merged_iter_pqueue_check() callable by reference\n    @@ t/unit-tests/t-reftable-pq.c: license that can be found in the LICENSE file or a\n      \t}\n      }\n\n    -@@ t/unit-tests/t-reftable-pq.c: static void test_pq(void)\n    +@@ t/unit-tests/t-reftable-pq.c: static void t_pq(void)\n      \t\t};\n\n      \t\tmerged_iter_pqueue_add(&pq, &e);\n  6:  0b03f3567d ! 387:  94a77f5a60 t-reftable-pq: add test for index based comparison\n    @@ t/unit-tests/t-reftable-pq.c: static void merged_iter_pqueue_check(const struct\n      \t}\n      }\n\n    --static void test_pq(void)\n    -+static void test_pq_record(void)\n    +-static void t_pq(void)\n    ++static void t_pq_record(void)\n      {\n      \tstruct merged_iter_pqueue pq = { 0 };\n      \tstruct reftable_record recs[54];\n    -@@ t/unit-tests/t-reftable-pq.c: static void test_pq(void)\n    +@@ t/unit-tests/t-reftable-pq.c: static void t_pq(void)\n      \tmerged_iter_pqueue_release(&pq);\n      }\n\n    -+static void test_pq_index(void)\n    ++static void t_pq_index(void)\n     +{\n     +\tstruct merged_iter_pqueue pq = { 0 };\n     +\tstruct reftable_record recs[14];\n    @@ t/unit-tests/t-reftable-pq.c: static void test_pq(void)\n     +\n      int cmd_main(int argc, const char *argv[])\n      {\n    --\tTEST(test_pq(), \"pq works\");\n    -+\tTEST(test_pq_record(), \"pq works with record-based comparison\");\n    -+\tTEST(test_pq_index(), \"pq works with index-based comparison\");\n    +-\tTEST(t_pq(), \"pq works\");\n    ++\tTEST(t_pq_record(), \"pq works with record-based comparison\");\n    ++\tTEST(t_pq_index(), \"pq works with index-based comparison\");\n\n      \treturn test_done();\n      }\n  7:  0cdfa6221e ! 388:  9a76f87bd1 t-reftable-pq: add tests for merged_iter_pqueue_top()\n    @@ t/unit-tests/t-reftable-pq.c: static void merged_iter_pqueue_check(const struct\n     +\treturn !reftable_record_cmp(a->rec, b->rec) && (a->index == b->index);\n     +}\n     +\n    - static void test_pq_record(void)\n    + static void t_pq_record(void)\n      {\n      \tstruct merged_iter_pqueue pq = { 0 };\n    -@@ t/unit-tests/t-reftable-pq.c: static void test_pq_record(void)\n    +@@ t/unit-tests/t-reftable-pq.c: static void t_pq_record(void)\n      \t} while (i != 1);\n\n      \twhile (!merged_iter_pqueue_is_empty(pq)) {\n    @@ t/unit-tests/t-reftable-pq.c: static void test_pq_record(void)\n      \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n      \t\tif (last)\n      \t\t\tcheck_int(strcmp(last, e.rec->u.ref.refname), <, 0);\n    -@@ t/unit-tests/t-reftable-pq.c: static void test_pq_index(void)\n    +@@ t/unit-tests/t-reftable-pq.c: static void t_pq_index(void)\n      \t}\n\n      \tfor (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) {\n    @@ t/unit-tests/t-reftable-pq.c: static void test_pq_index(void)\n      \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n      \t\tcheck_int(e.index, ==, i);\n      \t\tif (last)\n    -@@ t/unit-tests/t-reftable-pq.c: static void test_pq_index(void)\n    +@@ t/unit-tests/t-reftable-pq.c: static void t_pq_index(void)\n      \tmerged_iter_pqueue_release(&pq);\n      }\n\n    -+static void test_merged_iter_pqueue_top(void)\n    ++static void t_merged_iter_pqueue_top(void)\n     +{\n     +\tstruct merged_iter_pqueue pq = { 0 };\n     +\tstruct reftable_record recs[14];\n    @@ t/unit-tests/t-reftable-pq.c: static void test_pq_index(void)\n     +\n      int cmd_main(int argc, const char *argv[])\n      {\n    - \tTEST(test_pq_record(), \"pq works with record-based comparison\");\n    - \tTEST(test_pq_index(), \"pq works with index-based comparison\");\n    -+\tTEST(test_merged_iter_pqueue_top(), \"merged_iter_pqueue_top works\");\n    + \tTEST(t_pq_record(), \"pq works with record-based comparison\");\n    + \tTEST(t_pq_index(), \"pq works with index-based comparison\");\n    ++\tTEST(t_merged_iter_pqueue_top(), \"merged_iter_pqueue_top works\");\n\n      \treturn test_done();\n      }\n\n"},{"id":"499164","messageId":"20240723143032.4261-2-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240723143032.4261-1-chandrapratap3519@gmail.com","subject":"[PATCH v5 1/7] reftable: remove unncessary curly braces in reftable/pq.c","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-07-23T14:17:11Z","receivedAt":"2024-07-23T14:33:11Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"According to Documentation/CodingGuidelines, control-flow statements\nwith a single line as their body must omit curly braces. Make\nreftable/pq.c conform to this guideline. Besides that, remove\nunnecessary newlines and variable assignment.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n reftable/pq.c | 17 ++++-------------\n 1 file changed, 4 insertions(+), 13 deletions(-)\n\ndiff --git a/reftable/pq.c b/reftable/pq.c\nindex 7fb45d8c60..1a180c5fa6 100644\n--- a/reftable/pq.c\n+++ b/reftable/pq.c\n@@ -27,22 +27,16 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n \tpq->heap[0] = pq->heap[pq->len - 1];\n \tpq->len--;\n \n-\ti = 0;\n \twhile (i < pq->len) {\n \t\tint min = i;\n \t\tint j = 2 * i + 1;\n \t\tint k = 2 * i + 2;\n-\t\tif (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i])) {\n+\t\tif (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tmin = j;\n-\t\t}\n-\t\tif (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min])) {\n+\t\tif (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min]))\n \t\t\tmin = k;\n-\t\t}\n-\n-\t\tif (min == i) {\n+\t\tif (min == i)\n \t\t\tbreak;\n-\t\t}\n-\n \t\tSWAP(pq->heap[i], pq->heap[min]);\n \t\ti = min;\n \t}\n@@ -60,12 +54,9 @@ void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry\n \ti = pq->len - 1;\n \twhile (i > 0) {\n \t\tint j = (i - 1) / 2;\n-\t\tif (pq_less(&pq->heap[j], &pq->heap[i])) {\n+\t\tif (pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tbreak;\n-\t\t}\n-\n \t\tSWAP(pq->heap[j], pq->heap[i]);\n-\n \t\ti = j;\n \t}\n }\n-- \n2.45.GIT\n\n"},{"id":"499165","messageId":"20240723143032.4261-3-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240723143032.4261-1-chandrapratap3519@gmail.com","subject":"[PATCH v5 2/7] reftable: change the type of array indices to 'size_t' in reftable/pq.c","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-07-23T14:17:12Z","receivedAt":"2024-07-23T14:33:14Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"The variables 'i', 'j', 'k' and 'min' are used as indices for\n'pq->heap', which is an array. Additionally, 'pq->len' is of\ntype 'size_t' and is often used to assign values to these\nvariables. Hence, change the type of these variables from 'int'\nto 'size_t'.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n reftable/pq.c | 12 ++++++------\n 1 file changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/reftable/pq.c b/reftable/pq.c\nindex 1a180c5fa6..2b5b7d1c0e 100644\n--- a/reftable/pq.c\n+++ b/reftable/pq.c\n@@ -22,15 +22,15 @@ int pq_less(struct pq_entry *a, struct pq_entry *b)\n \n struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n {\n-\tint i = 0;\n+\tsize_t i = 0;\n \tstruct pq_entry e = pq->heap[0];\n \tpq->heap[0] = pq->heap[pq->len - 1];\n \tpq->len--;\n \n \twhile (i < pq->len) {\n-\t\tint min = i;\n-\t\tint j = 2 * i + 1;\n-\t\tint k = 2 * i + 2;\n+\t\tsize_t min = i;\n+\t\tsize_t j = 2 * i + 1;\n+\t\tsize_t k = 2 * i + 2;\n \t\tif (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tmin = j;\n \t\tif (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min]))\n@@ -46,14 +46,14 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n \n void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e)\n {\n-\tint i = 0;\n+\tsize_t i = 0;\n \n \tREFTABLE_ALLOC_GROW(pq->heap, pq->len + 1, pq->cap);\n \tpq->heap[pq->len++] = *e;\n \n \ti = pq->len - 1;\n \twhile (i > 0) {\n-\t\tint j = (i - 1) / 2;\n+\t\tsize_t j = (i - 1) / 2;\n \t\tif (pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tbreak;\n \t\tSWAP(pq->heap[j], pq->heap[i]);\n-- \n2.45.GIT\n\n"},{"id":"499166","messageId":"20240723143032.4261-4-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240723143032.4261-1-chandrapratap3519@gmail.com","subject":"[PATCH v5 3/7] t: move reftable/pq_test.c to the unit testing framework","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-07-23T14:17:13Z","receivedAt":"2024-07-23T14:33:17Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"reftable/pq_test.c exercises a priority queue defined by\nreftable/pq.{c, h}. Migrate reftable/pq_test.c to the unit testing\nframework. Migration involves refactoring the tests to use the unit\ntesting framework instead of reftable's test framework, and\nrenaming the tests to align with unit-tests' standards.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n Makefile                                      |  2 +-\n reftable/reftable-tests.h                     |  1 -\n t/helper/test-reftable.c                      |  1 -\n .../pq_test.c => t/unit-tests/t-reftable-pq.c | 39 ++++++++-----------\n 4 files changed, 17 insertions(+), 26 deletions(-)\n rename reftable/pq_test.c => t/unit-tests/t-reftable-pq.c (61%)\n\ndiff --git a/Makefile b/Makefile\nindex d6479092a0..1ee83e98dc 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1340,6 +1340,7 @@ UNIT_TEST_PROGRAMS += t-oidmap\n UNIT_TEST_PROGRAMS += t-oidtree\n UNIT_TEST_PROGRAMS += t-prio-queue\n UNIT_TEST_PROGRAMS += t-reftable-basics\n+UNIT_TEST_PROGRAMS += t-reftable-pq\n UNIT_TEST_PROGRAMS += t-reftable-record\n UNIT_TEST_PROGRAMS += t-strbuf\n UNIT_TEST_PROGRAMS += t-strcmp-offset\n@@ -2681,7 +2682,6 @@ REFTABLE_OBJS += reftable/writer.o\n REFTABLE_TEST_OBJS += reftable/block_test.o\n REFTABLE_TEST_OBJS += reftable/dump.o\n REFTABLE_TEST_OBJS += reftable/merged_test.o\n-REFTABLE_TEST_OBJS += reftable/pq_test.o\n REFTABLE_TEST_OBJS += reftable/readwrite_test.o\n REFTABLE_TEST_OBJS += reftable/stack_test.o\n REFTABLE_TEST_OBJS += reftable/test_framework.o\ndiff --git a/reftable/reftable-tests.h b/reftable/reftable-tests.h\nindex 114cc3d053..67283faf06 100644\n--- a/reftable/reftable-tests.h\n+++ b/reftable/reftable-tests.h\n@@ -12,7 +12,6 @@ license that can be found in the LICENSE file or at\n int basics_test_main(int argc, const char **argv);\n int block_test_main(int argc, const char **argv);\n int merged_test_main(int argc, const char **argv);\n-int pq_test_main(int argc, const char **argv);\n int record_test_main(int argc, const char **argv);\n int readwrite_test_main(int argc, const char **argv);\n int stack_test_main(int argc, const char **argv);\ndiff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c\nindex aa6538a8da..b808ad3e12 100644\n--- a/t/helper/test-reftable.c\n+++ b/t/helper/test-reftable.c\n@@ -7,7 +7,6 @@ int cmd__reftable(int argc, const char **argv)\n \t/* test from simple to complex. */\n \tblock_test_main(argc, argv);\n \ttree_test_main(argc, argv);\n-\tpq_test_main(argc, argv);\n \treadwrite_test_main(argc, argv);\n \tmerged_test_main(argc, argv);\n \tstack_test_main(argc, argv);\ndiff --git a/reftable/pq_test.c b/t/unit-tests/t-reftable-pq.c\nsimilarity index 61%\nrename from reftable/pq_test.c\nrename to t/unit-tests/t-reftable-pq.c\nindex b7d3c80cc7..a78aba9e71 100644\n--- a/reftable/pq_test.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -6,35 +6,28 @@ license that can be found in the LICENSE file or at\n https://developers.google.com/open-source/licenses/bsd\n */\n \n-#include \"system.h\"\n-\n-#include \"basics.h\"\n-#include \"constants.h\"\n-#include \"pq.h\"\n-#include \"record.h\"\n-#include \"reftable-tests.h\"\n-#include \"test_framework.h\"\n+#include \"test-lib.h\"\n+#include \"reftable/constants.h\"\n+#include \"reftable/pq.h\"\n \n void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n {\n-\tint i;\n-\tfor (i = 1; i < pq.len; i++) {\n-\t\tint parent = (i - 1) / 2;\n-\n-\t\tEXPECT(pq_less(&pq.heap[parent], &pq.heap[i]));\n+\tfor (size_t i = 1; i < pq.len; i++) {\n+\t\tsize_t parent = (i - 1) / 2;\n+\t\tcheck(pq_less(&pq.heap[parent], &pq.heap[i]));\n \t}\n }\n \n-static void test_pq(void)\n+static void t_pq(void)\n {\n-\tstruct merged_iter_pqueue pq = { NULL };\n+\tstruct merged_iter_pqueue pq = { 0 };\n \tstruct reftable_record recs[54];\n-\tint N = ARRAY_SIZE(recs) - 1, i;\n+\tsize_t N = ARRAY_SIZE(recs) - 1, i;\n \tchar *last = NULL;\n \n \tfor (i = 0; i < N; i++) {\n \t\tstruct strbuf refname = STRBUF_INIT;\n-\t\tstrbuf_addf(&refname, \"%02d\", i);\n+\t\tstrbuf_addf(&refname, \"%02\"PRIuMAX, (uintmax_t)i);\n \n \t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n \t\trecs[i].u.ref.refname = strbuf_detach(&refname, NULL);\n@@ -48,7 +41,6 @@ static void test_pq(void)\n \n \t\tmerged_iter_pqueue_add(&pq, &e);\n \t\tmerged_iter_pqueue_check(pq);\n-\n \t\ti = (i * 7) % N;\n \t} while (i != 1);\n \n@@ -56,9 +48,9 @@ static void test_pq(void)\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n \t\tmerged_iter_pqueue_check(pq);\n \n-\t\tEXPECT(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n+\t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tif (last)\n-\t\t\tEXPECT(strcmp(last, e.rec->u.ref.refname) < 0);\n+\t\t\tcheck_int(strcmp(last, e.rec->u.ref.refname), <, 0);\n \t\tlast = e.rec->u.ref.refname;\n \t}\n \n@@ -67,8 +59,9 @@ static void test_pq(void)\n \tmerged_iter_pqueue_release(&pq);\n }\n \n-int pq_test_main(int argc, const char *argv[])\n+int cmd_main(int argc, const char *argv[])\n {\n-\tRUN_TEST(test_pq);\n-\treturn 0;\n+\tTEST(t_pq(), \"pq works\");\n+\n+\treturn test_done();\n }\n-- \n2.45.GIT\n\n"},{"id":"499167","messageId":"20240723143032.4261-5-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240723143032.4261-1-chandrapratap3519@gmail.com","subject":"[PATCH v5 4/7] t-reftable-pq: make merged_iter_pqueue_check() static","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-07-23T14:17:14Z","receivedAt":"2024-07-23T14:33:20Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"merged_iter_pqueue_check() is a function previously defined in\nreftable/pq_test.c (now t/unit-tests/t-reftable-pq.c) and used in\nthe testing of a priority queue as defined by reftable/pq.{c, h}.\nAs such, this function is only called by reftable/pq_test.c and it\nmakes little sense to expose it to non-testing code via reftable/pq.h.\n\nHence, make this function static and remove its prototype from\nreftable/pq.h.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n reftable/pq.h                | 1 -\n t/unit-tests/t-reftable-pq.c | 2 +-\n 2 files changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/reftable/pq.h b/reftable/pq.h\nindex f796c23179..707bd26767 100644\n--- a/reftable/pq.h\n+++ b/reftable/pq.h\n@@ -22,7 +22,6 @@ struct merged_iter_pqueue {\n \tsize_t cap;\n };\n \n-void merged_iter_pqueue_check(struct merged_iter_pqueue pq);\n struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq);\n void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e);\n void merged_iter_pqueue_release(struct merged_iter_pqueue *pq);\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex a78aba9e71..220e82be19 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -10,7 +10,7 @@ license that can be found in the LICENSE file or at\n #include \"reftable/constants.h\"\n #include \"reftable/pq.h\"\n \n-void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n+static void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n {\n \tfor (size_t i = 1; i < pq.len; i++) {\n \t\tsize_t parent = (i - 1) / 2;\n-- \n2.45.GIT\n\n"},{"id":"499168","messageId":"20240723143032.4261-6-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240723143032.4261-1-chandrapratap3519@gmail.com","subject":"[PATCH v5 5/7] t-reftable-pq: make merged_iter_pqueue_check() callable by reference","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-07-23T14:17:15Z","receivedAt":"2024-07-23T14:33:23Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"merged_iter_pqueue_check() checks the validity of a priority queue\nrepresented by a merged_iter_pqueue struct by asserting the\nparent-child relation in the struct's heap. Explicity passing a\nstruct to this function means a copy of the entire struct is created,\nwhich is inefficient.\n\nMake the function accept a pointer to the struct instead. This is\nsafe to do since the function doesn't modify the struct in any way.\nMake the function parameter 'const' to assert immutability.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n t/unit-tests/t-reftable-pq.c | 10 +++++-----\n 1 file changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex 220e82be19..9230dd9b9e 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -10,11 +10,11 @@ license that can be found in the LICENSE file or at\n #include \"reftable/constants.h\"\n #include \"reftable/pq.h\"\n \n-static void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n+static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n {\n-\tfor (size_t i = 1; i < pq.len; i++) {\n+\tfor (size_t i = 1; i < pq->len; i++) {\n \t\tsize_t parent = (i - 1) / 2;\n-\t\tcheck(pq_less(&pq.heap[parent], &pq.heap[i]));\n+\t\tcheck(pq_less(&pq->heap[parent], &pq->heap[i]));\n \t}\n }\n \n@@ -40,13 +40,13 @@ static void t_pq(void)\n \t\t};\n \n \t\tmerged_iter_pqueue_add(&pq, &e);\n-\t\tmerged_iter_pqueue_check(pq);\n+\t\tmerged_iter_pqueue_check(&pq);\n \t\ti = (i * 7) % N;\n \t} while (i != 1);\n \n \twhile (!merged_iter_pqueue_is_empty(pq)) {\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n-\t\tmerged_iter_pqueue_check(pq);\n+\t\tmerged_iter_pqueue_check(&pq);\n \n \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tif (last)\n-- \n2.45.GIT\n\n"},{"id":"499169","messageId":"20240723143032.4261-7-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240723143032.4261-1-chandrapratap3519@gmail.com","subject":"[PATCH v5 6/7] t-reftable-pq: add test for index based comparison","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-07-23T14:17:16Z","receivedAt":"2024-07-23T14:33:26Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"When comparing two entries, the priority queue as defined by\nreftable/pq.{c, h} first compares the entries on the basis of\ntheir ref-record's keys. If the keys turn out to be equal, the\ncomparison is then made on the basis of their update indices\n(which are never equal).\n\nIn the current testing setup, only the case for comparison on\nthe basis of ref-record's keys is exercised. Add a test for\nindex-based comparison as well. Rename the existing test to\nreflect its nature of only testing record-based comparison.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n t/unit-tests/t-reftable-pq.c | 43 ++++++++++++++++++++++++++++++++++--\n 1 file changed, 41 insertions(+), 2 deletions(-)\n\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex 9230dd9b9e..23c3f6888b 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -18,7 +18,7 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n \t}\n }\n \n-static void t_pq(void)\n+static void t_pq_record(void)\n {\n \tstruct merged_iter_pqueue pq = { 0 };\n \tstruct reftable_record recs[54];\n@@ -59,9 +59,48 @@ static void t_pq(void)\n \tmerged_iter_pqueue_release(&pq);\n }\n \n+static void t_pq_index(void)\n+{\n+\tstruct merged_iter_pqueue pq = { 0 };\n+\tstruct reftable_record recs[14];\n+\tchar *last = NULL;\n+\tsize_t N = ARRAY_SIZE(recs), i;\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n+\t\trecs[i].u.ref.refname = xstrdup(\"refs/heads/master\");\n+\t}\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\tstruct pq_entry e = {\n+\t\t\t.rec = &recs[i],\n+\t\t\t.index = i,\n+\t\t};\n+\n+\t\tmerged_iter_pqueue_add(&pq, &e);\n+\t\tmerged_iter_pqueue_check(&pq);\n+\t}\n+\n+\tfor (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) {\n+\t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n+\t\tmerged_iter_pqueue_check(&pq);\n+\n+\t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n+\t\tcheck_int(e.index, ==, i);\n+\t\tif (last)\n+\t\t\tcheck_str(last, e.rec->u.ref.refname);\n+\t\tlast = e.rec->u.ref.refname;\n+\t}\n+\n+\tfor (i = 0; i < N; i++)\n+\t\treftable_record_release(&recs[i]);\n+\tmerged_iter_pqueue_release(&pq);\n+}\n+\n int cmd_main(int argc, const char *argv[])\n {\n-\tTEST(t_pq(), \"pq works\");\n+\tTEST(t_pq_record(), \"pq works with record-based comparison\");\n+\tTEST(t_pq_index(), \"pq works with index-based comparison\");\n \n \treturn test_done();\n }\n-- \n2.45.GIT\n\n"},{"id":"499170","messageId":"20240723143032.4261-8-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240723143032.4261-1-chandrapratap3519@gmail.com","subject":"[PATCH v5 7/7] t-reftable-pq: add tests for merged_iter_pqueue_top()","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-07-23T14:17:17Z","receivedAt":"2024-07-23T14:33:29Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"merged_iter_pqueue_top() as defined by reftable/pq.{c, h} returns\nthe element at the top of a priority-queue's heap without removing\nit. Since there are no tests for this function in the existing\nsetup, add tests for the same.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n t/unit-tests/t-reftable-pq.c | 49 ++++++++++++++++++++++++++++++++++++\n 1 file changed, 49 insertions(+)\n\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex 23c3f6888b..84b0a3b708 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -18,6 +18,11 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n \t}\n }\n \n+static int pq_entry_equal(struct pq_entry *a, struct pq_entry *b)\n+{\n+\treturn !reftable_record_cmp(a->rec, b->rec) && (a->index == b->index);\n+}\n+\n static void t_pq_record(void)\n {\n \tstruct merged_iter_pqueue pq = { 0 };\n@@ -45,9 +50,11 @@ static void t_pq_record(void)\n \t} while (i != 1);\n \n \twhile (!merged_iter_pqueue_is_empty(pq)) {\n+\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n \t\tmerged_iter_pqueue_check(&pq);\n \n+\t\tcheck(pq_entry_equal(&top, &e));\n \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tif (last)\n \t\t\tcheck_int(strcmp(last, e.rec->u.ref.refname), <, 0);\n@@ -82,9 +89,11 @@ static void t_pq_index(void)\n \t}\n \n \tfor (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) {\n+\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n \t\tmerged_iter_pqueue_check(&pq);\n \n+\t\tcheck(pq_entry_equal(&top, &e));\n \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tcheck_int(e.index, ==, i);\n \t\tif (last)\n@@ -97,10 +106,50 @@ static void t_pq_index(void)\n \tmerged_iter_pqueue_release(&pq);\n }\n \n+static void t_merged_iter_pqueue_top(void)\n+{\n+\tstruct merged_iter_pqueue pq = { 0 };\n+\tstruct reftable_record recs[14];\n+\tsize_t N = ARRAY_SIZE(recs), i;\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n+\t\trecs[i].u.ref.refname = xstrdup(\"refs/heads/master\");\n+\t}\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\tstruct pq_entry e = {\n+\t\t\t.rec = &recs[i],\n+\t\t\t.index = i,\n+\t\t};\n+\n+\t\tmerged_iter_pqueue_add(&pq, &e);\n+\t\tmerged_iter_pqueue_check(&pq);\n+\t}\n+\n+\tfor (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) {\n+\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n+\t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n+\n+\t\tmerged_iter_pqueue_check(&pq);\n+\t\tcheck(pq_entry_equal(&top, &e));\n+\t\tcheck(reftable_record_equal(top.rec, &recs[i], GIT_SHA1_RAWSZ));\n+\t\tfor (size_t j = 0; i < pq.len; j++) {\n+\t\t\tcheck(pq_less(&top, &pq.heap[j]));\n+\t\t\tcheck_int(top.index, >, j);\n+\t\t}\n+\t}\n+\n+\tfor (i = 0; i < N; i++)\n+\t\treftable_record_release(&recs[i]);\n+\tmerged_iter_pqueue_release(&pq);\n+}\n+\n int cmd_main(int argc, const char *argv[])\n {\n \tTEST(t_pq_record(), \"pq works with record-based comparison\");\n \tTEST(t_pq_index(), \"pq works with index-based comparison\");\n+\tTEST(t_merged_iter_pqueue_top(), \"merged_iter_pqueue_top works\");\n \n \treturn test_done();\n }\n-- \n2.45.GIT\n\n"},{"id":"499180","messageId":"xmqq5xsw2fyd.fsf@gitster.g","threadId":"61595","inReplyTo":"20240723143032.4261-1-chandrapratap3519@gmail.com","subject":"Re: [GSoC][PATCH v5 0/7] t: port reftable/pq_test.c to the unit testing framework","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-07-23T17:09:14Z","receivedAt":"2024-07-23T17:09:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Chandra Pratap <chandrapratap3519@gmail.com> writes:\n\n> The reftable library comes with self tests, which are exercised\n> as part of the usual end-to-end tests and are designed to\n> observe the end-user visible effects of Git commands. What it\n> exercises, however, is a better match for the unit-testing\n> framework, merged at 8bf6fbd0 (Merge branch 'js/doc-unit-tests',\n> 2023-12-09), which is designed to observe how low level\n> implementation details, at the level of sequences of individual\n> function calls, behave.\n>\n> Hence, port reftable/pq_test.c to the unit testing framework and\n> improve upon the ported test. The first two patches in the series\n> are preparatory cleanup, the third patch moves the test to the unit\n> testing framework, and the rest of the patches improve upon the\n> ported test.\n>\n> Mentored-by: Patrick Steinhardt <ps@pks.im>\n> Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n> Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n>\n> ---\n> Changes in v5:\n> - Rebase the branch on top of the  latest master branch\n\nIf you need to perform this rebase, please say _why_ you are\nrebasing.\n\n\"A new rc was tagged so I rebased\" is *not* a good reason.\n\n\"I wanted to use that new feature that was merged to 'master'\nrecently, which was not available when I wrote the previous\niteration of this series, hence I rebased\" is a very good reason.\n\n\"Since I wrote the previous iteration, other unit test topics have\ngraduated, so there are trivial conflicts in Makefile when merging\nthis topic\" is usually not a good reason, especially when the same\nconflicts with these other unit test topics are already resolved\nwhen your previous iteration is merged to 'seen'.\n\nIf there isn't a reason worth mentioning why you are rebasing, then\nplease do not rebase.  It is distracting.\n\n> - Rename tests according to unit-tests' conventions\n> - remove 'pq_test_main()' from reftable/reftable-test.h\n>\n> CI/PR for v5: https://github.com/gitgitgadget/git/pull/1745\n\nBy the way, I still haven't got any answer to a question I asked\nlong ago on this series, wrt possibly unifying this pq and another\npq we already use elsewhere in our codebase.  If we are butchering\nwhat we borrowed from elsewhere and store in reftable/. directory\nand taking responsibility of maintaining it ourselves, we probably\nshould consider larger refactoring and cleaning up, and part of it\nwe may end up discarding this pq implementation, making the unit\ntesting on it a wasted effort.\n\nThanks.\n\n> Chandra Pratap(7):\n> reftable: remove unncessary curly braces in reftable/pq.c\n> reftable: change the type of array indices to 'size_t' in reftable/pq.c\n> t: move reftable/pq_test.c to the unit testing framework\n> t-reftable-pq: make merged_iter_pqueue_check() static\n> t-reftable-pq: make merged_iter_pqueue_check() callable by reference\n> t-reftable-pq: add test for index based comparison\n> t-reftable-pq: add tests for merged_iter_pqueue_top()\n>\n> Makefile                     |   2 +-\n> reftable/pq.c                |  29 +++-----\n> reftable/pq.h                |   1 -\n> reftable/pq_test.c           |  74 ---------------------\n> reftable/reftable-tests.h    |   1 -\n> t/helper/test-reftable.c     |   1 -\n> t/unit-tests/t-reftable-pq.c | 155 +++++++++++++++++++++++++++++++++++++++++++\n> 7 files changed, 166 insertions(+), 97 deletions(-)\n>\n> Range-diff against v4:\n> <rebase commits>\n>   1:  d3c5605ea2 = 382:  acd9d26aaf reftable: remove unncessary curly braces in reftable/pq.c\n>   2:  3c333e7770 = 383:  2e0986207b reftable: change the type of array indices to 'size_t' in reftable/pq.c\n>   3:  bf547f705a ! 384:  df06b6d604 t: move reftable/pq_test.c to the unit testing framework\n>     @@ Commit message\n>          t: move reftable/pq_test.c to the unit testing framework\n>\n>          reftable/pq_test.c exercises a priority queue defined by\n>     -    reftable/pq.{c, h}. Migrate reftable/pq_test.c to the unit\n>     -    testing framework. Migration involves refactoring the tests\n>     -    to use the unit testing framework instead of reftable's test\n>     -    framework.\n>     +    reftable/pq.{c, h}. Migrate reftable/pq_test.c to the unit testing\n>     +    framework. Migration involves refactoring the tests to use the unit\n>     +    testing framework instead of reftable's test framework, and\n>     +    renaming the tests to align with unit-tests' standards.\n>\n>          Mentored-by: Patrick Steinhardt <ps@pks.im>\n>          Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n>          Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n>\n>       ## Makefile ##\n>     -@@ Makefile: THIRD_PARTY_SOURCES += sha1dc/%\n>     - UNIT_TEST_PROGRAMS += t-ctype\n>     - UNIT_TEST_PROGRAMS += t-mem-pool\n>     +@@ Makefile: UNIT_TEST_PROGRAMS += t-oidmap\n>     + UNIT_TEST_PROGRAMS += t-oidtree\n>       UNIT_TEST_PROGRAMS += t-prio-queue\n>     + UNIT_TEST_PROGRAMS += t-reftable-basics\n>      +UNIT_TEST_PROGRAMS += t-reftable-pq\n>     + UNIT_TEST_PROGRAMS += t-reftable-record\n>       UNIT_TEST_PROGRAMS += t-strbuf\n>       UNIT_TEST_PROGRAMS += t-strcmp-offset\n>     - UNIT_TEST_PROGRAMS += t-trailer\n>     -@@ Makefile: REFTABLE_TEST_OBJS += reftable/basics_test.o\n>     +@@ Makefile: REFTABLE_OBJS += reftable/writer.o\n>       REFTABLE_TEST_OBJS += reftable/block_test.o\n>       REFTABLE_TEST_OBJS += reftable/dump.o\n>       REFTABLE_TEST_OBJS += reftable/merged_test.o\n>      -REFTABLE_TEST_OBJS += reftable/pq_test.o\n>     - REFTABLE_TEST_OBJS += reftable/record_test.o\n>       REFTABLE_TEST_OBJS += reftable/readwrite_test.o\n>       REFTABLE_TEST_OBJS += reftable/stack_test.o\n>     + REFTABLE_TEST_OBJS += reftable/test_framework.o\n>     +\n>     + ## reftable/reftable-tests.h ##\n>     +@@ reftable/reftable-tests.h: license that can be found in the LICENSE file or at\n>     + int basics_test_main(int argc, const char **argv);\n>     + int block_test_main(int argc, const char **argv);\n>     + int merged_test_main(int argc, const char **argv);\n>     +-int pq_test_main(int argc, const char **argv);\n>     + int record_test_main(int argc, const char **argv);\n>     + int readwrite_test_main(int argc, const char **argv);\n>     + int stack_test_main(int argc, const char **argv);\n>\n>       ## t/helper/test-reftable.c ##\n>      @@ t/helper/test-reftable.c: int cmd__reftable(int argc, const char **argv)\n>     - \trecord_test_main(argc, argv);\n>     + \t/* test from simple to complex. */\n>       \tblock_test_main(argc, argv);\n>       \ttree_test_main(argc, argv);\n>      -\tpq_test_main(argc, argv);\n>     @@ t/unit-tests/t-reftable-pq.c: license that can be found in the LICENSE file or a\n>       \t}\n>       }\n>\n>     - static void test_pq(void)\n>     +-static void test_pq(void)\n>     ++static void t_pq(void)\n>       {\n>      -\tstruct merged_iter_pqueue pq = { NULL };\n>      +\tstruct merged_iter_pqueue pq = { 0 };\n>     @@ t/unit-tests/t-reftable-pq.c: static void test_pq(void)\n>       {\n>      -\tRUN_TEST(test_pq);\n>      -\treturn 0;\n>     -+\tTEST(test_pq(), \"pq works\");\n>     ++\tTEST(t_pq(), \"pq works\");\n>      +\n>      +\treturn test_done();\n>       }\n>   4:  7dd3a2b27f = 385:  40745ab18e t-reftable-pq: make merged_iter_pqueue_check() static\n>   5:  c803e7adfc ! 386:  ee8432ac4a t-reftable-pq: make merged_iter_pqueue_check() callable by reference\n>     @@ t/unit-tests/t-reftable-pq.c: license that can be found in the LICENSE file or a\n>       \t}\n>       }\n>\n>     -@@ t/unit-tests/t-reftable-pq.c: static void test_pq(void)\n>     +@@ t/unit-tests/t-reftable-pq.c: static void t_pq(void)\n>       \t\t};\n>\n>       \t\tmerged_iter_pqueue_add(&pq, &e);\n>   6:  0b03f3567d ! 387:  94a77f5a60 t-reftable-pq: add test for index based comparison\n>     @@ t/unit-tests/t-reftable-pq.c: static void merged_iter_pqueue_check(const struct\n>       \t}\n>       }\n>\n>     --static void test_pq(void)\n>     -+static void test_pq_record(void)\n>     +-static void t_pq(void)\n>     ++static void t_pq_record(void)\n>       {\n>       \tstruct merged_iter_pqueue pq = { 0 };\n>       \tstruct reftable_record recs[54];\n>     -@@ t/unit-tests/t-reftable-pq.c: static void test_pq(void)\n>     +@@ t/unit-tests/t-reftable-pq.c: static void t_pq(void)\n>       \tmerged_iter_pqueue_release(&pq);\n>       }\n>\n>     -+static void test_pq_index(void)\n>     ++static void t_pq_index(void)\n>      +{\n>      +\tstruct merged_iter_pqueue pq = { 0 };\n>      +\tstruct reftable_record recs[14];\n>     @@ t/unit-tests/t-reftable-pq.c: static void test_pq(void)\n>      +\n>       int cmd_main(int argc, const char *argv[])\n>       {\n>     --\tTEST(test_pq(), \"pq works\");\n>     -+\tTEST(test_pq_record(), \"pq works with record-based comparison\");\n>     -+\tTEST(test_pq_index(), \"pq works with index-based comparison\");\n>     +-\tTEST(t_pq(), \"pq works\");\n>     ++\tTEST(t_pq_record(), \"pq works with record-based comparison\");\n>     ++\tTEST(t_pq_index(), \"pq works with index-based comparison\");\n>\n>       \treturn test_done();\n>       }\n>   7:  0cdfa6221e ! 388:  9a76f87bd1 t-reftable-pq: add tests for merged_iter_pqueue_top()\n>     @@ t/unit-tests/t-reftable-pq.c: static void merged_iter_pqueue_check(const struct\n>      +\treturn !reftable_record_cmp(a->rec, b->rec) && (a->index == b->index);\n>      +}\n>      +\n>     - static void test_pq_record(void)\n>     + static void t_pq_record(void)\n>       {\n>       \tstruct merged_iter_pqueue pq = { 0 };\n>     -@@ t/unit-tests/t-reftable-pq.c: static void test_pq_record(void)\n>     +@@ t/unit-tests/t-reftable-pq.c: static void t_pq_record(void)\n>       \t} while (i != 1);\n>\n>       \twhile (!merged_iter_pqueue_is_empty(pq)) {\n>     @@ t/unit-tests/t-reftable-pq.c: static void test_pq_record(void)\n>       \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n>       \t\tif (last)\n>       \t\t\tcheck_int(strcmp(last, e.rec->u.ref.refname), <, 0);\n>     -@@ t/unit-tests/t-reftable-pq.c: static void test_pq_index(void)\n>     +@@ t/unit-tests/t-reftable-pq.c: static void t_pq_index(void)\n>       \t}\n>\n>       \tfor (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) {\n>     @@ t/unit-tests/t-reftable-pq.c: static void test_pq_index(void)\n>       \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n>       \t\tcheck_int(e.index, ==, i);\n>       \t\tif (last)\n>     -@@ t/unit-tests/t-reftable-pq.c: static void test_pq_index(void)\n>     +@@ t/unit-tests/t-reftable-pq.c: static void t_pq_index(void)\n>       \tmerged_iter_pqueue_release(&pq);\n>       }\n>\n>     -+static void test_merged_iter_pqueue_top(void)\n>     ++static void t_merged_iter_pqueue_top(void)\n>      +{\n>      +\tstruct merged_iter_pqueue pq = { 0 };\n>      +\tstruct reftable_record recs[14];\n>     @@ t/unit-tests/t-reftable-pq.c: static void test_pq_index(void)\n>      +\n>       int cmd_main(int argc, const char *argv[])\n>       {\n>     - \tTEST(test_pq_record(), \"pq works with record-based comparison\");\n>     - \tTEST(test_pq_index(), \"pq works with index-based comparison\");\n>     -+\tTEST(test_merged_iter_pqueue_top(), \"merged_iter_pqueue_top works\");\n>     + \tTEST(t_pq_record(), \"pq works with record-based comparison\");\n>     + \tTEST(t_pq_index(), \"pq works with index-based comparison\");\n>     ++\tTEST(t_merged_iter_pqueue_top(), \"merged_iter_pqueue_top works\");\n>\n>       \treturn test_done();\n>       }\n"},{"id":"499218","messageId":"CA+J6zkRKzQGvwhiQdgRqcctDP76y5_v582rRTzEXJyx7=+WRqw@mail.gmail.com","threadId":"61595","inReplyTo":"xmqq5xsw2fyd.fsf@gitster.g","subject":"Re: [GSoC][PATCH v5 0/7] t: port reftable/pq_test.c to the unit testing framework","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-07-24T05:12:13Z","receivedAt":"2024-07-24T05:12:25Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"On Tue, 23 Jul 2024 at 22:39, Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Chandra Pratap <chandrapratap3519@gmail.com> writes:\n>\n> > The reftable library comes with self tests, which are exercised\n> > as part of the usual end-to-end tests and are designed to\n> > observe the end-user visible effects of Git commands. What it\n> > exercises, however, is a better match for the unit-testing\n> > framework, merged at 8bf6fbd0 (Merge branch 'js/doc-unit-tests',\n> > 2023-12-09), which is designed to observe how low level\n> > implementation details, at the level of sequences of individual\n> > function calls, behave.\n> >\n> > Hence, port reftable/pq_test.c to the unit testing framework and\n> > improve upon the ported test. The first two patches in the series\n> > are preparatory cleanup, the third patch moves the test to the unit\n> > testing framework, and the rest of the patches improve upon the\n> > ported test.\n> >\n> > Mentored-by: Patrick Steinhardt <ps@pks.im>\n> > Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n> > Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n> >\n> > ---\n> > Changes in v5:\n> > - Rebase the branch on top of the  latest master branch\n>\n> If you need to perform this rebase, please say _why_ you are\n> rebasing.\n>\n> \"A new rc was tagged so I rebased\" is *not* a good reason.\n>\n> \"I wanted to use that new feature that was merged to 'master'\n> recently, which was not available when I wrote the previous\n> iteration of this series, hence I rebased\" is a very good reason.\n>\n> \"Since I wrote the previous iteration, other unit test topics have\n> graduated, so there are trivial conflicts in Makefile when merging\n> this topic\" is usually not a good reason, especially when the same\n> conflicts with these other unit test topics are already resolved\n> when your previous iteration is merged to 'seen'.\n>\n> If there isn't a reason worth mentioning why you are rebasing, then\n> please do not rebase.  It is distracting.\n\nOh, okay.\n\n> > - Rename tests according to unit-tests' conventions\n> > - remove 'pq_test_main()' from reftable/reftable-test.h\n> >\n> > CI/PR for v5: https://github.com/gitgitgadget/git/pull/1745\n>\n> By the way, I still haven't got any answer to a question I asked\n> long ago on this series, wrt possibly unifying this pq and another\n> pq we already use elsewhere in our codebase.  If we are butchering\n> what we borrowed from elsewhere and store in reftable/. directory\n> and taking responsibility of maintaining it ourselves, we probably\n> should consider larger refactoring and cleaning up, and part of it\n> we may end up discarding this pq implementation, making the unit\n> testing on it a wasted effort.\n>\n> Thanks.\n>\n\nI did talk about this with Patrick and Christian on a private slack channel\na few weeks ago and here is how that conversation went:\n\nMe: Hey, I wanted to talk about the message from Junio the other day.\nIt is true that through this project, we are modifying the reftable directory\nto a point that it is no longer easily usable by someone from outside. If\nthat is the direction we want to take, wouldn't it make more sense to get\nrid of reftable/pq.{c, h} altogether and use Git's prio-queue instead?\n\nChristian: Yeah, I think the direction the Git project wants to take is to\nintegrate the reftable code more and more with the Git code. On the other\nhand, there are libification projects which are trying to split parts of the\nGit code into libraries usable by other projects. But I don't think each of\nthese libraries should have their own test framework, their own prio-queue\nimplementation, their own string implementation, etc. So, even if I am not\nsure about the end result, I think it would be ok to modify the reftable code\nso that it uses the Git's prio queue and maybe other Git data structures.\nBut I'd like Patrick to confirm, and the list to agree to this. So I'd\nrather wait\nuntil Patrick is back from his vacation before doing things like replacing\nreftable/pq.{c, h} with Git's prio-queue.\n\nPatrick: Just chiming in real quick: while the reftable library is\ncurrently in a\nposition where it cannot be used standalone by other projects, I'd very much\nlike to move into the direction of making it completely standalone again so\nthat we can adapt e.g. libgit2 to use it. So I rather want to move the other\ndirection over time and re-establish a proper boundary between reftable\nlibrary and the remainder of Git. I don't really think that this needs to impact\nthe reftable tests though. Git is the upstream of the reftable\nlibrary, and I don't\nsee much of a point why every other project should carry the same tests, too.\n\n---snip---\n"},{"id":"499226","messageId":"CAP8UFD12Cqorr7oPS+JfOTYY6LaNUgPEJaEscf-jwLUOur+xqA@mail.gmail.com","threadId":"61595","inReplyTo":"CA+J6zkRKzQGvwhiQdgRqcctDP76y5_v582rRTzEXJyx7=+WRqw@mail.gmail.com","subject":"Re: [GSoC][PATCH v5 0/7] t: port reftable/pq_test.c to the unit testing framework","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2024-07-24T07:17:55Z","receivedAt":"2024-07-24T07:18:14Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Wed, Jul 24, 2024 at 7:12 AM Chandra Pratap\n<chandrapratap3519@gmail.com> wrote:\n>\n> On Tue, 23 Jul 2024 at 22:39, Junio C Hamano <gitster@pobox.com> wrote:\n\n> > > - Rename tests according to unit-tests' conventions\n> > > - remove 'pq_test_main()' from reftable/reftable-test.h\n> > >\n> > > CI/PR for v5: https://github.com/gitgitgadget/git/pull/1745\n> >\n> > By the way, I still haven't got any answer to a question I asked\n> > long ago on this series, wrt possibly unifying this pq and another\n> > pq we already use elsewhere in our codebase.  If we are butchering\n> > what we borrowed from elsewhere and store in reftable/. directory\n> > and taking responsibility of maintaining it ourselves, we probably\n> > should consider larger refactoring and cleaning up, and part of it\n> > we may end up discarding this pq implementation, making the unit\n> > testing on it a wasted effort.\n\nI agree it might have been better to start by replacing the pq\nimplementation in reftable/ with our own first, as there would be no\nneed for this patch series, but Chandra's GSoC is about replacing the\nunit test framework in reftable/ with our own which is still valuable.\nAnd I think that at this point it is just simpler to not get\ndistracted by replacing the pq implementation now. It's also not like\nchanging the unit test framework would make replacing the pq\nimplementation harder.\n\n> I did talk about this with Patrick and Christian on a private slack channel\n> a few weeks ago and here is how that conversation went:\n>\n> Me: Hey, I wanted to talk about the message from Junio the other day.\n> It is true that through this project, we are modifying the reftable directory\n> to a point that it is no longer easily usable by someone from outside. If\n> that is the direction we want to take, wouldn't it make more sense to get\n> rid of reftable/pq.{c, h} altogether and use Git's prio-queue instead?\n>\n> Christian: Yeah, I think the direction the Git project wants to take is to\n> integrate the reftable code more and more with the Git code. On the other\n> hand, there are libification projects which are trying to split parts of the\n> Git code into libraries usable by other projects. But I don't think each of\n> these libraries should have their own test framework, their own prio-queue\n> implementation, their own string implementation, etc. So, even if I am not\n> sure about the end result, I think it would be ok to modify the reftable code\n> so that it uses the Git's prio queue and maybe other Git data structures.\n> But I'd like Patrick to confirm, and the list to agree to this. So I'd\n> rather wait\n> until Patrick is back from his vacation before doing things like replacing\n> reftable/pq.{c, h} with Git's prio-queue.\n\nYeah, if it had been discussed and agreed on earlier, I think\nreplacing the pq implementation would have made sense. Now I think\nit's a bit late at this stage in Chandra's GSoC to go in this\ndirection though. I think it's better if he can focus on finishing to\nreplace the unit test framework.\n"},{"id":"499228","messageId":"CA+J6zkT7px4WPE7F=GnBv9X_piTBOPedbrTekYA1SFriZbbfLQ@mail.gmail.com","threadId":"61595","inReplyTo":"CAP8UFD12Cqorr7oPS+JfOTYY6LaNUgPEJaEscf-jwLUOur+xqA@mail.gmail.com","subject":"Re: [GSoC][PATCH v5 0/7] t: port reftable/pq_test.c to the unit testing framework","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-07-24T07:51:32Z","receivedAt":"2024-07-24T07:51:44Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"On Wed, 24 Jul 2024 at 12:48, Christian Couder\n<christian.couder@gmail.com> wrote:\n>\n> On Wed, Jul 24, 2024 at 7:12 AM Chandra Pratap\n> <chandrapratap3519@gmail.com> wrote:\n> >\n> > On Tue, 23 Jul 2024 at 22:39, Junio C Hamano <gitster@pobox.com> wrote:\n>\n> > > > - Rename tests according to unit-tests' conventions\n> > > > - remove 'pq_test_main()' from reftable/reftable-test.h\n> > > >\n> > > > CI/PR for v5: https://github.com/gitgitgadget/git/pull/1745\n> > >\n> > > By the way, I still haven't got any answer to a question I asked\n> > > long ago on this series, wrt possibly unifying this pq and another\n> > > pq we already use elsewhere in our codebase.  If we are butchering\n> > > what we borrowed from elsewhere and store in reftable/. directory\n> > > and taking responsibility of maintaining it ourselves, we probably\n> > > should consider larger refactoring and cleaning up, and part of it\n> > > we may end up discarding this pq implementation, making the unit\n> > > testing on it a wasted effort.\n>\n> I agree it might have been better to start by replacing the pq\n> implementation in reftable/ with our own first, as there would be no\n> need for this patch series, but Chandra's GSoC is about replacing the\n> unit test framework in reftable/ with our own which is still valuable.\n> And I think that at this point it is just simpler to not get\n> distracted by replacing the pq implementation now. It's also not like\n> changing the unit test framework would make replacing the pq\n> implementation harder.\n>\n> > I did talk about this with Patrick and Christian on a private slack channel\n> > a few weeks ago and here is how that conversation went:\n> >\n> > Me: Hey, I wanted to talk about the message from Junio the other day.\n> > It is true that through this project, we are modifying the reftable directory\n> > to a point that it is no longer easily usable by someone from outside. If\n> > that is the direction we want to take, wouldn't it make more sense to get\n> > rid of reftable/pq.{c, h} altogether and use Git's prio-queue instead?\n> >\n> > Christian: Yeah, I think the direction the Git project wants to take is to\n> > integrate the reftable code more and more with the Git code. On the other\n> > hand, there are libification projects which are trying to split parts of the\n> > Git code into libraries usable by other projects. But I don't think each of\n> > these libraries should have their own test framework, their own prio-queue\n> > implementation, their own string implementation, etc. So, even if I am not\n> > sure about the end result, I think it would be ok to modify the reftable code\n> > so that it uses the Git's prio queue and maybe other Git data structures.\n> > But I'd like Patrick to confirm, and the list to agree to this. So I'd\n> > rather wait\n> > until Patrick is back from his vacation before doing things like replacing\n> > reftable/pq.{c, h} with Git's prio-queue.\n>\n> Yeah, if it had been discussed and agreed on earlier, I think\n> replacing the pq implementation would have made sense. Now I think\n> it's a bit late at this stage in Chandra's GSoC to go in this\n> direction though. I think it's better if he can focus on finishing to\n> replace the unit test framework.\n\nI'm actually more or less done with porting most of the reftable\ntests to the unit test framework and it shouldn't be long before\npatches for rest of the tests see the mailing list, so I can definitely\nmake time for other endeavors like these.\n\nThe only thing that I think is holding us back from making a change\nlike what Junio suggests is 'how far are we willing to butcher our copy\nof reftable/?' From what Patrick said earlier, I think the answer to that is\n'it is fine to modify reftable/ tests because they don't need to be uniform\nacross all implementations of reftable, but modifying other parts to be\nmore dependent on Git's internals is a no-go.'\n"},{"id":"499238","messageId":"ZqDBxUC34pV2TLGz@tanuki","threadId":"61595","inReplyTo":"CAP8UFD12Cqorr7oPS+JfOTYY6LaNUgPEJaEscf-jwLUOur+xqA@mail.gmail.com","subject":"Re: [GSoC][PATCH v5 0/7] t: port reftable/pq_test.c to the unit testing framework","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-07-24T08:56:37Z","receivedAt":"2024-07-24T08:56:43Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Wed, Jul 24, 2024 at 09:17:55AM +0200, Christian Couder wrote:\n> On Wed, Jul 24, 2024 at 7:12 AM Chandra Pratap\n> <chandrapratap3519@gmail.com> wrote:\n> > On Tue, 23 Jul 2024 at 22:39, Junio C Hamano <gitster@pobox.com> wrote:\n> > I did talk about this with Patrick and Christian on a private slack channel\n> > a few weeks ago and here is how that conversation went:\n> >\n> > Me: Hey, I wanted to talk about the message from Junio the other day.\n> > It is true that through this project, we are modifying the reftable directory\n> > to a point that it is no longer easily usable by someone from outside. If\n> > that is the direction we want to take, wouldn't it make more sense to get\n> > rid of reftable/pq.{c, h} altogether and use Git's prio-queue instead?\n> >\n> > Christian: Yeah, I think the direction the Git project wants to take is to\n> > integrate the reftable code more and more with the Git code. On the other\n> > hand, there are libification projects which are trying to split parts of the\n> > Git code into libraries usable by other projects. But I don't think each of\n> > these libraries should have their own test framework, their own prio-queue\n> > implementation, their own string implementation, etc. So, even if I am not\n> > sure about the end result, I think it would be ok to modify the reftable code\n> > so that it uses the Git's prio queue and maybe other Git data structures.\n> > But I'd like Patrick to confirm, and the list to agree to this. So I'd\n> > rather wait\n> > until Patrick is back from his vacation before doing things like replacing\n> > reftable/pq.{c, h} with Git's prio-queue.\n> \n> Yeah, if it had been discussed and agreed on earlier, I think\n> replacing the pq implementation would have made sense. Now I think\n> it's a bit late at this stage in Chandra's GSoC to go in this\n> direction though. I think it's better if he can focus on finishing to\n> replace the unit test framework.\n\nReplacing the priority queue with the one we already have will create\nadditional work in the future when we want to get the reftable library\nback into a state where it can be used as a standalone library again. I\nknow that it's currently a mess anyway, but I've heard from multiple\nfolks already who are interested in using the reftable library in their\nown C projects (most importantly libgit2).\n\nIf we want Git to be the reftable upstream for such projects, then we\nshould play nice and not make their lifes harder. I plan to work on\nportability work as soon as somebody properly commits to integrating\nreftables into their project. This will probably come in the form of:\n\n  - Removing all Git-specific includes in the \"reftable/\" directory.\n\n  - Declaring a list of \"shim\" functions and types that users of the\n    reftable library need to use.\n\n  - Implementing those shim functions for Git.\n\nOf course, those shims will closely follow the interfaces that we have\nin Git. E.g. there will shims for \"strbuf\", the tempfile interface, and\neverything else that we currently use in the reftable library. So\nultimately, I expect that the shim implementations will simply look like\nthe following:\n\n```\ntypedef struct strbuf reftable_buf;\n\nstatic inline void reftable_buf_add(struct strbuf reftable_buf *buf,\n                                    const void *data, size_t len)\n{\n    strbuf_add(buf, data, len);\n}\n```\n\nWhile we could also shim out the priority queue, I don't really think\nthat it is worth it.\n\nPatrick\n"},{"id":"499240","messageId":"ZqDDS3EhXwDittDr@tanuki","threadId":"61595","inReplyTo":"20240723143032.4261-7-chandrapratap3519@gmail.com","subject":"Re: [PATCH v5 6/7] t-reftable-pq: add test for index based comparison","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-07-24T09:03:07Z","receivedAt":"2024-07-24T09:03:13Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Tue, Jul 23, 2024 at 07:47:16PM +0530, Chandra Pratap wrote:\n> diff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\n> index 9230dd9b9e..23c3f6888b 100644\n> --- a/t/unit-tests/t-reftable-pq.c\n> +++ b/t/unit-tests/t-reftable-pq.c\n> @@ -18,7 +18,7 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n>  \t}\n>  }\n>  \n> -static void t_pq(void)\n> +static void t_pq_record(void)\n>  {\n>  \tstruct merged_iter_pqueue pq = { 0 };\n>  \tstruct reftable_record recs[54];\n> @@ -59,9 +59,48 @@ static void t_pq(void)\n>  \tmerged_iter_pqueue_release(&pq);\n>  }\n>  \n> +static void t_pq_index(void)\n> +{\n> +\tstruct merged_iter_pqueue pq = { 0 };\n> +\tstruct reftable_record recs[14];\n> +\tchar *last = NULL;\n> +\tsize_t N = ARRAY_SIZE(recs), i;\n> +\n> +\tfor (i = 0; i < N; i++) {\n> +\t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n> +\t\trecs[i].u.ref.refname = xstrdup(\"refs/heads/master\");\n> +\t}\n> +\n> +\tfor (i = 0; i < N; i++) {\n> +\t\tstruct pq_entry e = {\n> +\t\t\t.rec = &recs[i],\n> +\t\t\t.index = i,\n> +\t\t};\n> +\n> +\t\tmerged_iter_pqueue_add(&pq, &e);\n> +\t\tmerged_iter_pqueue_check(&pq);\n> +\t}\n\nOne of those reasons that we use the modulo-loops in the other tests is\nso that the order in which entries are added is mixed. Here we add them\nin priority order already, so that makes the test less interesting. We\nmight thus want to do the same here and scramble the order a bit.\n\nPatrick\n"},{"id":"499275","messageId":"xmqqttgeydtk.fsf@gitster.g","threadId":"61595","inReplyTo":"ZqDBxUC34pV2TLGz@tanuki","subject":"Re: [GSoC][PATCH v5 0/7] t: port reftable/pq_test.c to the unit testing framework","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-07-24T16:06:31Z","receivedAt":"2024-07-24T16:06:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> Of course, those shims will closely follow the interfaces that we have\n> in Git. E.g. there will shims for \"strbuf\", the tempfile interface, and\n> everything else that we currently use in the reftable library. So\n> ultimately, I expect that the shim implementations will simply look like\n> the following:\n>\n> ```\n> typedef struct strbuf reftable_buf;\n>\n> static inline void reftable_buf_add(struct strbuf reftable_buf *buf,\n>                                     const void *data, size_t len)\n> {\n>     strbuf_add(buf, data, len);\n> }\n> ```\n>\n> While we could also shim out the priority queue, I don't really think\n> that it is worth it.\n\nOK, I am fine if somebody wants to spend cycles to move the\nreftable_pq tests to the unit-test framework.  I just wasn't sure\nwhat the future plans were, and one obvious direction to replace\nreftable_pq would invalidate such work, and I wanted to make sure\neverybody involved in this effort is aware of that.\n\nThanks.\n\n"},{"id":"499278","messageId":"xmqqikwuydek.fsf@gitster.g","threadId":"61595","inReplyTo":"ZqDDS3EhXwDittDr@tanuki","subject":"Re: [PATCH v5 6/7] t-reftable-pq: add test for index based comparison","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-07-24T16:15:31Z","receivedAt":"2024-07-24T16:15:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> One of those reasons that we use the modulo-loops in the other tests is\n> so that the order in which entries are added is mixed. Here we add them\n> in priority order already, so that makes the test less interesting. We\n> might thus want to do the same here and scramble the order a bit.\n\nWouldn't modulo-loops mean the total number of elements must be\nprime with the skip count, or something, which in turn means that it\nis harder to test certain corner cases of the underlying data\nstructure (e.g. \"what if the length is exactly a power of two?  A\npower of two plus one?  A power of two minus one?\"  etc.)\n\nIt certainly is much better than just inserting in the priority\norder (or in the reverse priority order).\n\nThanks.\n"},{"id":"499309","messageId":"ZqHeNnYrJneUmPTB@tanuki","threadId":"61595","inReplyTo":"xmqqikwuydek.fsf@gitster.g","subject":"Re: [PATCH v5 6/7] t-reftable-pq: add test for index based comparison","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-07-25T05:10:14Z","receivedAt":"2024-07-25T05:10:22Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Wed, Jul 24, 2024 at 09:15:31AM -0700, Junio C Hamano wrote:\n> Patrick Steinhardt <ps@pks.im> writes:\n> \n> > One of those reasons that we use the modulo-loops in the other tests is\n> > so that the order in which entries are added is mixed. Here we add them\n> > in priority order already, so that makes the test less interesting. We\n> > might thus want to do the same here and scramble the order a bit.\n> \n> Wouldn't modulo-loops mean the total number of elements must be\n> prime with the skip count, or something, which in turn means that it\n> is harder to test certain corner cases of the underlying data\n> structure (e.g. \"what if the length is exactly a power of two?  A\n> power of two plus one?  A power of two minus one?\"  etc.)\n> \n> It certainly is much better than just inserting in the priority\n> order (or in the reverse priority order).\n\nYeah. I am not a huge fan of those modulo-loop as they hide what the\nactual test data is myself, but they are already being used in those\ntests anyway, and that's why I proposed them. The better option, in my\nopinion, is to just make the test data explicit by for example looping\nthrough an array of input data and inserting it one by one.\n\nPatrick\n"},{"id":"499315","messageId":"20240725093855.4201-1-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240723143032.4261-1-chandrapratap3519@gmail.com","subject":"[GSoC][PATCH v6 0/7] t: port reftable/pq_test.c to the unit testing framework","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-07-25T09:25:52Z","receivedAt":"2024-07-25T09:39:27Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"The reftable library comes with self tests, which are exercised\nas part of the usual end-to-end tests and are designed to\nobserve the end-user visible effects of Git commands. What it\nexercises, however, is a better match for the unit-testing\nframework, merged at 8bf6fbd0 (Merge branch 'js/doc-unit-tests',\n2023-12-09), which is designed to observe how low level\nimplementation details, at the level of sequences of individual\nfunction calls, behave.\n\nHence, port reftable/pq_test.c to the unit testing framework and\nimprove upon the ported test. The first two patches in the series\nare preparatory cleanup, the third patch moves the test to the unit\ntesting framework, and the rest of the patches improve upon the\nported test.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n\n---\nChanges in v6:\n- Use modulo loop to pseudo-randomly insert elements in\n  t_pq_index() in patch 6.\n- Use 'xstrfmt' for refnames instead of using a 'strbuf'\n  in t_pq_record() in patch 6.\n- Use string literals instead of 'xstrdup' for refnames in\n  t_pq_index() and t_merged_iter_pqueue_top() in patch 6 & 7.\n- Use modulo loop to pseudo-randomly insert elements in\n  t_merged_iter_pqueue_top() in patch 7\n\nCI/PR for v6: https://github.com/gitgitgadget/git/pull/1745\n\nChandra Pratap(7):\nreftable: remove unncessary curly braces in reftable/pq.c\nreftable: change the type of array indices to 'size_t' in reftable/pq.c\nt: move reftable/pq_test.c to the unit testing framework\nt-reftable-pq: make merged_iter_pqueue_check() static\nt-reftable-pq: make merged_iter_pqueue_check() callable by reference\nt-reftable-pq: add test for index based comparison\nt-reftable-pq: add tests for merged_iter_pqueue_top()\n\nMakefile                     |   2 +-\nreftable/pq.c                |  29 +++-----\nreftable/pq.h                |   1 -\nreftable/pq_test.c           |  74 ---------------------\nreftable/reftable-tests.h    |   1 -\nt/helper/test-reftable.c     |   1 -\nt/unit-tests/t-reftable-pq.c | 154 +++++++++++++++++++++++++++++++++++++++++++\n7 files changed, 165 insertions(+), 97 deletions(-)\n\nRange-diff against v5:\n1:  94a77f5a60 ! 1:  f5c30187e1 t-reftable-pq: add test for index based comparison\n    @@ Commit message\n         index-based comparison as well. Rename the existing test to\n         reflect its nature of only testing record-based comparison.\n\n    +    While at it, replace 'strbuf_detach' with 'xstrfmt' to assign\n    +    refnames in the existing test. This makes the test conciser.\n    +\n         Mentored-by: Patrick Steinhardt <ps@pks.im>\n         Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n         Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n    @@ t/unit-tests/t-reftable-pq.c: static void merged_iter_pqueue_check(const struct\n      {\n      \tstruct merged_iter_pqueue pq = { 0 };\n      \tstruct reftable_record recs[54];\n    +@@ t/unit-tests/t-reftable-pq.c: static void t_pq(void)\n    + \tchar *last = NULL;\n    +\n    + \tfor (i = 0; i < N; i++) {\n    +-\t\tstruct strbuf refname = STRBUF_INIT;\n    +-\t\tstrbuf_addf(&refname, \"%02\"PRIuMAX, (uintmax_t)i);\n    +-\n    + \t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n    +-\t\trecs[i].u.ref.refname = strbuf_detach(&refname, NULL);\n    ++\t\trecs[i].u.ref.refname = xstrfmt(\"%02\"PRIuMAX, (uintmax_t)i);\n    + \t}\n    +\n    + \ti = 1;\n     @@ t/unit-tests/t-reftable-pq.c: static void t_pq(void)\n      \tmerged_iter_pqueue_release(&pq);\n      }\n    @@ t/unit-tests/t-reftable-pq.c: static void t_pq(void)\n     +static void t_pq_index(void)\n     +{\n     +\tstruct merged_iter_pqueue pq = { 0 };\n    -+\tstruct reftable_record recs[14];\n    ++\tstruct reftable_record recs[13];\n     +\tchar *last = NULL;\n     +\tsize_t N = ARRAY_SIZE(recs), i;\n     +\n     +\tfor (i = 0; i < N; i++) {\n     +\t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n    -+\t\trecs[i].u.ref.refname = xstrdup(\"refs/heads/master\");\n    ++\t\trecs[i].u.ref.refname = (char *) \"refs/heads/master\";\n     +\t}\n     +\n    -+\tfor (i = 0; i < N; i++) {\n    ++\ti = 1;\n    ++\tdo {\n     +\t\tstruct pq_entry e = {\n     +\t\t\t.rec = &recs[i],\n     +\t\t\t.index = i,\n    @@ t/unit-tests/t-reftable-pq.c: static void t_pq(void)\n     +\n     +\t\tmerged_iter_pqueue_add(&pq, &e);\n     +\t\tmerged_iter_pqueue_check(&pq);\n    ++\t\ti = (i * 7) % N;\n     +\t}\n    ++\twhile (i != 1);\n     +\n    -+\tfor (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) {\n    ++\tfor (i = N - 1; i > 0; i--) {\n     +\t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n     +\t\tmerged_iter_pqueue_check(&pq);\n     +\n    @@ t/unit-tests/t-reftable-pq.c: static void t_pq(void)\n     +\t\tlast = e.rec->u.ref.refname;\n     +\t}\n     +\n    -+\tfor (i = 0; i < N; i++)\n    -+\t\treftable_record_release(&recs[i]);\n     +\tmerged_iter_pqueue_release(&pq);\n     +}\n     +\n2:  9a76f87bd1 ! 2:  394540a789 t-reftable-pq: add tests for merged_iter_pqueue_top()\n    @@ t/unit-tests/t-reftable-pq.c: static void t_pq_record(void)\n      \t\tif (last)\n      \t\t\tcheck_int(strcmp(last, e.rec->u.ref.refname), <, 0);\n     @@ t/unit-tests/t-reftable-pq.c: static void t_pq_index(void)\n    - \t}\n    + \twhile (i != 1);\n\n    - \tfor (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) {\n    + \tfor (i = N - 1; i > 0; i--) {\n     +\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n      \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n      \t\tmerged_iter_pqueue_check(&pq);\n    @@ t/unit-tests/t-reftable-pq.c: static void t_pq_index(void)\n     +static void t_merged_iter_pqueue_top(void)\n     +{\n     +\tstruct merged_iter_pqueue pq = { 0 };\n    -+\tstruct reftable_record recs[14];\n    ++\tstruct reftable_record recs[13];\n     +\tsize_t N = ARRAY_SIZE(recs), i;\n     +\n     +\tfor (i = 0; i < N; i++) {\n     +\t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n    -+\t\trecs[i].u.ref.refname = xstrdup(\"refs/heads/master\");\n    ++\t\trecs[i].u.ref.refname = (char *) \"refs/heads/master\";\n     +\t}\n     +\n    -+\tfor (i = 0; i < N; i++) {\n    ++\ti = 1;\n    ++\tdo {\n     +\t\tstruct pq_entry e = {\n     +\t\t\t.rec = &recs[i],\n     +\t\t\t.index = i,\n    @@ t/unit-tests/t-reftable-pq.c: static void t_pq_index(void)\n     +\n     +\t\tmerged_iter_pqueue_add(&pq, &e);\n     +\t\tmerged_iter_pqueue_check(&pq);\n    ++\t\ti = (i * 7) % N;\n     +\t}\n    ++\twhile (i != 1);\n     +\n    -+\tfor (i = N - 1; !merged_iter_pqueue_is_empty(pq); i--) {\n    ++\tfor (i = N - 1; i > 0; i--) {\n     +\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n     +\t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n     +\n    @@ t/unit-tests/t-reftable-pq.c: static void t_pq_index(void)\n     +\t\t}\n     +\t}\n     +\n    -+\tfor (i = 0; i < N; i++)\n    -+\t\treftable_record_release(&recs[i]);\n     +\tmerged_iter_pqueue_release(&pq);\n     +}\n     +\n\n"},{"id":"499316","messageId":"20240725093855.4201-2-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240725093855.4201-1-chandrapratap3519@gmail.com","subject":"[PATCH v6 1/7] reftable: remove unncessary curly braces in reftable/pq.c","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-07-25T09:25:53Z","receivedAt":"2024-07-25T09:39:30Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"According to Documentation/CodingGuidelines, control-flow statements\nwith a single line as their body must omit curly braces. Make\nreftable/pq.c conform to this guideline. Besides that, remove\nunnecessary newlines and variable assignment.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n reftable/pq.c | 17 ++++-------------\n 1 file changed, 4 insertions(+), 13 deletions(-)\n\ndiff --git a/reftable/pq.c b/reftable/pq.c\nindex 7fb45d8c60..1a180c5fa6 100644\n--- a/reftable/pq.c\n+++ b/reftable/pq.c\n@@ -27,22 +27,16 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n \tpq->heap[0] = pq->heap[pq->len - 1];\n \tpq->len--;\n \n-\ti = 0;\n \twhile (i < pq->len) {\n \t\tint min = i;\n \t\tint j = 2 * i + 1;\n \t\tint k = 2 * i + 2;\n-\t\tif (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i])) {\n+\t\tif (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tmin = j;\n-\t\t}\n-\t\tif (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min])) {\n+\t\tif (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min]))\n \t\t\tmin = k;\n-\t\t}\n-\n-\t\tif (min == i) {\n+\t\tif (min == i)\n \t\t\tbreak;\n-\t\t}\n-\n \t\tSWAP(pq->heap[i], pq->heap[min]);\n \t\ti = min;\n \t}\n@@ -60,12 +54,9 @@ void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry\n \ti = pq->len - 1;\n \twhile (i > 0) {\n \t\tint j = (i - 1) / 2;\n-\t\tif (pq_less(&pq->heap[j], &pq->heap[i])) {\n+\t\tif (pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tbreak;\n-\t\t}\n-\n \t\tSWAP(pq->heap[j], pq->heap[i]);\n-\n \t\ti = j;\n \t}\n }\n-- \n2.45.GIT\n\n"},{"id":"499317","messageId":"20240725093855.4201-3-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240725093855.4201-1-chandrapratap3519@gmail.com","subject":"[PATCH v6 2/7] reftable: change the type of array indices to 'size_t' in reftable/pq.c","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-07-25T09:25:54Z","receivedAt":"2024-07-25T09:39:33Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"The variables 'i', 'j', 'k' and 'min' are used as indices for\n'pq->heap', which is an array. Additionally, 'pq->len' is of\ntype 'size_t' and is often used to assign values to these\nvariables. Hence, change the type of these variables from 'int'\nto 'size_t'.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n reftable/pq.c | 12 ++++++------\n 1 file changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/reftable/pq.c b/reftable/pq.c\nindex 1a180c5fa6..2b5b7d1c0e 100644\n--- a/reftable/pq.c\n+++ b/reftable/pq.c\n@@ -22,15 +22,15 @@ int pq_less(struct pq_entry *a, struct pq_entry *b)\n \n struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n {\n-\tint i = 0;\n+\tsize_t i = 0;\n \tstruct pq_entry e = pq->heap[0];\n \tpq->heap[0] = pq->heap[pq->len - 1];\n \tpq->len--;\n \n \twhile (i < pq->len) {\n-\t\tint min = i;\n-\t\tint j = 2 * i + 1;\n-\t\tint k = 2 * i + 2;\n+\t\tsize_t min = i;\n+\t\tsize_t j = 2 * i + 1;\n+\t\tsize_t k = 2 * i + 2;\n \t\tif (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tmin = j;\n \t\tif (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min]))\n@@ -46,14 +46,14 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n \n void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e)\n {\n-\tint i = 0;\n+\tsize_t i = 0;\n \n \tREFTABLE_ALLOC_GROW(pq->heap, pq->len + 1, pq->cap);\n \tpq->heap[pq->len++] = *e;\n \n \ti = pq->len - 1;\n \twhile (i > 0) {\n-\t\tint j = (i - 1) / 2;\n+\t\tsize_t j = (i - 1) / 2;\n \t\tif (pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tbreak;\n \t\tSWAP(pq->heap[j], pq->heap[i]);\n-- \n2.45.GIT\n\n"},{"id":"499318","messageId":"20240725093855.4201-4-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240725093855.4201-1-chandrapratap3519@gmail.com","subject":"[PATCH v6 3/7] t: move reftable/pq_test.c to the unit testing framework","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-07-25T09:25:55Z","receivedAt":"2024-07-25T09:39:36Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"reftable/pq_test.c exercises a priority queue defined by\nreftable/pq.{c, h}. Migrate reftable/pq_test.c to the unit testing\nframework. Migration involves refactoring the tests to use the unit\ntesting framework instead of reftable's test framework, and\nrenaming the tests to align with unit-tests' standards.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n Makefile                                      |  2 +-\n reftable/reftable-tests.h                     |  1 -\n t/helper/test-reftable.c                      |  1 -\n .../pq_test.c => t/unit-tests/t-reftable-pq.c | 39 ++++++++-----------\n 4 files changed, 17 insertions(+), 26 deletions(-)\n rename reftable/pq_test.c => t/unit-tests/t-reftable-pq.c (61%)\n\ndiff --git a/Makefile b/Makefile\nindex d6479092a0..1ee83e98dc 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1340,6 +1340,7 @@ UNIT_TEST_PROGRAMS += t-oidmap\n UNIT_TEST_PROGRAMS += t-oidtree\n UNIT_TEST_PROGRAMS += t-prio-queue\n UNIT_TEST_PROGRAMS += t-reftable-basics\n+UNIT_TEST_PROGRAMS += t-reftable-pq\n UNIT_TEST_PROGRAMS += t-reftable-record\n UNIT_TEST_PROGRAMS += t-strbuf\n UNIT_TEST_PROGRAMS += t-strcmp-offset\n@@ -2681,7 +2682,6 @@ REFTABLE_OBJS += reftable/writer.o\n REFTABLE_TEST_OBJS += reftable/block_test.o\n REFTABLE_TEST_OBJS += reftable/dump.o\n REFTABLE_TEST_OBJS += reftable/merged_test.o\n-REFTABLE_TEST_OBJS += reftable/pq_test.o\n REFTABLE_TEST_OBJS += reftable/readwrite_test.o\n REFTABLE_TEST_OBJS += reftable/stack_test.o\n REFTABLE_TEST_OBJS += reftable/test_framework.o\ndiff --git a/reftable/reftable-tests.h b/reftable/reftable-tests.h\nindex 114cc3d053..67283faf06 100644\n--- a/reftable/reftable-tests.h\n+++ b/reftable/reftable-tests.h\n@@ -12,7 +12,6 @@ license that can be found in the LICENSE file or at\n int basics_test_main(int argc, const char **argv);\n int block_test_main(int argc, const char **argv);\n int merged_test_main(int argc, const char **argv);\n-int pq_test_main(int argc, const char **argv);\n int record_test_main(int argc, const char **argv);\n int readwrite_test_main(int argc, const char **argv);\n int stack_test_main(int argc, const char **argv);\ndiff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c\nindex aa6538a8da..b808ad3e12 100644\n--- a/t/helper/test-reftable.c\n+++ b/t/helper/test-reftable.c\n@@ -7,7 +7,6 @@ int cmd__reftable(int argc, const char **argv)\n \t/* test from simple to complex. */\n \tblock_test_main(argc, argv);\n \ttree_test_main(argc, argv);\n-\tpq_test_main(argc, argv);\n \treadwrite_test_main(argc, argv);\n \tmerged_test_main(argc, argv);\n \tstack_test_main(argc, argv);\ndiff --git a/reftable/pq_test.c b/t/unit-tests/t-reftable-pq.c\nsimilarity index 61%\nrename from reftable/pq_test.c\nrename to t/unit-tests/t-reftable-pq.c\nindex b7d3c80cc7..a78aba9e71 100644\n--- a/reftable/pq_test.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -6,35 +6,28 @@ license that can be found in the LICENSE file or at\n https://developers.google.com/open-source/licenses/bsd\n */\n \n-#include \"system.h\"\n-\n-#include \"basics.h\"\n-#include \"constants.h\"\n-#include \"pq.h\"\n-#include \"record.h\"\n-#include \"reftable-tests.h\"\n-#include \"test_framework.h\"\n+#include \"test-lib.h\"\n+#include \"reftable/constants.h\"\n+#include \"reftable/pq.h\"\n \n void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n {\n-\tint i;\n-\tfor (i = 1; i < pq.len; i++) {\n-\t\tint parent = (i - 1) / 2;\n-\n-\t\tEXPECT(pq_less(&pq.heap[parent], &pq.heap[i]));\n+\tfor (size_t i = 1; i < pq.len; i++) {\n+\t\tsize_t parent = (i - 1) / 2;\n+\t\tcheck(pq_less(&pq.heap[parent], &pq.heap[i]));\n \t}\n }\n \n-static void test_pq(void)\n+static void t_pq(void)\n {\n-\tstruct merged_iter_pqueue pq = { NULL };\n+\tstruct merged_iter_pqueue pq = { 0 };\n \tstruct reftable_record recs[54];\n-\tint N = ARRAY_SIZE(recs) - 1, i;\n+\tsize_t N = ARRAY_SIZE(recs) - 1, i;\n \tchar *last = NULL;\n \n \tfor (i = 0; i < N; i++) {\n \t\tstruct strbuf refname = STRBUF_INIT;\n-\t\tstrbuf_addf(&refname, \"%02d\", i);\n+\t\tstrbuf_addf(&refname, \"%02\"PRIuMAX, (uintmax_t)i);\n \n \t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n \t\trecs[i].u.ref.refname = strbuf_detach(&refname, NULL);\n@@ -48,7 +41,6 @@ static void test_pq(void)\n \n \t\tmerged_iter_pqueue_add(&pq, &e);\n \t\tmerged_iter_pqueue_check(pq);\n-\n \t\ti = (i * 7) % N;\n \t} while (i != 1);\n \n@@ -56,9 +48,9 @@ static void test_pq(void)\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n \t\tmerged_iter_pqueue_check(pq);\n \n-\t\tEXPECT(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n+\t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tif (last)\n-\t\t\tEXPECT(strcmp(last, e.rec->u.ref.refname) < 0);\n+\t\t\tcheck_int(strcmp(last, e.rec->u.ref.refname), <, 0);\n \t\tlast = e.rec->u.ref.refname;\n \t}\n \n@@ -67,8 +59,9 @@ static void test_pq(void)\n \tmerged_iter_pqueue_release(&pq);\n }\n \n-int pq_test_main(int argc, const char *argv[])\n+int cmd_main(int argc, const char *argv[])\n {\n-\tRUN_TEST(test_pq);\n-\treturn 0;\n+\tTEST(t_pq(), \"pq works\");\n+\n+\treturn test_done();\n }\n-- \n2.45.GIT\n\n"},{"id":"499319","messageId":"20240725093855.4201-5-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240725093855.4201-1-chandrapratap3519@gmail.com","subject":"[PATCH v6 4/7] t-reftable-pq: make merged_iter_pqueue_check() static","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-07-25T09:25:56Z","receivedAt":"2024-07-25T09:39:39Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"merged_iter_pqueue_check() is a function previously defined in\nreftable/pq_test.c (now t/unit-tests/t-reftable-pq.c) and used in\nthe testing of a priority queue as defined by reftable/pq.{c, h}.\nAs such, this function is only called by reftable/pq_test.c and it\nmakes little sense to expose it to non-testing code via reftable/pq.h.\n\nHence, make this function static and remove its prototype from\nreftable/pq.h.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n reftable/pq.h                | 1 -\n t/unit-tests/t-reftable-pq.c | 2 +-\n 2 files changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/reftable/pq.h b/reftable/pq.h\nindex f796c23179..707bd26767 100644\n--- a/reftable/pq.h\n+++ b/reftable/pq.h\n@@ -22,7 +22,6 @@ struct merged_iter_pqueue {\n \tsize_t cap;\n };\n \n-void merged_iter_pqueue_check(struct merged_iter_pqueue pq);\n struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq);\n void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e);\n void merged_iter_pqueue_release(struct merged_iter_pqueue *pq);\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex a78aba9e71..220e82be19 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -10,7 +10,7 @@ license that can be found in the LICENSE file or at\n #include \"reftable/constants.h\"\n #include \"reftable/pq.h\"\n \n-void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n+static void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n {\n \tfor (size_t i = 1; i < pq.len; i++) {\n \t\tsize_t parent = (i - 1) / 2;\n-- \n2.45.GIT\n\n"},{"id":"499320","messageId":"20240725093855.4201-6-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240725093855.4201-1-chandrapratap3519@gmail.com","subject":"[PATCH v6 5/7] t-reftable-pq: make merged_iter_pqueue_check() callable by reference","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-07-25T09:25:57Z","receivedAt":"2024-07-25T09:39:41Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"merged_iter_pqueue_check() checks the validity of a priority queue\nrepresented by a merged_iter_pqueue struct by asserting the\nparent-child relation in the struct's heap. Explicity passing a\nstruct to this function means a copy of the entire struct is created,\nwhich is inefficient.\n\nMake the function accept a pointer to the struct instead. This is\nsafe to do since the function doesn't modify the struct in any way.\nMake the function parameter 'const' to assert immutability.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n t/unit-tests/t-reftable-pq.c | 10 +++++-----\n 1 file changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex 220e82be19..9230dd9b9e 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -10,11 +10,11 @@ license that can be found in the LICENSE file or at\n #include \"reftable/constants.h\"\n #include \"reftable/pq.h\"\n \n-static void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n+static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n {\n-\tfor (size_t i = 1; i < pq.len; i++) {\n+\tfor (size_t i = 1; i < pq->len; i++) {\n \t\tsize_t parent = (i - 1) / 2;\n-\t\tcheck(pq_less(&pq.heap[parent], &pq.heap[i]));\n+\t\tcheck(pq_less(&pq->heap[parent], &pq->heap[i]));\n \t}\n }\n \n@@ -40,13 +40,13 @@ static void t_pq(void)\n \t\t};\n \n \t\tmerged_iter_pqueue_add(&pq, &e);\n-\t\tmerged_iter_pqueue_check(pq);\n+\t\tmerged_iter_pqueue_check(&pq);\n \t\ti = (i * 7) % N;\n \t} while (i != 1);\n \n \twhile (!merged_iter_pqueue_is_empty(pq)) {\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n-\t\tmerged_iter_pqueue_check(pq);\n+\t\tmerged_iter_pqueue_check(&pq);\n \n \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tif (last)\n-- \n2.45.GIT\n\n"},{"id":"499321","messageId":"20240725093855.4201-7-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240725093855.4201-1-chandrapratap3519@gmail.com","subject":"[PATCH v6 6/7] t-reftable-pq: add test for index based comparison","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-07-25T09:25:58Z","receivedAt":"2024-07-25T09:39:45Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"When comparing two entries, the priority queue as defined by\nreftable/pq.{c, h} first compares the entries on the basis of\ntheir ref-record's keys. If the keys turn out to be equal, the\ncomparison is then made on the basis of their update indices\n(which are never equal).\n\nIn the current testing setup, only the case for comparison on\nthe basis of ref-record's keys is exercised. Add a test for\nindex-based comparison as well. Rename the existing test to\nreflect its nature of only testing record-based comparison.\n\nWhile at it, replace 'strbuf_detach' with 'xstrfmt' to assign\nrefnames in the existing test. This makes the test conciser.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n t/unit-tests/t-reftable-pq.c | 49 +++++++++++++++++++++++++++++++-----\n 1 file changed, 43 insertions(+), 6 deletions(-)\n\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex 9230dd9b9e..67f3e4546c 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -18,7 +18,7 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n \t}\n }\n \n-static void t_pq(void)\n+static void t_pq_record(void)\n {\n \tstruct merged_iter_pqueue pq = { 0 };\n \tstruct reftable_record recs[54];\n@@ -26,11 +26,8 @@ static void t_pq(void)\n \tchar *last = NULL;\n \n \tfor (i = 0; i < N; i++) {\n-\t\tstruct strbuf refname = STRBUF_INIT;\n-\t\tstrbuf_addf(&refname, \"%02\"PRIuMAX, (uintmax_t)i);\n-\n \t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n-\t\trecs[i].u.ref.refname = strbuf_detach(&refname, NULL);\n+\t\trecs[i].u.ref.refname = xstrfmt(\"%02\"PRIuMAX, (uintmax_t)i);\n \t}\n \n \ti = 1;\n@@ -59,9 +56,49 @@ static void t_pq(void)\n \tmerged_iter_pqueue_release(&pq);\n }\n \n+static void t_pq_index(void)\n+{\n+\tstruct merged_iter_pqueue pq = { 0 };\n+\tstruct reftable_record recs[13];\n+\tchar *last = NULL;\n+\tsize_t N = ARRAY_SIZE(recs), i;\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n+\t\trecs[i].u.ref.refname = (char *) \"refs/heads/master\";\n+\t}\n+\n+\ti = 1;\n+\tdo {\n+\t\tstruct pq_entry e = {\n+\t\t\t.rec = &recs[i],\n+\t\t\t.index = i,\n+\t\t};\n+\n+\t\tmerged_iter_pqueue_add(&pq, &e);\n+\t\tmerged_iter_pqueue_check(&pq);\n+\t\ti = (i * 7) % N;\n+\t}\n+\twhile (i != 1);\n+\n+\tfor (i = N - 1; i > 0; i--) {\n+\t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n+\t\tmerged_iter_pqueue_check(&pq);\n+\n+\t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n+\t\tcheck_int(e.index, ==, i);\n+\t\tif (last)\n+\t\t\tcheck_str(last, e.rec->u.ref.refname);\n+\t\tlast = e.rec->u.ref.refname;\n+\t}\n+\n+\tmerged_iter_pqueue_release(&pq);\n+}\n+\n int cmd_main(int argc, const char *argv[])\n {\n-\tTEST(t_pq(), \"pq works\");\n+\tTEST(t_pq_record(), \"pq works with record-based comparison\");\n+\tTEST(t_pq_index(), \"pq works with index-based comparison\");\n \n \treturn test_done();\n }\n-- \n2.45.GIT\n\n"},{"id":"499322","messageId":"20240725093855.4201-8-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240725093855.4201-1-chandrapratap3519@gmail.com","subject":"[PATCH v6 7/7] t-reftable-pq: add tests for merged_iter_pqueue_top()","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-07-25T09:25:59Z","receivedAt":"2024-07-25T09:39:47Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"merged_iter_pqueue_top() as defined by reftable/pq.{c, h} returns\nthe element at the top of a priority-queue's heap without removing\nit. Since there are no tests for this function in the existing\nsetup, add tests for the same.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n t/unit-tests/t-reftable-pq.c | 50 ++++++++++++++++++++++++++++++++++++\n 1 file changed, 50 insertions(+)\n\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex 67f3e4546c..ce322d7255 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -18,6 +18,11 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n \t}\n }\n \n+static int pq_entry_equal(struct pq_entry *a, struct pq_entry *b)\n+{\n+\treturn !reftable_record_cmp(a->rec, b->rec) && (a->index == b->index);\n+}\n+\n static void t_pq_record(void)\n {\n \tstruct merged_iter_pqueue pq = { 0 };\n@@ -42,9 +47,11 @@ static void t_pq_record(void)\n \t} while (i != 1);\n \n \twhile (!merged_iter_pqueue_is_empty(pq)) {\n+\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n \t\tmerged_iter_pqueue_check(&pq);\n \n+\t\tcheck(pq_entry_equal(&top, &e));\n \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tif (last)\n \t\t\tcheck_int(strcmp(last, e.rec->u.ref.refname), <, 0);\n@@ -82,9 +89,11 @@ static void t_pq_index(void)\n \twhile (i != 1);\n \n \tfor (i = N - 1; i > 0; i--) {\n+\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n \t\tmerged_iter_pqueue_check(&pq);\n \n+\t\tcheck(pq_entry_equal(&top, &e));\n \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tcheck_int(e.index, ==, i);\n \t\tif (last)\n@@ -95,10 +104,51 @@ static void t_pq_index(void)\n \tmerged_iter_pqueue_release(&pq);\n }\n \n+static void t_merged_iter_pqueue_top(void)\n+{\n+\tstruct merged_iter_pqueue pq = { 0 };\n+\tstruct reftable_record recs[13];\n+\tsize_t N = ARRAY_SIZE(recs), i;\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n+\t\trecs[i].u.ref.refname = (char *) \"refs/heads/master\";\n+\t}\n+\n+\ti = 1;\n+\tdo {\n+\t\tstruct pq_entry e = {\n+\t\t\t.rec = &recs[i],\n+\t\t\t.index = i,\n+\t\t};\n+\n+\t\tmerged_iter_pqueue_add(&pq, &e);\n+\t\tmerged_iter_pqueue_check(&pq);\n+\t\ti = (i * 7) % N;\n+\t}\n+\twhile (i != 1);\n+\n+\tfor (i = N - 1; i > 0; i--) {\n+\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n+\t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n+\n+\t\tmerged_iter_pqueue_check(&pq);\n+\t\tcheck(pq_entry_equal(&top, &e));\n+\t\tcheck(reftable_record_equal(top.rec, &recs[i], GIT_SHA1_RAWSZ));\n+\t\tfor (size_t j = 0; i < pq.len; j++) {\n+\t\t\tcheck(pq_less(&top, &pq.heap[j]));\n+\t\t\tcheck_int(top.index, >, j);\n+\t\t}\n+\t}\n+\n+\tmerged_iter_pqueue_release(&pq);\n+}\n+\n int cmd_main(int argc, const char *argv[])\n {\n \tTEST(t_pq_record(), \"pq works with record-based comparison\");\n \tTEST(t_pq_index(), \"pq works with index-based comparison\");\n+\tTEST(t_merged_iter_pqueue_top(), \"merged_iter_pqueue_top works\");\n \n \treturn test_done();\n }\n-- \n2.45.GIT\n\n"},{"id":"499334","messageId":"e222c920-731c-4b8d-9d84-c9d6b56c4d27@app.fastmail.com","threadId":"61595","inReplyTo":"20240725093855.4201-2-chandrapratap3519@gmail.com","subject":"Re: [PATCH v6 1/7] reftable: remove unncessary curly braces in reftable/pq.c","fromName":"Kristoffer Haugsbakk","fromEmail":"code@khaugsbakk.name","sentAt":"2024-07-25T13:29:08Z","receivedAt":"2024-07-25T13:29:29Z","isPatch":true,"sender":{"key":"code@khaugsbakk.name","avatar":"https://avatars.githubusercontent.com/u/2229597?v=4"},"body":"On Thu, Jul 25, 2024, at 11:25, Chandra Pratap wrote:\n> […]\n\ns/unncessary/unnecessary/\n\n(the subject line)\n\n-- \nKristoffer Haugsbakk\n\n"},{"id":"499563","messageId":"ZqiCLLps7k2i8p2C@tanuki","threadId":"61595","inReplyTo":"20240725093855.4201-7-chandrapratap3519@gmail.com","subject":"Re: [PATCH v6 6/7] t-reftable-pq: add test for index based comparison","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-07-30T06:03:24Z","receivedAt":"2024-07-30T06:03:29Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Jul 25, 2024 at 02:55:58PM +0530, Chandra Pratap wrote:\n> @@ -59,9 +56,49 @@ static void t_pq(void)\n>  \tmerged_iter_pqueue_release(&pq);\n>  }\n>  \n> +static void t_pq_index(void)\n> +{\n> +\tstruct merged_iter_pqueue pq = { 0 };\n> +\tstruct reftable_record recs[13];\n> +\tchar *last = NULL;\n> +\tsize_t N = ARRAY_SIZE(recs), i;\n> +\n> +\tfor (i = 0; i < N; i++) {\n> +\t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n> +\t\trecs[i].u.ref.refname = (char *) \"refs/heads/master\";\n> +\t}\n> +\n> +\ti = 1;\n> +\tdo {\n> +\t\tstruct pq_entry e = {\n> +\t\t\t.rec = &recs[i],\n> +\t\t\t.index = i,\n> +\t\t};\n> +\n> +\t\tmerged_iter_pqueue_add(&pq, &e);\n> +\t\tmerged_iter_pqueue_check(&pq);\n> +\t\ti = (i * 7) % N;\n> +\t}\n> +\twhile (i != 1);\n\nNit: the `while (i != 1)` should go on the same line as the closing\ncurly brace.\n\nPatrick\n"},{"id":"499564","messageId":"ZqiCU_si-bFUgl4a@tanuki","threadId":"61595","inReplyTo":"20240725093855.4201-8-chandrapratap3519@gmail.com","subject":"Re: [PATCH v6 7/7] t-reftable-pq: add tests for merged_iter_pqueue_top()","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-07-30T06:04:03Z","receivedAt":"2024-07-30T06:04:09Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Jul 25, 2024 at 02:55:59PM +0530, Chandra Pratap wrote:\n> @@ -95,10 +104,51 @@ static void t_pq_index(void)\n>  \tmerged_iter_pqueue_release(&pq);\n>  }\n>  \n> +static void t_merged_iter_pqueue_top(void)\n> +{\n> +\tstruct merged_iter_pqueue pq = { 0 };\n> +\tstruct reftable_record recs[13];\n> +\tsize_t N = ARRAY_SIZE(recs), i;\n> +\n> +\tfor (i = 0; i < N; i++) {\n> +\t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n> +\t\trecs[i].u.ref.refname = (char *) \"refs/heads/master\";\n> +\t}\n> +\n> +\ti = 1;\n> +\tdo {\n> +\t\tstruct pq_entry e = {\n> +\t\t\t.rec = &recs[i],\n> +\t\t\t.index = i,\n> +\t\t};\n> +\n> +\t\tmerged_iter_pqueue_add(&pq, &e);\n> +\t\tmerged_iter_pqueue_check(&pq);\n> +\t\ti = (i * 7) % N;\n> +\t}\n> +\twhile (i != 1);\n\nSame nit here. Other than that this patch series looks good to me,\nthanks!\n\nPatrick\n"},{"id":"499827","messageId":"20240801110453.5087-1-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240725093855.4201-1-chandrapratap3519@gmail.com","subject":"[GSoC][PATCH v7 0/7] t: port reftable/pq_test.c to the unit testing framework","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-08-01T10:59:41Z","receivedAt":"2024-08-01T11:05:21Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"The reftable library comes with self tests, which are exercised\nas part of the usual end-to-end tests and are designed to\nobserve the end-user visible effects of Git commands. What it\nexercises, however, is a better match for the unit-testing\nframework, merged at 8bf6fbd0 (Merge branch 'js/doc-unit-tests',\n2023-12-09), which is designed to observe how low level\nimplementation details, at the level of sequences of individual\nfunction calls, behave.\n\nHence, port reftable/pq_test.c to the unit testing framework and\nimprove upon the ported test. The first two patches in the series\nare preparatory cleanup, the third patch moves the test to the unit\ntesting framework, and the rest of the patches improve upon the\nported test.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n\n---\nChanges in v7:\n- Fix a typo in patch 1\n- Fix do-while style error in patch 6 and 7\n\nCI/PR for v7: https://github.com/gitgitgadget/git/pull/1745\n\nChandra Pratap(7):\nreftable: remove unncessary curly braces in reftable/pq.c\nreftable: change the type of array indices to 'size_t' in reftable/pq.c\nt: move reftable/pq_test.c to the unit testing framework\nt-reftable-pq: make merged_iter_pqueue_check() static\nt-reftable-pq: make merged_iter_pqueue_check() callable by reference\nt-reftable-pq: add test for index based comparison\nt-reftable-pq: add tests for merged_iter_pqueue_top()\n\nMakefile                     |   2 +-\nreftable/pq.c                |  29 +++-----\nreftable/pq.h                |   1 -\nreftable/pq_test.c           |  74 ---------------------\nreftable/reftable-tests.h    |   1 -\nt/helper/test-reftable.c     |   1 -\nt/unit-tests/t-reftable-pq.c | 152 +++++++++++++++++++++++++++++++++++++++++++\n7 files changed, 163 insertions(+), 97 deletions(-)\n\nRange-diff against v6:\n\n1:  acd9d26aaf ! 1:  91719cc47f reftable: remove unncessary curly braces in reftable/pq.c\n    @@ Metadata\n     Author: Chandra Pratap <chandrapratap3519@gmail.com>\n\n      ## Commit message ##\n    -    reftable: remove unncessary curly braces in reftable/pq.c\n    +    reftable: remove unnecessary curly braces in reftable/pq.c\n\n         According to Documentation/CodingGuidelines, control-flow statements\n         with a single line as their body must omit curly braces. Make\n2:  2e0986207b = 2:  2e5e72d5c5 reftable: change the type of array indices to 'size_t' in reftable/pq.c\n3:  df06b6d604 = 3:  5db9e92f20 t: move reftable/pq_test.c to the unit testing framework\n4:  40745ab18e = 4:  9334b1fe9e t-reftable-pq: make merged_iter_pqueue_check() static\n5:  ee8432ac4a = 5:  9d8c33d1fc t-reftable-pq: make merged_iter_pqueue_check() callable by reference\n6:  f5c30187e1 ! 6:  7a67861652 t-reftable-pq: add test for index based comparison\n    @@ t/unit-tests/t-reftable-pq.c: static void t_pq(void)\n     +\t\tmerged_iter_pqueue_add(&pq, &e);\n     +\t\tmerged_iter_pqueue_check(&pq);\n     +\t\ti = (i * 7) % N;\n    -+\t}\n    -+\twhile (i != 1);\n    ++\t} while (i != 1);\n     +\n     +\tfor (i = N - 1; i > 0; i--) {\n     +\t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n7:  394540a789 ! 7:  5ac60563e4 t-reftable-pq: add tests for merged_iter_pqueue_top()\n    @@ t/unit-tests/t-reftable-pq.c: static void t_pq_record(void)\n      \t\tif (last)\n      \t\t\tcheck_int(strcmp(last, e.rec->u.ref.refname), <, 0);\n     @@ t/unit-tests/t-reftable-pq.c: static void t_pq_index(void)\n    - \twhile (i != 1);\n    + \t} while (i != 1);\n\n      \tfor (i = N - 1; i > 0; i--) {\n     +\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n    @@ t/unit-tests/t-reftable-pq.c: static void t_pq_index(void)\n     +\t\tmerged_iter_pqueue_add(&pq, &e);\n     +\t\tmerged_iter_pqueue_check(&pq);\n     +\t\ti = (i * 7) % N;\n    -+\t}\n    -+\twhile (i != 1);\n    ++\t} while (i != 1);\n     +\n     +\tfor (i = N - 1; i > 0; i--) {\n     +\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n\n"},{"id":"499828","messageId":"20240801110453.5087-2-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240801110453.5087-1-chandrapratap3519@gmail.com","subject":"[PATCH v7 1/7] reftable: remove unnecessary curly braces in reftable/pq.c","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-08-01T10:59:42Z","receivedAt":"2024-08-01T11:05:24Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"According to Documentation/CodingGuidelines, control-flow statements\nwith a single line as their body must omit curly braces. Make\nreftable/pq.c conform to this guideline. Besides that, remove\nunnecessary newlines and variable assignment.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n reftable/pq.c | 17 ++++-------------\n 1 file changed, 4 insertions(+), 13 deletions(-)\n\ndiff --git a/reftable/pq.c b/reftable/pq.c\nindex 7fb45d8c60..1a180c5fa6 100644\n--- a/reftable/pq.c\n+++ b/reftable/pq.c\n@@ -27,22 +27,16 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n \tpq->heap[0] = pq->heap[pq->len - 1];\n \tpq->len--;\n \n-\ti = 0;\n \twhile (i < pq->len) {\n \t\tint min = i;\n \t\tint j = 2 * i + 1;\n \t\tint k = 2 * i + 2;\n-\t\tif (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i])) {\n+\t\tif (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tmin = j;\n-\t\t}\n-\t\tif (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min])) {\n+\t\tif (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min]))\n \t\t\tmin = k;\n-\t\t}\n-\n-\t\tif (min == i) {\n+\t\tif (min == i)\n \t\t\tbreak;\n-\t\t}\n-\n \t\tSWAP(pq->heap[i], pq->heap[min]);\n \t\ti = min;\n \t}\n@@ -60,12 +54,9 @@ void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry\n \ti = pq->len - 1;\n \twhile (i > 0) {\n \t\tint j = (i - 1) / 2;\n-\t\tif (pq_less(&pq->heap[j], &pq->heap[i])) {\n+\t\tif (pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tbreak;\n-\t\t}\n-\n \t\tSWAP(pq->heap[j], pq->heap[i]);\n-\n \t\ti = j;\n \t}\n }\n-- \n2.45.GIT\n\n"},{"id":"499829","messageId":"20240801110453.5087-3-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240801110453.5087-1-chandrapratap3519@gmail.com","subject":"[PATCH v7 2/7] reftable: change the type of array indices to 'size_t' in reftable/pq.c","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-08-01T10:59:43Z","receivedAt":"2024-08-01T11:05:27Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"The variables 'i', 'j', 'k' and 'min' are used as indices for\n'pq->heap', which is an array. Additionally, 'pq->len' is of\ntype 'size_t' and is often used to assign values to these\nvariables. Hence, change the type of these variables from 'int'\nto 'size_t'.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n reftable/pq.c | 12 ++++++------\n 1 file changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/reftable/pq.c b/reftable/pq.c\nindex 1a180c5fa6..2b5b7d1c0e 100644\n--- a/reftable/pq.c\n+++ b/reftable/pq.c\n@@ -22,15 +22,15 @@ int pq_less(struct pq_entry *a, struct pq_entry *b)\n \n struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n {\n-\tint i = 0;\n+\tsize_t i = 0;\n \tstruct pq_entry e = pq->heap[0];\n \tpq->heap[0] = pq->heap[pq->len - 1];\n \tpq->len--;\n \n \twhile (i < pq->len) {\n-\t\tint min = i;\n-\t\tint j = 2 * i + 1;\n-\t\tint k = 2 * i + 2;\n+\t\tsize_t min = i;\n+\t\tsize_t j = 2 * i + 1;\n+\t\tsize_t k = 2 * i + 2;\n \t\tif (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tmin = j;\n \t\tif (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min]))\n@@ -46,14 +46,14 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq)\n \n void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e)\n {\n-\tint i = 0;\n+\tsize_t i = 0;\n \n \tREFTABLE_ALLOC_GROW(pq->heap, pq->len + 1, pq->cap);\n \tpq->heap[pq->len++] = *e;\n \n \ti = pq->len - 1;\n \twhile (i > 0) {\n-\t\tint j = (i - 1) / 2;\n+\t\tsize_t j = (i - 1) / 2;\n \t\tif (pq_less(&pq->heap[j], &pq->heap[i]))\n \t\t\tbreak;\n \t\tSWAP(pq->heap[j], pq->heap[i]);\n-- \n2.45.GIT\n\n"},{"id":"499830","messageId":"20240801110453.5087-4-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240801110453.5087-1-chandrapratap3519@gmail.com","subject":"[PATCH v7 3/7] t: move reftable/pq_test.c to the unit testing framework","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-08-01T10:59:44Z","receivedAt":"2024-08-01T11:05:30Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"reftable/pq_test.c exercises a priority queue defined by\nreftable/pq.{c, h}. Migrate reftable/pq_test.c to the unit testing\nframework. Migration involves refactoring the tests to use the unit\ntesting framework instead of reftable's test framework, and\nrenaming the tests to align with unit-tests' standards.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n Makefile                                      |  2 +-\n reftable/reftable-tests.h                     |  1 -\n t/helper/test-reftable.c                      |  1 -\n .../pq_test.c => t/unit-tests/t-reftable-pq.c | 39 ++++++++-----------\n 4 files changed, 17 insertions(+), 26 deletions(-)\n rename reftable/pq_test.c => t/unit-tests/t-reftable-pq.c (61%)\n\ndiff --git a/Makefile b/Makefile\nindex d6479092a0..1ee83e98dc 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1340,6 +1340,7 @@ UNIT_TEST_PROGRAMS += t-oidmap\n UNIT_TEST_PROGRAMS += t-oidtree\n UNIT_TEST_PROGRAMS += t-prio-queue\n UNIT_TEST_PROGRAMS += t-reftable-basics\n+UNIT_TEST_PROGRAMS += t-reftable-pq\n UNIT_TEST_PROGRAMS += t-reftable-record\n UNIT_TEST_PROGRAMS += t-strbuf\n UNIT_TEST_PROGRAMS += t-strcmp-offset\n@@ -2681,7 +2682,6 @@ REFTABLE_OBJS += reftable/writer.o\n REFTABLE_TEST_OBJS += reftable/block_test.o\n REFTABLE_TEST_OBJS += reftable/dump.o\n REFTABLE_TEST_OBJS += reftable/merged_test.o\n-REFTABLE_TEST_OBJS += reftable/pq_test.o\n REFTABLE_TEST_OBJS += reftable/readwrite_test.o\n REFTABLE_TEST_OBJS += reftable/stack_test.o\n REFTABLE_TEST_OBJS += reftable/test_framework.o\ndiff --git a/reftable/reftable-tests.h b/reftable/reftable-tests.h\nindex 114cc3d053..67283faf06 100644\n--- a/reftable/reftable-tests.h\n+++ b/reftable/reftable-tests.h\n@@ -12,7 +12,6 @@ license that can be found in the LICENSE file or at\n int basics_test_main(int argc, const char **argv);\n int block_test_main(int argc, const char **argv);\n int merged_test_main(int argc, const char **argv);\n-int pq_test_main(int argc, const char **argv);\n int record_test_main(int argc, const char **argv);\n int readwrite_test_main(int argc, const char **argv);\n int stack_test_main(int argc, const char **argv);\ndiff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c\nindex aa6538a8da..b808ad3e12 100644\n--- a/t/helper/test-reftable.c\n+++ b/t/helper/test-reftable.c\n@@ -7,7 +7,6 @@ int cmd__reftable(int argc, const char **argv)\n \t/* test from simple to complex. */\n \tblock_test_main(argc, argv);\n \ttree_test_main(argc, argv);\n-\tpq_test_main(argc, argv);\n \treadwrite_test_main(argc, argv);\n \tmerged_test_main(argc, argv);\n \tstack_test_main(argc, argv);\ndiff --git a/reftable/pq_test.c b/t/unit-tests/t-reftable-pq.c\nsimilarity index 61%\nrename from reftable/pq_test.c\nrename to t/unit-tests/t-reftable-pq.c\nindex b7d3c80cc7..a78aba9e71 100644\n--- a/reftable/pq_test.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -6,35 +6,28 @@ license that can be found in the LICENSE file or at\n https://developers.google.com/open-source/licenses/bsd\n */\n \n-#include \"system.h\"\n-\n-#include \"basics.h\"\n-#include \"constants.h\"\n-#include \"pq.h\"\n-#include \"record.h\"\n-#include \"reftable-tests.h\"\n-#include \"test_framework.h\"\n+#include \"test-lib.h\"\n+#include \"reftable/constants.h\"\n+#include \"reftable/pq.h\"\n \n void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n {\n-\tint i;\n-\tfor (i = 1; i < pq.len; i++) {\n-\t\tint parent = (i - 1) / 2;\n-\n-\t\tEXPECT(pq_less(&pq.heap[parent], &pq.heap[i]));\n+\tfor (size_t i = 1; i < pq.len; i++) {\n+\t\tsize_t parent = (i - 1) / 2;\n+\t\tcheck(pq_less(&pq.heap[parent], &pq.heap[i]));\n \t}\n }\n \n-static void test_pq(void)\n+static void t_pq(void)\n {\n-\tstruct merged_iter_pqueue pq = { NULL };\n+\tstruct merged_iter_pqueue pq = { 0 };\n \tstruct reftable_record recs[54];\n-\tint N = ARRAY_SIZE(recs) - 1, i;\n+\tsize_t N = ARRAY_SIZE(recs) - 1, i;\n \tchar *last = NULL;\n \n \tfor (i = 0; i < N; i++) {\n \t\tstruct strbuf refname = STRBUF_INIT;\n-\t\tstrbuf_addf(&refname, \"%02d\", i);\n+\t\tstrbuf_addf(&refname, \"%02\"PRIuMAX, (uintmax_t)i);\n \n \t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n \t\trecs[i].u.ref.refname = strbuf_detach(&refname, NULL);\n@@ -48,7 +41,6 @@ static void test_pq(void)\n \n \t\tmerged_iter_pqueue_add(&pq, &e);\n \t\tmerged_iter_pqueue_check(pq);\n-\n \t\ti = (i * 7) % N;\n \t} while (i != 1);\n \n@@ -56,9 +48,9 @@ static void test_pq(void)\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n \t\tmerged_iter_pqueue_check(pq);\n \n-\t\tEXPECT(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n+\t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tif (last)\n-\t\t\tEXPECT(strcmp(last, e.rec->u.ref.refname) < 0);\n+\t\t\tcheck_int(strcmp(last, e.rec->u.ref.refname), <, 0);\n \t\tlast = e.rec->u.ref.refname;\n \t}\n \n@@ -67,8 +59,9 @@ static void test_pq(void)\n \tmerged_iter_pqueue_release(&pq);\n }\n \n-int pq_test_main(int argc, const char *argv[])\n+int cmd_main(int argc, const char *argv[])\n {\n-\tRUN_TEST(test_pq);\n-\treturn 0;\n+\tTEST(t_pq(), \"pq works\");\n+\n+\treturn test_done();\n }\n-- \n2.45.GIT\n\n"},{"id":"499831","messageId":"20240801110453.5087-5-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240801110453.5087-1-chandrapratap3519@gmail.com","subject":"[PATCH v7 4/7] t-reftable-pq: make merged_iter_pqueue_check() static","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-08-01T10:59:45Z","receivedAt":"2024-08-01T11:05:33Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"merged_iter_pqueue_check() is a function previously defined in\nreftable/pq_test.c (now t/unit-tests/t-reftable-pq.c) and used in\nthe testing of a priority queue as defined by reftable/pq.{c, h}.\nAs such, this function is only called by reftable/pq_test.c and it\nmakes little sense to expose it to non-testing code via reftable/pq.h.\n\nHence, make this function static and remove its prototype from\nreftable/pq.h.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n reftable/pq.h                | 1 -\n t/unit-tests/t-reftable-pq.c | 2 +-\n 2 files changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/reftable/pq.h b/reftable/pq.h\nindex f796c23179..707bd26767 100644\n--- a/reftable/pq.h\n+++ b/reftable/pq.h\n@@ -22,7 +22,6 @@ struct merged_iter_pqueue {\n \tsize_t cap;\n };\n \n-void merged_iter_pqueue_check(struct merged_iter_pqueue pq);\n struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq);\n void merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e);\n void merged_iter_pqueue_release(struct merged_iter_pqueue *pq);\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex a78aba9e71..220e82be19 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -10,7 +10,7 @@ license that can be found in the LICENSE file or at\n #include \"reftable/constants.h\"\n #include \"reftable/pq.h\"\n \n-void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n+static void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n {\n \tfor (size_t i = 1; i < pq.len; i++) {\n \t\tsize_t parent = (i - 1) / 2;\n-- \n2.45.GIT\n\n"},{"id":"499832","messageId":"20240801110453.5087-6-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240801110453.5087-1-chandrapratap3519@gmail.com","subject":"[PATCH v7 5/7] t-reftable-pq: make merged_iter_pqueue_check() callable by reference","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-08-01T10:59:46Z","receivedAt":"2024-08-01T11:05:35Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"merged_iter_pqueue_check() checks the validity of a priority queue\nrepresented by a merged_iter_pqueue struct by asserting the\nparent-child relation in the struct's heap. Explicity passing a\nstruct to this function means a copy of the entire struct is created,\nwhich is inefficient.\n\nMake the function accept a pointer to the struct instead. This is\nsafe to do since the function doesn't modify the struct in any way.\nMake the function parameter 'const' to assert immutability.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n t/unit-tests/t-reftable-pq.c | 10 +++++-----\n 1 file changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex 220e82be19..9230dd9b9e 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -10,11 +10,11 @@ license that can be found in the LICENSE file or at\n #include \"reftable/constants.h\"\n #include \"reftable/pq.h\"\n \n-static void merged_iter_pqueue_check(struct merged_iter_pqueue pq)\n+static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n {\n-\tfor (size_t i = 1; i < pq.len; i++) {\n+\tfor (size_t i = 1; i < pq->len; i++) {\n \t\tsize_t parent = (i - 1) / 2;\n-\t\tcheck(pq_less(&pq.heap[parent], &pq.heap[i]));\n+\t\tcheck(pq_less(&pq->heap[parent], &pq->heap[i]));\n \t}\n }\n \n@@ -40,13 +40,13 @@ static void t_pq(void)\n \t\t};\n \n \t\tmerged_iter_pqueue_add(&pq, &e);\n-\t\tmerged_iter_pqueue_check(pq);\n+\t\tmerged_iter_pqueue_check(&pq);\n \t\ti = (i * 7) % N;\n \t} while (i != 1);\n \n \twhile (!merged_iter_pqueue_is_empty(pq)) {\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n-\t\tmerged_iter_pqueue_check(pq);\n+\t\tmerged_iter_pqueue_check(&pq);\n \n \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tif (last)\n-- \n2.45.GIT\n\n"},{"id":"499833","messageId":"20240801110453.5087-7-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240801110453.5087-1-chandrapratap3519@gmail.com","subject":"[PATCH v7 6/7] t-reftable-pq: add test for index based comparison","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-08-01T10:59:47Z","receivedAt":"2024-08-01T11:05:39Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"When comparing two entries, the priority queue as defined by\nreftable/pq.{c, h} first compares the entries on the basis of\ntheir ref-record's keys. If the keys turn out to be equal, the\ncomparison is then made on the basis of their update indices\n(which are never equal).\n\nIn the current testing setup, only the case for comparison on\nthe basis of ref-record's keys is exercised. Add a test for\nindex-based comparison as well. Rename the existing test to\nreflect its nature of only testing record-based comparison.\n\nWhile at it, replace 'strbuf_detach' with 'xstrfmt' to assign\nrefnames in the existing test. This makes the test conciser.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n t/unit-tests/t-reftable-pq.c | 48 +++++++++++++++++++++++++++++++-----\n 1 file changed, 42 insertions(+), 6 deletions(-)\n\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex 9230dd9b9e..70ff89507d 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -18,7 +18,7 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n \t}\n }\n \n-static void t_pq(void)\n+static void t_pq_record(void)\n {\n \tstruct merged_iter_pqueue pq = { 0 };\n \tstruct reftable_record recs[54];\n@@ -26,11 +26,8 @@ static void t_pq(void)\n \tchar *last = NULL;\n \n \tfor (i = 0; i < N; i++) {\n-\t\tstruct strbuf refname = STRBUF_INIT;\n-\t\tstrbuf_addf(&refname, \"%02\"PRIuMAX, (uintmax_t)i);\n-\n \t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n-\t\trecs[i].u.ref.refname = strbuf_detach(&refname, NULL);\n+\t\trecs[i].u.ref.refname = xstrfmt(\"%02\"PRIuMAX, (uintmax_t)i);\n \t}\n \n \ti = 1;\n@@ -59,9 +56,48 @@ static void t_pq(void)\n \tmerged_iter_pqueue_release(&pq);\n }\n \n+static void t_pq_index(void)\n+{\n+\tstruct merged_iter_pqueue pq = { 0 };\n+\tstruct reftable_record recs[13];\n+\tchar *last = NULL;\n+\tsize_t N = ARRAY_SIZE(recs), i;\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n+\t\trecs[i].u.ref.refname = (char *) \"refs/heads/master\";\n+\t}\n+\n+\ti = 1;\n+\tdo {\n+\t\tstruct pq_entry e = {\n+\t\t\t.rec = &recs[i],\n+\t\t\t.index = i,\n+\t\t};\n+\n+\t\tmerged_iter_pqueue_add(&pq, &e);\n+\t\tmerged_iter_pqueue_check(&pq);\n+\t\ti = (i * 7) % N;\n+\t} while (i != 1);\n+\n+\tfor (i = N - 1; i > 0; i--) {\n+\t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n+\t\tmerged_iter_pqueue_check(&pq);\n+\n+\t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n+\t\tcheck_int(e.index, ==, i);\n+\t\tif (last)\n+\t\t\tcheck_str(last, e.rec->u.ref.refname);\n+\t\tlast = e.rec->u.ref.refname;\n+\t}\n+\n+\tmerged_iter_pqueue_release(&pq);\n+}\n+\n int cmd_main(int argc, const char *argv[])\n {\n-\tTEST(t_pq(), \"pq works\");\n+\tTEST(t_pq_record(), \"pq works with record-based comparison\");\n+\tTEST(t_pq_index(), \"pq works with index-based comparison\");\n \n \treturn test_done();\n }\n-- \n2.45.GIT\n\n"},{"id":"499834","messageId":"20240801110453.5087-8-chandrapratap3519@gmail.com","threadId":"61595","inReplyTo":"20240801110453.5087-1-chandrapratap3519@gmail.com","subject":"[PATCH v7 7/7] t-reftable-pq: add tests for merged_iter_pqueue_top()","fromName":"Chandra Pratap","fromEmail":"chandrapratap3519@gmail.com","sentAt":"2024-08-01T10:59:48Z","receivedAt":"2024-08-01T11:05:42Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"merged_iter_pqueue_top() as defined by reftable/pq.{c, h} returns\nthe element at the top of a priority-queue's heap without removing\nit. Since there are no tests for this function in the existing\nsetup, add tests for the same.\n\nMentored-by: Patrick Steinhardt <ps@pks.im>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n t/unit-tests/t-reftable-pq.c | 49 ++++++++++++++++++++++++++++++++++++\n 1 file changed, 49 insertions(+)\n\ndiff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c\nindex 70ff89507d..039bd0f1f9 100644\n--- a/t/unit-tests/t-reftable-pq.c\n+++ b/t/unit-tests/t-reftable-pq.c\n@@ -18,6 +18,11 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)\n \t}\n }\n \n+static int pq_entry_equal(struct pq_entry *a, struct pq_entry *b)\n+{\n+\treturn !reftable_record_cmp(a->rec, b->rec) && (a->index == b->index);\n+}\n+\n static void t_pq_record(void)\n {\n \tstruct merged_iter_pqueue pq = { 0 };\n@@ -42,9 +47,11 @@ static void t_pq_record(void)\n \t} while (i != 1);\n \n \twhile (!merged_iter_pqueue_is_empty(pq)) {\n+\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n \t\tmerged_iter_pqueue_check(&pq);\n \n+\t\tcheck(pq_entry_equal(&top, &e));\n \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tif (last)\n \t\t\tcheck_int(strcmp(last, e.rec->u.ref.refname), <, 0);\n@@ -81,9 +88,11 @@ static void t_pq_index(void)\n \t} while (i != 1);\n \n \tfor (i = N - 1; i > 0; i--) {\n+\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n \t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n \t\tmerged_iter_pqueue_check(&pq);\n \n+\t\tcheck(pq_entry_equal(&top, &e));\n \t\tcheck(reftable_record_type(e.rec) == BLOCK_TYPE_REF);\n \t\tcheck_int(e.index, ==, i);\n \t\tif (last)\n@@ -94,10 +103,50 @@ static void t_pq_index(void)\n \tmerged_iter_pqueue_release(&pq);\n }\n \n+static void t_merged_iter_pqueue_top(void)\n+{\n+\tstruct merged_iter_pqueue pq = { 0 };\n+\tstruct reftable_record recs[13];\n+\tsize_t N = ARRAY_SIZE(recs), i;\n+\n+\tfor (i = 0; i < N; i++) {\n+\t\treftable_record_init(&recs[i], BLOCK_TYPE_REF);\n+\t\trecs[i].u.ref.refname = (char *) \"refs/heads/master\";\n+\t}\n+\n+\ti = 1;\n+\tdo {\n+\t\tstruct pq_entry e = {\n+\t\t\t.rec = &recs[i],\n+\t\t\t.index = i,\n+\t\t};\n+\n+\t\tmerged_iter_pqueue_add(&pq, &e);\n+\t\tmerged_iter_pqueue_check(&pq);\n+\t\ti = (i * 7) % N;\n+\t} while (i != 1);\n+\n+\tfor (i = N - 1; i > 0; i--) {\n+\t\tstruct pq_entry top = merged_iter_pqueue_top(pq);\n+\t\tstruct pq_entry e = merged_iter_pqueue_remove(&pq);\n+\n+\t\tmerged_iter_pqueue_check(&pq);\n+\t\tcheck(pq_entry_equal(&top, &e));\n+\t\tcheck(reftable_record_equal(top.rec, &recs[i], GIT_SHA1_RAWSZ));\n+\t\tfor (size_t j = 0; i < pq.len; j++) {\n+\t\t\tcheck(pq_less(&top, &pq.heap[j]));\n+\t\t\tcheck_int(top.index, >, j);\n+\t\t}\n+\t}\n+\n+\tmerged_iter_pqueue_release(&pq);\n+}\n+\n int cmd_main(int argc, const char *argv[])\n {\n \tTEST(t_pq_record(), \"pq works with record-based comparison\");\n \tTEST(t_pq_index(), \"pq works with index-based comparison\");\n+\tTEST(t_merged_iter_pqueue_top(), \"merged_iter_pqueue_top works\");\n \n \treturn test_done();\n }\n-- \n2.45.GIT\n\n"},{"id":"499839","messageId":"Zqt02XmevPRB3idt@tanuki","threadId":"61595","inReplyTo":"20240801110453.5087-1-chandrapratap3519@gmail.com","subject":"Re: [GSoC][PATCH v7 0/7] t: port reftable/pq_test.c to the unit testing framework","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-08-01T11:43:21Z","receivedAt":"2024-08-01T11:43:27Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Aug 01, 2024 at 04:29:41PM +0530, Chandra Pratap wrote:\n> The reftable library comes with self tests, which are exercised\n> as part of the usual end-to-end tests and are designed to\n> observe the end-user visible effects of Git commands. What it\n> exercises, however, is a better match for the unit-testing\n> framework, merged at 8bf6fbd0 (Merge branch 'js/doc-unit-tests',\n> 2023-12-09), which is designed to observe how low level\n> implementation details, at the level of sequences of individual\n> function calls, behave.\n> \n> Hence, port reftable/pq_test.c to the unit testing framework and\n> improve upon the ported test. The first two patches in the series\n> are preparatory cleanup, the third patch moves the test to the unit\n> testing framework, and the rest of the patches improve upon the\n> ported test.\n> \n> Mentored-by: Patrick Steinhardt <ps@pks.im>\n> Mentored-by: Christian Couder <chriscool@tuxfamily.org>\n> Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n> \n> ---\n> Changes in v7:\n> - Fix a typo in patch 1\n> - Fix do-while style error in patch 6 and 7\n\nThe range-diff looks as expected to me, so the whole series LGTM now.\nThanks!\n\nPatrick\n"},{"id":"499871","messageId":"xmqq34noxm3n.fsf@gitster.g","threadId":"61595","inReplyTo":"Zqt02XmevPRB3idt@tanuki","subject":"Re: [GSoC][PATCH v7 0/7] t: port reftable/pq_test.c to the unit testing framework","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-08-01T16:07:56Z","receivedAt":"2024-08-01T16:08:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> ... the whole series LGTM now.\n> Thanks!\n\nThanks, both.\n"}]}