Git 1.7.11
[gitweb.git] / wt-status.c
index 9ffc535f1ab0296fd0a3330b1f136d69f9ac9bb2..dd6d8c41068e6664cff1c07100e482e7ca9f0959 100644 (file)
@@ -11,6 +11,7 @@
 #include "remote.h"
 #include "refs.h"
 #include "submodule.h"
+#include "column.h"
 
 static char default_wt_status_colors[][COLOR_MAXLEN] = {
        GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
@@ -641,6 +642,8 @@ static void wt_status_print_other(struct wt_status *s,
 {
        int i;
        struct strbuf buf = STRBUF_INIT;
+       static struct string_list output = STRING_LIST_INIT_DUP;
+       struct column_options copts;
 
        if (!l->nr)
                return;
@@ -649,12 +652,33 @@ static void wt_status_print_other(struct wt_status *s,
 
        for (i = 0; i < l->nr; i++) {
                struct string_list_item *it;
+               const char *path;
                it = &(l->items[i]);
+               path = quote_path(it->string, strlen(it->string),
+                                 &buf, s->prefix);
+               if (column_active(s->colopts)) {
+                       string_list_append(&output, path);
+                       continue;
+               }
                status_printf(s, color(WT_STATUS_HEADER, s), "\t");
                status_printf_more(s, color(WT_STATUS_UNTRACKED, s),
-                       "%s\n", quote_path(it->string, strlen(it->string),
-                                           &buf, s->prefix));
+                                  "%s\n", path);
        }
+
+       strbuf_release(&buf);
+       if (!column_active(s->colopts))
+               return;
+
+       strbuf_addf(&buf, "%s#\t%s",
+                   color(WT_STATUS_HEADER, s),
+                   color(WT_STATUS_UNTRACKED, s));
+       memset(&copts, 0, sizeof(copts));
+       copts.padding = 1;
+       copts.indent = buf.buf;
+       if (want_color(s->use_color))
+               copts.nl = GIT_COLOR_RESET "\n";
+       print_columns(&output, s->colopts, &copts);
+       string_list_clear(&output, 0);
        strbuf_release(&buf);
 }
 
@@ -777,7 +801,7 @@ void wt_status_print(struct wt_status *s)
        }
 }
 
-static void wt_shortstatus_unmerged(int null_termination, struct string_list_item *it,
+static void wt_shortstatus_unmerged(struct string_list_item *it,
                           struct wt_status *s)
 {
        struct wt_status_change_data *d = it->util;
@@ -793,7 +817,7 @@ static void wt_shortstatus_unmerged(int null_termination, struct string_list_ite
        case 7: how = "UU"; break; /* both modified */
        }
        color_fprintf(s->fp, color(WT_STATUS_UNMERGED, s), "%s", how);
-       if (null_termination) {
+       if (s->null_termination) {
                fprintf(stdout, " %s%c", it->string, 0);
        } else {
                struct strbuf onebuf = STRBUF_INIT;
@@ -804,7 +828,7 @@ static void wt_shortstatus_unmerged(int null_termination, struct string_list_ite
        }
 }
 
-static void wt_shortstatus_status(int null_termination, struct string_list_item *it,
+static void wt_shortstatus_status(struct string_list_item *it,
                         struct wt_status *s)
 {
        struct wt_status_change_data *d = it->util;
@@ -818,7 +842,7 @@ static void wt_shortstatus_status(int null_termination, struct string_list_item
        else
                putchar(' ');
        putchar(' ');
-       if (null_termination) {
+       if (s->null_termination) {
                fprintf(stdout, "%s%c", it->string, 0);
                if (d->head_path)
                        fprintf(stdout, "%s%c", d->head_path, 0);
@@ -846,10 +870,10 @@ static void wt_shortstatus_status(int null_termination, struct string_list_item
        }
 }
 
-static void wt_shortstatus_other(int null_termination, struct string_list_item *it,
+static void wt_shortstatus_other(struct string_list_item *it,
                                 struct wt_status *s, const char *sign)
 {
-       if (null_termination) {
+       if (s->null_termination) {
                fprintf(stdout, "%s %s%c", sign, it->string, 0);
        } else {
                struct strbuf onebuf = STRBUF_INIT;
@@ -889,8 +913,8 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
        if (s->is_initial)
                color_fprintf(s->fp, header_color, _("Initial commit on "));
        if (!stat_tracking_info(branch, &num_ours, &num_theirs)) {
-               color_fprintf_ln(s->fp, branch_color_local,
-                       "%s", branch_name);
+               color_fprintf(s->fp, branch_color_local, "%s", branch_name);
+               fputc(s->null_termination ? '\0' : '\n', s->fp);
                return;
        }
 
@@ -914,14 +938,15 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
                color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);
        }
 
-       color_fprintf_ln(s->fp, header_color, "]");
+       color_fprintf(s->fp, header_color, "]");
+       fputc(s->null_termination ? '\0' : '\n', s->fp);
 }
 
-void wt_shortstatus_print(struct wt_status *s, int null_termination, int show_branch)
+void wt_shortstatus_print(struct wt_status *s)
 {
        int i;
 
-       if (show_branch)
+       if (s->show_branch)
                wt_shortstatus_print_tracking(s);
 
        for (i = 0; i < s->change.nr; i++) {
@@ -931,28 +956,28 @@ void wt_shortstatus_print(struct wt_status *s, int null_termination, int show_br
                it = &(s->change.items[i]);
                d = it->util;
                if (d->stagemask)
-                       wt_shortstatus_unmerged(null_termination, it, s);
+                       wt_shortstatus_unmerged(it, s);
                else
-                       wt_shortstatus_status(null_termination, it, s);
+                       wt_shortstatus_status(it, s);
        }
        for (i = 0; i < s->untracked.nr; i++) {
                struct string_list_item *it;
 
                it = &(s->untracked.items[i]);
-               wt_shortstatus_other(null_termination, it, s, "??");
+               wt_shortstatus_other(it, s, "??");
        }
        for (i = 0; i < s->ignored.nr; i++) {
                struct string_list_item *it;
 
                it = &(s->ignored.items[i]);
-               wt_shortstatus_other(null_termination, it, s, "!!");
+               wt_shortstatus_other(it, s, "!!");
        }
 }
 
-void wt_porcelain_print(struct wt_status *s, int null_termination)
+void wt_porcelain_print(struct wt_status *s)
 {
        s->use_color = 0;
        s->relative_paths = 0;
        s->prefix = NULL;
-       wt_shortstatus_print(s, null_termination, 0);
+       wt_shortstatus_print(s);
 }