X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=wt-status.c;h=96ff2f8f564b907b9ef77bd2ea41b5e854a13085;hb=2d893d6822458ea15ef74e2b8be563945a6296fc;hp=64cedfcbe14ab0448ab6225b50244a45492a546a;hpb=141201d124f3663a98e0f362c1af7f5f7b58dabb;p=git.git diff --git a/wt-status.c b/wt-status.c index 64cedfcbe..929b00f59 100644 --- a/wt-status.c +++ b/wt-status.c @@ -15,19 +15,13 @@ 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 */ + GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */ + GIT_COLOR_GREEN, /* WT_STATUS_UPDATED */ + GIT_COLOR_RED, /* WT_STATUS_CHANGED */ + GIT_COLOR_RED, /* WT_STATUS_UNTRACKED */ + GIT_COLOR_RED, /* WT_STATUS_NOBRANCH */ }; -static const char use_add_msg[] = -"use \"git add ...\" to update what will be committed"; -static const char use_add_rm_msg[] = -"use \"git add/rm ...\" to update what will be committed"; -static const char use_add_to_include_msg[] = -"use \"git add ...\" to include in what will be committed"; enum untracked_status_type show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES; static int parse_status_slot(const char *var, int offset) @@ -76,12 +70,24 @@ static void wt_status_print_cached_header(struct wt_status *s) color_fprintf_ln(s->fp, c, "#"); } -static void wt_status_print_header(struct wt_status *s, - const char *main, const char *sub) +static void wt_status_print_dirty_header(struct wt_status *s, + int has_deleted) { const char *c = color(WT_STATUS_HEADER); - color_fprintf_ln(s->fp, c, "# %s:", main); - color_fprintf_ln(s->fp, c, "# (%s)", sub); + color_fprintf_ln(s->fp, c, "# Changed but not updated:"); + if (!has_deleted) + color_fprintf_ln(s->fp, c, "# (use \"git add ...\" to update what will be committed)"); + else + color_fprintf_ln(s->fp, c, "# (use \"git add/rm ...\" to update what will be committed)"); + color_fprintf_ln(s->fp, c, "# (use \"git checkout -- ...\" to discard changes in working directory)"); + color_fprintf_ln(s->fp, c, "#"); +} + +static void wt_status_print_untracked_header(struct wt_status *s) +{ + const char *c = color(WT_STATUS_HEADER); + color_fprintf_ln(s->fp, c, "# Untracked files:"); + color_fprintf_ln(s->fp, c, "# (use \"git add ...\" to include in what will be committed)"); color_fprintf_ln(s->fp, c, "#"); } @@ -97,10 +103,8 @@ static void wt_status_print_filepair(struct wt_status *s, { const char *c = color(t); const char *one, *two; - struct strbuf onebuf, twobuf; + struct strbuf onebuf = STRBUF_INIT, twobuf = STRBUF_INIT; - strbuf_init(&onebuf, 0); - strbuf_init(&twobuf, 0); one = quote_path(p->one->path, -1, &onebuf, s->prefix); two = quote_path(p->two->path, -1, &twobuf, s->prefix); @@ -166,14 +170,14 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q, struct wt_status *s = data; int i; if (q->nr) { - const char *msg = use_add_msg; + int has_deleted = 0; s->workdir_dirty = 1; for (i = 0; i < q->nr; i++) if (q->queue[i]->status == DIFF_STATUS_DELETED) { - msg = use_add_rm_msg; + has_deleted = 1; break; } - wt_status_print_header(s, "Changed but not updated", msg); + wt_status_print_dirty_header(s, has_deleted); } for (i = 0; i < q->nr; i++) wt_status_print_filepair(s, WT_STATUS_CHANGED, q->queue[i]); @@ -181,32 +185,12 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q, wt_status_print_trailer(s); } -static void wt_status_print_initial(struct wt_status *s) -{ - int i; - struct strbuf buf; - - strbuf_init(&buf, 0); - if (active_nr) { - s->commitable = 1; - wt_status_print_cached_header(s); - } - for (i = 0; i < active_nr; i++) { - color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t"); - color_fprintf_ln(s->fp, color(WT_STATUS_UPDATED), "new file: %s", - quote_path(active_cache[i]->name, -1, - &buf, s->prefix)); - } - if (active_nr) - wt_status_print_trailer(s); - strbuf_release(&buf); -} - static void wt_status_print_updated(struct wt_status *s) { struct rev_info rev; init_revisions(&rev, NULL); - setup_revisions(0, NULL, &rev, s->reference); + setup_revisions(0, NULL, &rev, + s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference); rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK; rev.diffopt.format_callback = wt_status_print_updated_cb; rev.diffopt.format_callback_data = s; @@ -262,15 +246,13 @@ static void wt_status_print_untracked(struct wt_status *s) struct dir_struct dir; int i; int shown_header = 0; - struct strbuf buf; + struct strbuf buf = STRBUF_INIT; - strbuf_init(&buf, 0); memset(&dir, 0, sizeof(dir)); - if (!s->untracked) { - dir.show_other_directories = 1; - dir.hide_empty_directories = 1; - } + if (!s->untracked) + dir.flags |= + DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES; setup_standard_excludes(&dir); read_directory(&dir, ".", "", 0, NULL); @@ -280,8 +262,7 @@ static void wt_status_print_untracked(struct wt_status *s) continue; if (!shown_header) { s->workdir_untracked = 1; - wt_status_print_header(s, "Untracked files", - use_add_to_include_msg); + wt_status_print_untracked_header(s); shown_header = 1; } color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t"); @@ -297,11 +278,21 @@ static void wt_status_print_verbose(struct wt_status *s) struct rev_info rev; init_revisions(&rev, NULL); - setup_revisions(0, NULL, &rev, s->reference); + DIFF_OPT_SET(&rev.diffopt, ALLOW_TEXTCONV); + setup_revisions(0, NULL, &rev, + s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference); rev.diffopt.output_format |= DIFF_FORMAT_PATCH; rev.diffopt.detect_rename = 1; rev.diffopt.file = s->fp; rev.diffopt.close_file = 0; + /* + * If we're not going to stdout, then we definitely don't + * want color, since we are going to the commit message + * file (and even the "auto" setting won't work, since it + * will have checked isatty on stdout). + */ + if (s->fp != stdout) + DIFF_OPT_CLR(&rev.diffopt, COLOR_DIFF); run_diff_index(&rev, 1); } @@ -350,12 +341,9 @@ void wt_status_print(struct wt_status *s) color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#"); color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "# Initial commit"); color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#"); - wt_status_print_initial(s); - } - else { - wt_status_print_updated(s); } + wt_status_print_updated(s); wt_status_print_changed(s); if (wt_status_submodule_summary) wt_status_print_submodule_summary(s); @@ -364,7 +352,7 @@ void wt_status_print(struct wt_status *s) else if (s->commitable) fprintf(s->fp, "# Untracked files not listed (use -u option to show untracked files)\n"); - if (s->verbose && !s->is_initial) + if (s->verbose) wt_status_print_verbose(s); if (!s->commitable) { if (s->amend) @@ -421,5 +409,5 @@ int git_status_config(const char *k, const char *v, void *cb) return error("Invalid untracked files mode '%s'", v); return 0; } - return git_color_default_config(k, v, cb); + return git_diff_ui_config(k, v, cb); }