From mboxrd@z Thu Jan 1 00:00:00 1970 From: john at keeping.me.uk (John Keeping) Date: Sun, 7 Apr 2013 10:29:59 +0100 Subject: [PATCH 08/19] ui-log.c: use a strbuf for grep arguments In-Reply-To: References: Message-ID: <88f0b0c98e2d5c8df50a256d85d1beba1923c3dd.1365326321.git.john@keeping.me.uk> Signed-off-by: John Keeping --- ui-log.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ui-log.c b/ui-log.c index 7c3308c..44f6004 100644 --- a/ui-log.c +++ b/ui-log.c @@ -289,7 +289,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern struct vector vec = VECTOR_INIT(char *); int i, columns = commit_graph ? 4 : 3; int must_free_tip = 0; - char *arg; + struct strbuf argbuf = STRBUF_INIT; /* First argv is NULL */ vector_push(&vec, NULL, 0); @@ -303,10 +303,11 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern pattern = xstrdup(pattern); if (!strcmp(grep, "grep") || !strcmp(grep, "author") || !strcmp(grep, "committer")) { - arg = fmt("--%s=%s", grep, pattern); - vector_push(&vec, &arg, 0); + strbuf_addf(&argbuf, "--%s=%s", grep, pattern); + vector_push(&vec, &argbuf.buf, 0); } if (!strcmp(grep, "range")) { + char *arg; /* Split the pattern at whitespace and add each token * as a revision expression. Do not accept other * rev-list options. Also, replace the previously @@ -341,8 +342,8 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern } if (path) { - arg = "--"; - vector_push(&vec, &arg, 0); + static const char *double_dash_arg = "--"; + vector_push(&vec, &double_dash_arg, 0); vector_push(&vec, &path, 0); } @@ -438,4 +439,5 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern /* If we allocated tip then it is safe to cast away const. */ if (must_free_tip) free((char*) tip); + strbuf_release(&argbuf); } -- 1.8.2.692.g17a9715