{"thread":{"id":"11109","subject":"[PATCH] Trace and quote with argv: get rid of unneeded count argument.","startedAt":"2007-12-03T04:51:50Z","lastAt":"2007-12-03T04:51:50Z","messageCount":1,"participants":["Christian Couder"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"61722","messageId":"20071203055150.b8d222f8.chriscool@tuxfamily.org","threadId":"11109","inReplyTo":null,"subject":"[PATCH] Trace and quote with argv: get rid of unneeded count argument.","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2007-12-03T04:51:50Z","receivedAt":"2007-12-03T04:51:50Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Now that str_buf takes care of all the allocations, there is\nno more gain to pass an argument count.\n\nSo this patch removes the \"count\" argument from:\n\t- \"sq_quote_argv\"\n\t- \"trace_argv_printf\"\nand all the callers.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n builtin-rev-parse.c |    2 +-\n cache.h             |    2 +-\n exec_cmd.c          |    2 +-\n git.c               |    6 +++---\n quote.c             |   13 +++----------\n quote.h             |    3 +--\n trace.c             |    4 ++--\n 7 files changed, 12 insertions(+), 20 deletions(-)\n\n\tI wrote to Junio:\n\t> Minor nit: now that the number of arguments is known, we could perhaps use \n\t> the argument count instead of -1 in trace_argv_printf, so that it is not \n\t> computed again in quote.c:sq_quote_argv, like this:\n\t>\n\t>trace_argv_printf(nargv, argc + 1, \"trace: exec:\");\n\n\tAfter looking at it a little more, I think it's better to get rid of the\n\t\"count\" argument altogether with a patch like this one.\n\ndiff --git a/builtin-rev-parse.c b/builtin-rev-parse.c\nindex d1038a0..20d1789 100644\n--- a/builtin-rev-parse.c\n+++ b/builtin-rev-parse.c\n@@ -327,7 +327,7 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)\n \t                     keep_dashdash ? PARSE_OPT_KEEP_DASHDASH : 0);\n \n \tstrbuf_addf(&parsed, \" --\");\n-\tsq_quote_argv(&parsed, argv, argc, 0);\n+\tsq_quote_argv(&parsed, argv, 0);\n \tputs(parsed.buf);\n \treturn 0;\n }\ndiff --git a/cache.h b/cache.h\nindex 4e59646..9f63199 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -617,7 +617,7 @@ extern void alloc_report(void);\n \n /* trace.c */\n extern void trace_printf(const char *format, ...);\n-extern void trace_argv_printf(const char **argv, int count, const char *format, ...);\n+extern void trace_argv_printf(const char **argv, const char *format, ...);\n \n /* convert.c */\n /* returns 1 if *dst was used */\ndiff --git a/exec_cmd.c b/exec_cmd.c\nindex 2d0a758..e189cac 100644\n--- a/exec_cmd.c\n+++ b/exec_cmd.c\n@@ -80,7 +80,7 @@ int execv_git_cmd(const char **argv)\n \ttmp = argv[0];\n \targv[0] = cmd.buf;\n \n-\ttrace_argv_printf(argv, -1, \"trace: exec:\");\n+\ttrace_argv_printf(argv, \"trace: exec:\");\n \n \t/* execvp() can only ever return if it fails */\n \texecvp(cmd.buf, (char **)argv);\ndiff --git a/git.c b/git.c\nindex f406c4b..c8b7e74 100644\n--- a/git.c\n+++ b/git.c\n@@ -178,7 +178,7 @@ static int handle_alias(int *argcp, const char ***argv)\n \n \t\t\t\tstrbuf_init(&buf, PATH_MAX);\n \t\t\t\tstrbuf_addstr(&buf, alias_string);\n-\t\t\t\tsq_quote_argv(&buf, (*argv) + 1, *argcp - 1, PATH_MAX);\n+\t\t\t\tsq_quote_argv(&buf, (*argv) + 1, PATH_MAX);\n \t\t\t\tfree(alias_string);\n \t\t\t\talias_string = buf.buf;\n \t\t\t}\n@@ -207,7 +207,7 @@ static int handle_alias(int *argcp, const char ***argv)\n \t\tif (!strcmp(alias_command, new_argv[0]))\n \t\t\tdie(\"recursive alias: %s\", alias_command);\n \n-\t\ttrace_argv_printf(new_argv, count,\n+\t\ttrace_argv_printf(new_argv,\n \t\t\t\t  \"trace: alias expansion: %s =>\",\n \t\t\t\t  alias_command);\n \n@@ -261,7 +261,7 @@ static int run_command(struct cmd_struct *p, int argc, const char **argv)\n \tif (p->option & NEED_WORK_TREE)\n \t\tsetup_work_tree();\n \n-\ttrace_argv_printf(argv, argc, \"trace: built-in: git\");\n+\ttrace_argv_printf(argv, \"trace: built-in: git\");\n \n \tstatus = p->fn(argc, argv, prefix);\n \tif (status)\ndiff --git a/quote.c b/quote.c\nindex 0455783..6986b44 100644\n--- a/quote.c\n+++ b/quote.c\n@@ -56,20 +56,13 @@ void sq_quote_print(FILE *stream, const char *src)\n \tfputc('\\'', stream);\n }\n \n-void sq_quote_argv(struct strbuf *dst, const char** argv, int count,\n-                   size_t maxlen)\n+void sq_quote_argv(struct strbuf *dst, const char** argv, size_t maxlen)\n {\n \tint i;\n \n-\t/* Count argv if needed. */\n-\tif (count < 0) {\n-\t\tfor (count = 0; argv[count]; count++)\n-\t\t\t; /* just counting */\n-\t}\n-\n \t/* Copy into destination buffer. */\n-\tstrbuf_grow(dst, 32 * count);\n-\tfor (i = 0; i < count; ++i) {\n+\tstrbuf_grow(dst, 255);\n+\tfor (i = 0; argv[i]; ++i) {\n \t\tstrbuf_addch(dst, ' ');\n \t\tsq_quote_buf(dst, argv[i]);\n \t\tif (maxlen && dst->len > maxlen)\ndiff --git a/quote.h b/quote.h\nindex 4287990..ab7596f 100644\n--- a/quote.h\n+++ b/quote.h\n@@ -31,8 +31,7 @@\n extern void sq_quote_print(FILE *stream, const char *src);\n \n extern void sq_quote_buf(struct strbuf *, const char *src);\n-extern void sq_quote_argv(struct strbuf *, const char **argv, int count,\n-                          size_t maxlen);\n+extern void sq_quote_argv(struct strbuf *, const char **argv, size_t maxlen);\n \n /* This unwraps what sq_quote() produces in place, but returns\n  * NULL if the input does not look like what sq_quote would have\ndiff --git a/trace.c b/trace.c\nindex d3d1b6d..4713f91 100644\n--- a/trace.c\n+++ b/trace.c\n@@ -93,7 +93,7 @@ void trace_printf(const char *fmt, ...)\n \t\tclose(fd);\n }\n \n-void trace_argv_printf(const char **argv, int count, const char *fmt, ...)\n+void trace_argv_printf(const char **argv, const char *fmt, ...)\n {\n \tstruct strbuf buf;\n \tva_list ap;\n@@ -117,7 +117,7 @@ void trace_argv_printf(const char **argv, int count, const char *fmt, ...)\n \t}\n \tstrbuf_setlen(&buf, len);\n \n-\tsq_quote_argv(&buf, argv, count, 0);\n+\tsq_quote_argv(&buf, argv, 0);\n \tstrbuf_addch(&buf, '\\n');\n \twrite_or_whine_pipe(fd, buf.buf, buf.len, err_msg);\n \tstrbuf_release(&buf);\n-- \n1.5.3.6.2115.gb9452-dirty\n"}]}