]> asedeno.scripts.mit.edu Git - git.git/blobdiff - wt-status.c
graph API: don't print branch lines for uninteresting merge parents
[git.git] / wt-status.c
index 32d780af1e4f6e701f75d9759dfd4ebec56e6425..6e6516cd874a92376a672dcdc181aed6a3b5636c 100644 (file)
@@ -7,14 +7,18 @@
 #include "diff.h"
 #include "revision.h"
 #include "diffcore.h"
+#include "quote.h"
+#include "run-command.h"
 
 int wt_status_relative_paths = 1;
 int wt_status_use_color = -1;
+int wt_status_submodule_summary;
 static char wt_status_colors[][COLOR_MAXLEN] = {
        "",         /* WT_STATUS_HEADER: normal */
        "\033[32m", /* WT_STATUS_UPDATED: green */
        "\033[31m", /* WT_STATUS_CHANGED: red */
        "\033[31m", /* WT_STATUS_UNTRACKED: red */
+       "\033[31m", /* WT_STATUS_NOBRANCH: red */
 };
 
 static const char use_add_msg[] =
@@ -35,6 +39,8 @@ static int parse_status_slot(const char *var, int offset)
                return WT_STATUS_CHANGED;
        if (!strcasecmp(var+offset, "untracked"))
                return WT_STATUS_UNTRACKED;
+       if (!strcasecmp(var+offset, "nobranch"))
+               return WT_STATUS_NOBRANCH;
        die("bad config variable '%s'", var);
 }
 
@@ -82,51 +88,7 @@ static void wt_status_print_trailer(struct wt_status *s)
        color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#");
 }
 
-static char *quote_path(const char *in, int len,
-                       struct strbuf *out, const char *prefix)
-{
-       if (len < 0)
-               len = strlen(in);
-
-       strbuf_grow(out, len);
-       strbuf_setlen(out, 0);
-       if (prefix) {
-               int off = 0;
-               while (prefix[off] && off < len && prefix[off] == in[off])
-                       if (prefix[off] == '/') {
-                               prefix += off + 1;
-                               in += off + 1;
-                               len -= off + 1;
-                               off = 0;
-                       } else
-                               off++;
-
-               for (; *prefix; prefix++)
-                       if (*prefix == '/')
-                               strbuf_addstr(out, "../");
-       }
-
-       for ( ; len > 0; in++, len--) {
-               int ch = *in;
-
-               switch (ch) {
-               case '\n':
-                       strbuf_addstr(out, "\\n");
-                       break;
-               case '\r':
-                       strbuf_addstr(out, "\\r");
-                       break;
-               default:
-                       strbuf_addch(out, ch);
-                       continue;
-               }
-       }
-
-       if (!out->len)
-               strbuf_addstr(out, "./");
-
-       return out->buf;
-}
+#define quote_path quote_path_relative
 
 static void wt_status_print_filepair(struct wt_status *s,
                                     int t, struct diff_filepair *p)
@@ -247,7 +209,7 @@ static void wt_status_print_updated(struct wt_status *s)
        rev.diffopt.format_callback = wt_status_print_updated_cb;
        rev.diffopt.format_callback_data = s;
        rev.diffopt.detect_rename = 1;
-       rev.diffopt.rename_limit = 100;
+       rev.diffopt.rename_limit = 200;
        rev.diffopt.break_opt = 0;
        run_diff_index(&rev, 1);
 }
@@ -263,6 +225,36 @@ static void wt_status_print_changed(struct wt_status *s)
        run_diff_files(&rev, 0);
 }
 
+static void wt_status_print_submodule_summary(struct wt_status *s)
+{
+       struct child_process sm_summary;
+       char summary_limit[64];
+       char index[PATH_MAX];
+       const char *env[] = { index, NULL };
+       const char *argv[] = {
+               "submodule",
+               "summary",
+               "--cached",
+               "--for-status",
+               "--summary-limit",
+               summary_limit,
+               s->amend ? "HEAD^" : "HEAD",
+               NULL
+       };
+
+       sprintf(summary_limit, "%d", wt_status_submodule_summary);
+       snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", s->index_file);
+
+       memset(&sm_summary, 0, sizeof(sm_summary));
+       sm_summary.argv = argv;
+       sm_summary.env = env;
+       sm_summary.git_cmd = 1;
+       sm_summary.no_stdin = 1;
+       fflush(s->fp);
+       sm_summary.out = dup(fileno(s->fp));    /* run_command closes it */
+       run_command(&sm_summary);
+}
+
 static void wt_status_print_untracked(struct wt_status *s)
 {
        struct dir_struct dir;
@@ -312,34 +304,22 @@ static void wt_status_print_untracked(struct wt_status *s)
 static void wt_status_print_verbose(struct wt_status *s)
 {
        struct rev_info rev;
-       int saved_stdout;
-
-       fflush(s->fp);
-
-       /* Sigh, the entire diff machinery is hardcoded to output to
-        * stdout.  Do the dup-dance...*/
-       saved_stdout = dup(STDOUT_FILENO);
-       if (saved_stdout < 0 ||dup2(fileno(s->fp), STDOUT_FILENO) < 0)
-               die("couldn't redirect stdout\n");
 
        init_revisions(&rev, NULL);
        setup_revisions(0, NULL, &rev, s->reference);
        rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
        rev.diffopt.detect_rename = 1;
+       rev.diffopt.file = s->fp;
+       rev.diffopt.close_file = 0;
        run_diff_index(&rev, 1);
-
-       fflush(stdout);
-
-       if (dup2(saved_stdout, STDOUT_FILENO) < 0)
-               die("couldn't restore stdout\n");
-       close(saved_stdout);
 }
 
 void wt_status_print(struct wt_status *s)
 {
        unsigned char sha1[20];
-       s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
+       const char *branch_color = color(WT_STATUS_HEADER);
 
+       s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
        if (s->branch) {
                const char *on_what = "On branch ";
                const char *branch_name = s->branch;
@@ -347,10 +327,11 @@ void wt_status_print(struct wt_status *s)
                        branch_name += 11;
                else if (!strcmp(branch_name, "HEAD")) {
                        branch_name = "";
+                       branch_color = color(WT_STATUS_NOBRANCH);
                        on_what = "Not currently on any branch.";
                }
-               color_fprintf_ln(s->fp, color(WT_STATUS_HEADER),
-                       "# %s%s", on_what, branch_name);
+               color_fprintf(s->fp, color(WT_STATUS_HEADER), "# ");
+               color_fprintf_ln(s->fp, branch_color, "%s%s", on_what, branch_name);
        }
 
        if (s->is_initial) {
@@ -364,6 +345,8 @@ void wt_status_print(struct wt_status *s)
        }
 
        wt_status_print_changed(s);
+       if (wt_status_submodule_summary)
+               wt_status_print_submodule_summary(s);
        wt_status_print_untracked(s);
 
        if (s->verbose && !s->is_initial)
@@ -386,6 +369,13 @@ void wt_status_print(struct wt_status *s)
 
 int git_status_config(const char *k, const char *v)
 {
+       if (!strcmp(k, "status.submodulesummary")) {
+               int is_bool;
+               wt_status_submodule_summary = git_config_bool_or_int(k, v, &is_bool);
+               if (is_bool && wt_status_submodule_summary)
+                       wt_status_submodule_summary = -1;
+               return 0;
+       }
        if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
                wt_status_use_color = git_config_colorbool(k, v, -1);
                return 0;