Trace and quote with argv: get rid of unneeded count argument.
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@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
Dec 3, 2007 at 05:51 UTC
b319ce4c14f7fe0ee469a3f9def1098d84177849
7 files changed
+12
-20
builtin-rev-parse.c
+1
-1
@@ -327,7 +327,7 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
327
keep_dashdash ? PARSE_OPT_KEEP_DASHDASH : 0);
328
329
strbuf_addf(&parsed, " --");
330
- sq_quote_argv(&parsed, argv, argc, 0);
330
+ sq_quote_argv(&parsed, argv, 0);
331
puts(parsed.buf);
332
return 0;
333
}
cache.h
+1
-1
@@ -620,7 +620,7 @@ extern void alloc_report(void);
620
621
/* trace.c */
622
extern void trace_printf(const char *format, ...);
623
-extern void trace_argv_printf(const char **argv, int count, const char *format, ...);
623
+extern void trace_argv_printf(const char **argv, const char *format, ...);
624
625
/* convert.c */
626
/* returns 1 if *dst was used */
exec_cmd.c
+1
-1
@@ -80,7 +80,7 @@ int execv_git_cmd(const char **argv)
80
tmp = argv[0];
81
argv[0] = cmd.buf;
82
83
- trace_argv_printf(argv, -1, "trace: exec:");
83
+ trace_argv_printf(argv, "trace: exec:");
84
85
/* execvp() can only ever return if it fails */
86
execvp(cmd.buf, (char **)argv);
git.c
+3
-3
@@ -169,7 +169,7 @@ static int handle_alias(int *argcp, const char ***argv)
169
170
strbuf_init(&buf, PATH_MAX);
171
strbuf_addstr(&buf, alias_string);
172
- sq_quote_argv(&buf, (*argv) + 1, *argcp - 1, PATH_MAX);
172
+ sq_quote_argv(&buf, (*argv) + 1, PATH_MAX);
173
free(alias_string);
174
alias_string = buf.buf;
175
}
@@ -198,7 +198,7 @@ static int handle_alias(int *argcp, const char ***argv)
198
if (!strcmp(alias_command, new_argv[0]))
199
die("recursive alias: %s", alias_command);
200
201
- trace_argv_printf(new_argv, count,
201
+ trace_argv_printf(new_argv,
202
"trace: alias expansion: %s =>",
203
alias_command);
204
@@ -252,7 +252,7 @@ static int run_command(struct cmd_struct *p, int argc, const char **argv)
252
if (p->option & NEED_WORK_TREE)
253
setup_work_tree();
254
255
- trace_argv_printf(argv, argc, "trace: built-in: git");
255
+ trace_argv_printf(argv, "trace: built-in: git");
256
257
status = p->fn(argc, argv, prefix);
258
if (status)
quote.c
+3
-10
@@ -56,20 +56,13 @@ void sq_quote_print(FILE *stream, const char *src)
56
fputc('\'', stream);
57
}
58
59
-void sq_quote_argv(struct strbuf *dst, const char** argv, int count,
60
- size_t maxlen)
59
+void sq_quote_argv(struct strbuf *dst, const char** argv, size_t maxlen)
60
{
61
int i;
62
64
- /* Count argv if needed. */
65
- if (count < 0) {
66
- for (count = 0; argv[count]; count++)
67
- ; /* just counting */
68
- }
69
-
63
/* Copy into destination buffer. */
71
- strbuf_grow(dst, 32 * count);
72
- for (i = 0; i < count; ++i) {
64
+ strbuf_grow(dst, 255);
65
+ for (i = 0; argv[i]; ++i) {
66
strbuf_addch(dst, ' ');
67
sq_quote_buf(dst, argv[i]);
68
if (maxlen && dst->len > maxlen)
quote.h
+1
-2
@@ -31,8 +31,7 @@
31
extern void sq_quote_print(FILE *stream, const char *src);
32
33
extern void sq_quote_buf(struct strbuf *, const char *src);
34
-extern void sq_quote_argv(struct strbuf *, const char **argv, int count,
35
- size_t maxlen);
34
+extern void sq_quote_argv(struct strbuf *, const char **argv, size_t maxlen);
35
36
/* This unwraps what sq_quote() produces in place, but returns
37
* NULL if the input does not look like what sq_quote would have
trace.c
+2
-2
@@ -93,7 +93,7 @@ void trace_printf(const char *fmt, ...)
93
close(fd);
94
}
95
96
-void trace_argv_printf(const char **argv, int count, const char *fmt, ...)
96
+void trace_argv_printf(const char **argv, const char *fmt, ...)
97
{
98
struct strbuf buf;
99
va_list ap;
@@ -117,7 +117,7 @@ void trace_argv_printf(const char **argv, int count, const char *fmt, ...)
117
}
118
strbuf_setlen(&buf, len);
119
120
- sq_quote_argv(&buf, argv, count, 0);
120
+ sq_quote_argv(&buf, argv, 0);
121
strbuf_addch(&buf, '\n');
122
write_or_whine_pipe(fd, buf.buf, buf.len, err_msg);
123
strbuf_release(&buf);