X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=wt-status.c;h=c3a9cab8980daa38e647a13eb2f0fcb42fbfbb8e;hb=f6576f4c0c6fa3b2d979faf28936c09480dedaab;hp=e7d42d0491743d577f84dc262ead721eb82c4785;hpb=bb293b831b9d0aade79c0acf5bf6091106e7d19b;p=git.git diff --git a/wt-status.c b/wt-status.c index e7d42d049..c3a9cab89 100644 --- a/wt-status.c +++ b/wt-status.c @@ -9,6 +9,7 @@ #include "diffcore.h" #include "quote.h" #include "run-command.h" +#include "remote.h" int wt_status_relative_paths = 1; int wt_status_use_color = -1; @@ -21,12 +22,6 @@ static char wt_status_colors[][COLOR_MAXLEN] = { "\033[31m", /* WT_STATUS_NOBRANCH: red */ }; -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) @@ -75,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, "#"); } @@ -96,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); @@ -165,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]); @@ -183,9 +188,8 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q, static void wt_status_print_initial(struct wt_status *s) { int i; - struct strbuf buf; + struct strbuf buf = STRBUF_INIT; - strbuf_init(&buf, 0); if (active_nr) { s->commitable = 1; wt_status_print_cached_header(s); @@ -261,9 +265,8 @@ 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) { @@ -274,24 +277,12 @@ static void wt_status_print_untracked(struct wt_status *s) read_directory(&dir, ".", "", 0, NULL); for(i = 0; i < dir.nr; i++) { - /* check for matching entry, which is unmerged; lifted from - * builtin-ls-files:show_other_files */ struct dir_entry *ent = dir.entries[i]; - int pos = cache_name_pos(ent->name, ent->len); - struct cache_entry *ce; - if (0 <= pos) - die("bug in wt_status_print_untracked"); - pos = -pos - 1; - if (pos < active_nr) { - ce = active_cache[pos]; - if (ce_namelen(ce) == ent->len && - !memcmp(ce->name, ent->name, ent->len)) - continue; - } + if (!cache_name_is_other(ent->name, ent->len)) + 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"); @@ -315,6 +306,25 @@ static void wt_status_print_verbose(struct wt_status *s) run_diff_index(&rev, 1); } +static void wt_status_print_tracking(struct wt_status *s) +{ + struct strbuf sb = STRBUF_INIT; + const char *cp, *ep; + struct branch *branch; + + assert(s->branch && !s->is_initial); + if (prefixcmp(s->branch, "refs/heads/")) + return; + branch = branch_get(s->branch + 11); + if (!format_tracking_info(branch, &sb)) + return; + + for (cp = sb.buf; (ep = strchr(cp, '\n')) != NULL; cp = ep + 1) + color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), + "# %.*s", (int)(ep - cp), cp); + color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#"); +} + void wt_status_print(struct wt_status *s) { unsigned char sha1[20]; @@ -333,6 +343,8 @@ void wt_status_print(struct wt_status *s) } 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) + wt_status_print_tracking(s); } if (s->is_initial) {