git-compat-util.h: don't define _XOPEN_SOURCE on cygwin
[gitweb.git] / column.c
index 8d1ce88d1493cf18436b03f843c6d90190d47bb2..ca878bcea7a42476a7c2b03e74897a2af87bec3f 100644 (file)
--- a/column.c
+++ b/column.c
@@ -336,8 +336,9 @@ static int column_config(const char *var, const char *value,
 int git_column_config(const char *var, const char *value,
                      const char *command, unsigned int *colopts)
 {
-       const char *it = skip_prefix(var, "column.");
-       if (!it)
+       const char *it;
+
+       if (!skip_prefix(var, "column.", &it))
                return 0;
 
        if (!strcmp(it, "ui"))
@@ -370,46 +371,29 @@ static struct child_process column_process;
 
 int run_column_filter(int colopts, const struct column_options *opts)
 {
-       const char *av[10];
-       int ret, ac = 0;
-       struct strbuf sb_colopt  = STRBUF_INIT;
-       struct strbuf sb_width   = STRBUF_INIT;
-       struct strbuf sb_padding = STRBUF_INIT;
+       struct argv_array *argv;
 
        if (fd_out != -1)
                return -1;
 
-       av[ac++] = "column";
-       strbuf_addf(&sb_colopt, "--raw-mode=%d", colopts);
-       av[ac++] = sb_colopt.buf;
-       if (opts && opts->width) {
-               strbuf_addf(&sb_width, "--width=%d", opts->width);
-               av[ac++] = sb_width.buf;
-       }
-       if (opts && opts->indent) {
-               av[ac++] = "--indent";
-               av[ac++] = opts->indent;
-       }
-       if (opts && opts->padding) {
-               strbuf_addf(&sb_padding, "--padding=%d", opts->padding);
-               av[ac++] = sb_padding.buf;
-       }
-       av[ac] = NULL;
+       memset(&column_process, 0, sizeof(column_process));
+       argv = &column_process.args;
+
+       argv_array_push(argv, "column");
+       argv_array_pushf(argv, "--raw-mode=%d", colopts);
+       if (opts && opts->width)
+               argv_array_pushf(argv, "--width=%d", opts->width);
+       if (opts && opts->indent)
+               argv_array_pushf(argv, "--indent=%s", opts->indent);
+       if (opts && opts->padding)
+               argv_array_pushf(argv, "--padding=%d", opts->padding);
 
        fflush(stdout);
-       memset(&column_process, 0, sizeof(column_process));
        column_process.in = -1;
        column_process.out = dup(1);
        column_process.git_cmd = 1;
-       column_process.argv = av;
-
-       ret = start_command(&column_process);
-
-       strbuf_release(&sb_colopt);
-       strbuf_release(&sb_width);
-       strbuf_release(&sb_padding);
 
-       if (ret)
+       if (start_command(&column_process))
                return -2;
 
        fd_out = dup(1);