[PATCH v2 11/22] ui-log.c: use a strbuf for grep arguments

John Keeping john at keeping.me.uk
Sun Apr 7 16:26:40 CEST 2013


Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-log.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/ui-log.c b/ui-log.c
index 606b67b..4a05b0f 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -290,7 +290,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);
@@ -304,10 +304,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
@@ -342,8 +343,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);
 	}
 
@@ -439,4 +440,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





More information about the CGit mailing list