[PATCH] Trace and quote with argv: get rid of unneeded count argument.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Now that str_buf takes care of all the allocations, there is
no more gain to pass an argument count.

So this patch removes the "count" argument from:
	- "sq_quote_argv"
	- "trace_argv_printf"
and all the callers.

Signed-off-by: Christian Couder <chriscool@xxxxxxxxxxxxx>
---
 builtin-rev-parse.c |    2 +-
 cache.h             |    2 +-
 exec_cmd.c          |    2 +-
 git.c               |    6 +++---
 quote.c             |   13 +++----------
 quote.h             |    3 +--
 trace.c             |    4 ++--
 7 files changed, 12 insertions(+), 20 deletions(-)

	I wrote to Junio:
	> Minor nit: now that the number of arguments is known, we could perhaps use 
	> the argument count instead of -1 in trace_argv_printf, so that it is not 
	> computed again in quote.c:sq_quote_argv, like this:
	>
	>trace_argv_printf(nargv, argc + 1, "trace: exec:");

	After looking at it a little more, I think it's better to get rid of the
	"count" argument altogether with a patch like this one.

diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index d1038a0..20d1789 100644
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
@@ -327,7 +327,7 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
 	                     keep_dashdash ? PARSE_OPT_KEEP_DASHDASH : 0);
 
 	strbuf_addf(&parsed, " --");
-	sq_quote_argv(&parsed, argv, argc, 0);
+	sq_quote_argv(&parsed, argv, 0);
 	puts(parsed.buf);
 	return 0;
 }
diff --git a/cache.h b/cache.h
index 4e59646..9f63199 100644
--- a/cache.h
+++ b/cache.h
@@ -617,7 +617,7 @@ extern void alloc_report(void);
 
 /* trace.c */
 extern void trace_printf(const char *format, ...);
-extern void trace_argv_printf(const char **argv, int count, const char *format, ...);
+extern void trace_argv_printf(const char **argv, const char *format, ...);
 
 /* convert.c */
 /* returns 1 if *dst was used */
diff --git a/exec_cmd.c b/exec_cmd.c
index 2d0a758..e189cac 100644
--- a/exec_cmd.c
+++ b/exec_cmd.c
@@ -80,7 +80,7 @@ int execv_git_cmd(const char **argv)
 	tmp = argv[0];
 	argv[0] = cmd.buf;
 
-	trace_argv_printf(argv, -1, "trace: exec:");
+	trace_argv_printf(argv, "trace: exec:");
 
 	/* execvp() can only ever return if it fails */
 	execvp(cmd.buf, (char **)argv);
diff --git a/git.c b/git.c
index f406c4b..c8b7e74 100644
--- a/git.c
+++ b/git.c
@@ -178,7 +178,7 @@ static int handle_alias(int *argcp, const char ***argv)
 
 				strbuf_init(&buf, PATH_MAX);
 				strbuf_addstr(&buf, alias_string);
-				sq_quote_argv(&buf, (*argv) + 1, *argcp - 1, PATH_MAX);
+				sq_quote_argv(&buf, (*argv) + 1, PATH_MAX);
 				free(alias_string);
 				alias_string = buf.buf;
 			}
@@ -207,7 +207,7 @@ static int handle_alias(int *argcp, const char ***argv)
 		if (!strcmp(alias_command, new_argv[0]))
 			die("recursive alias: %s", alias_command);
 
-		trace_argv_printf(new_argv, count,
+		trace_argv_printf(new_argv,
 				  "trace: alias expansion: %s =>",
 				  alias_command);
 
@@ -261,7 +261,7 @@ static int run_command(struct cmd_struct *p, int argc, const char **argv)
 	if (p->option & NEED_WORK_TREE)
 		setup_work_tree();
 
-	trace_argv_printf(argv, argc, "trace: built-in: git");
+	trace_argv_printf(argv, "trace: built-in: git");
 
 	status = p->fn(argc, argv, prefix);
 	if (status)
diff --git a/quote.c b/quote.c
index 0455783..6986b44 100644
--- a/quote.c
+++ b/quote.c
@@ -56,20 +56,13 @@ void sq_quote_print(FILE *stream, const char *src)
 	fputc('\'', stream);
 }
 
-void sq_quote_argv(struct strbuf *dst, const char** argv, int count,
-                   size_t maxlen)
+void sq_quote_argv(struct strbuf *dst, const char** argv, size_t maxlen)
 {
 	int i;
 
-	/* Count argv if needed. */
-	if (count < 0) {
-		for (count = 0; argv[count]; count++)
-			; /* just counting */
-	}
-
 	/* Copy into destination buffer. */
-	strbuf_grow(dst, 32 * count);
-	for (i = 0; i < count; ++i) {
+	strbuf_grow(dst, 255);
+	for (i = 0; argv[i]; ++i) {
 		strbuf_addch(dst, ' ');
 		sq_quote_buf(dst, argv[i]);
 		if (maxlen && dst->len > maxlen)
diff --git a/quote.h b/quote.h
index 4287990..ab7596f 100644
--- a/quote.h
+++ b/quote.h
@@ -31,8 +31,7 @@
 extern void sq_quote_print(FILE *stream, const char *src);
 
 extern void sq_quote_buf(struct strbuf *, const char *src);
-extern void sq_quote_argv(struct strbuf *, const char **argv, int count,
-                          size_t maxlen);
+extern void sq_quote_argv(struct strbuf *, const char **argv, size_t maxlen);
 
 /* This unwraps what sq_quote() produces in place, but returns
  * NULL if the input does not look like what sq_quote would have
diff --git a/trace.c b/trace.c
index d3d1b6d..4713f91 100644
--- a/trace.c
+++ b/trace.c
@@ -93,7 +93,7 @@ void trace_printf(const char *fmt, ...)
 		close(fd);
 }
 
-void trace_argv_printf(const char **argv, int count, const char *fmt, ...)
+void trace_argv_printf(const char **argv, const char *fmt, ...)
 {
 	struct strbuf buf;
 	va_list ap;
@@ -117,7 +117,7 @@ void trace_argv_printf(const char **argv, int count, const char *fmt, ...)
 	}
 	strbuf_setlen(&buf, len);
 
-	sq_quote_argv(&buf, argv, count, 0);
+	sq_quote_argv(&buf, argv, 0);
 	strbuf_addch(&buf, '\n');
 	write_or_whine_pipe(fd, buf.buf, buf.len, err_msg);
 	strbuf_release(&buf);
-- 
1.5.3.6.2115.gb9452-dirty

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux