{"thread":{"id":"51603","subject":"[PATCH] test-dir-iterator: use path argument directly","startedAt":"2019-08-07T11:15:28Z","lastAt":"2019-08-07T13:57:05Z","messageCount":2,"participants":["René Scharfe","Derrick Stolee"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"380065","messageId":"7f428974-9218-fa7c-6f3c-3c0db30a7fec@web.de","threadId":"51603","inReplyTo":null,"subject":"[PATCH] test-dir-iterator: use path argument directly","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2019-08-07T11:15:20Z","receivedAt":"2019-08-07T11:15:28Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Avoid allocating and leaking a strbuf for holding a verbatim copy of the\npath argument and pass the latter directly to dir_iterator_begin()\ninstead.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\nThis test helper was added after v2.22.0 (2019-06-07) by 150791adbf\n(dir-iterator: add tests for dir-iterator API, 2019-07-10).\n\n t/helper/test-dir-iterator.c | 4 +---\n 1 file changed, 1 insertion(+), 3 deletions(-)\n\ndiff --git a/t/helper/test-dir-iterator.c b/t/helper/test-dir-iterator.c\nindex c7c30664da..659b6bfa81 100644\n--- a/t/helper/test-dir-iterator.c\n+++ b/t/helper/test-dir-iterator.c\n@@ -19,7 +19,6 @@ static const char *error_name(int error_number)\n  */\n int cmd__dir_iterator(int argc, const char **argv)\n {\n-\tstruct strbuf path = STRBUF_INIT;\n \tstruct dir_iterator *diter;\n \tunsigned int flags = 0;\n \tint iter_status;\n@@ -36,8 +35,7 @@ int cmd__dir_iterator(int argc, const char **argv)\n \tif (!*argv || argc != 1)\n \t\tdie(\"dir-iterator needs exactly one non-option argument\");\n\n-\tstrbuf_add(&path, *argv, strlen(*argv));\n-\tditer = dir_iterator_begin(path.buf, flags);\n+\tditer = dir_iterator_begin(*argv, flags);\n\n \tif (!diter) {\n \t\tprintf(\"dir_iterator_begin failure: %s\\n\", error_name(errno));\n--\n2.22.0\n"},{"id":"380075","messageId":"5d24c373-8e27-e166-3019-4812da68ebf9@gmail.com","threadId":"51603","inReplyTo":"7f428974-9218-fa7c-6f3c-3c0db30a7fec@web.de","subject":"Re: [PATCH] test-dir-iterator: use path argument directly","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2019-08-07T13:57:02Z","receivedAt":"2019-08-07T13:57:05Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 8/7/2019 7:15 AM, René Scharfe wrote:\n> Avoid allocating and leaking a strbuf for holding a verbatim copy of the\n> path argument and pass the latter directly to dir_iterator_begin()\n> instead.\n> \n> Signed-off-by: René Scharfe <l.s.r@web.de>\n> ---\n> This test helper was added after v2.22.0 (2019-06-07) by 150791adbf\n> (dir-iterator: add tests for dir-iterator API, 2019-07-10).\n> \n>  t/helper/test-dir-iterator.c | 4 +---\n>  1 file changed, 1 insertion(+), 3 deletions(-)\n> \n> diff --git a/t/helper/test-dir-iterator.c b/t/helper/test-dir-iterator.c\n> index c7c30664da..659b6bfa81 100644\n> --- a/t/helper/test-dir-iterator.c\n> +++ b/t/helper/test-dir-iterator.c\n> @@ -19,7 +19,6 @@ static const char *error_name(int error_number)\n>   */\n>  int cmd__dir_iterator(int argc, const char **argv)\n>  {\n> -\tstruct strbuf path = STRBUF_INIT;\n>  \tstruct dir_iterator *diter;\n>  \tunsigned int flags = 0;\n>  \tint iter_status;\n> @@ -36,8 +35,7 @@ int cmd__dir_iterator(int argc, const char **argv)\n>  \tif (!*argv || argc != 1)\n>  \t\tdie(\"dir-iterator needs exactly one non-option argument\");\n> \n> -\tstrbuf_add(&path, *argv, strlen(*argv));\n> -\tditer = dir_iterator_begin(path.buf, flags);\n> +\tditer = dir_iterator_begin(*argv, flags);\n\nLGTM. I had a minor brain fart regarding the type of *argv and how the\nconst plays in, but dir_iterator_begin takes a \"const char *\" so this\nis safe.\n\nThanks,\n-Stolee\n"}]}