From 50b7e70f338e54f3534ee1b14c3bdb4c80d0dcf7 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 4 Aug 2009 23:49:33 -0700 Subject: wt-status.c: rework the way changes to the index and work tree are summarized Introduce a new infrastructure to find and summarize changes in a single string list, and rewrite wt_status_print_{updated,changed} functions using it. The goal of this change is to give more information on conflicted paths in the status output. Signed-off-by: Junio C Hamano --- wt-status.c | 226 ++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 181 insertions(+), 45 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 47735d8129..9aab567753 100644 --- a/wt-status.c +++ b/wt-status.c @@ -56,6 +56,7 @@ void wt_status_prepare(struct wt_status *s) s->reference = "HEAD"; s->fp = stdout; s->index_file = get_index_file(); + s->change.strdup_strings = 1; } static void wt_status_print_cached_header(struct wt_status *s) @@ -98,18 +99,35 @@ static void wt_status_print_trailer(struct wt_status *s) #define quote_path quote_path_relative -static void wt_status_print_filepair(struct wt_status *s, - int t, struct diff_filepair *p) +static void wt_status_print_change_data(struct wt_status *s, + int change_type, + struct string_list_item *it) { - const char *c = color(t); + struct wt_status_change_data *d = it->util; + const char *c = color(change_type); + int status = status; + char *one_name; + char *two_name; const char *one, *two; struct strbuf onebuf = STRBUF_INIT, twobuf = STRBUF_INIT; - one = quote_path(p->one->path, -1, &onebuf, s->prefix); - two = quote_path(p->two->path, -1, &twobuf, s->prefix); + one_name = two_name = it->string; + switch (change_type) { + case WT_STATUS_UPDATED: + status = d->index_status; + if (d->head_path) + one_name = d->head_path; + break; + case WT_STATUS_CHANGED: + status = d->worktree_status; + break; + } + + one = quote_path(one_name, -1, &onebuf, s->prefix); + two = quote_path(two_name, -1, &twobuf, s->prefix); color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t"); - switch (p->status) { + switch (status) { case DIFF_STATUS_ADDED: color_fprintf(s->fp, c, "new file: %s", one); break; @@ -135,64 +153,91 @@ static void wt_status_print_filepair(struct wt_status *s, color_fprintf(s->fp, c, "unmerged: %s", one); break; default: - die("bug: unhandled diff status %c", p->status); + die("bug: unhandled diff status %c", status); } fprintf(s->fp, "\n"); strbuf_release(&onebuf); strbuf_release(&twobuf); } -static void wt_status_print_updated_cb(struct diff_queue_struct *q, - struct diff_options *options, - void *data) +static void wt_status_collect_changed_cb(struct diff_queue_struct *q, + struct diff_options *options, + void *data) { struct wt_status *s = data; - int shown_header = 0; int i; + + if (!q->nr) + return; + s->workdir_dirty = 1; for (i = 0; i < q->nr; i++) { - if (q->queue[i]->status == 'U') - continue; - if (!shown_header) { - wt_status_print_cached_header(s); - s->commitable = 1; - shown_header = 1; + struct diff_filepair *p; + struct string_list_item *it; + struct wt_status_change_data *d; + + p = q->queue[i]; + it = string_list_insert(p->one->path, &s->change); + d = it->util; + if (!d) { + d = xcalloc(1, sizeof(*d)); + it->util = d; } - wt_status_print_filepair(s, WT_STATUS_UPDATED, q->queue[i]); + if (!d->worktree_status) + d->worktree_status = p->status; } - if (shown_header) - wt_status_print_trailer(s); } -static void wt_status_print_changed_cb(struct diff_queue_struct *q, - struct diff_options *options, - void *data) +static void wt_status_collect_updated_cb(struct diff_queue_struct *q, + struct diff_options *options, + void *data) { struct wt_status *s = data; int i; - if (q->nr) { - int has_deleted = 0; - s->workdir_dirty = 1; - for (i = 0; i < q->nr; i++) - if (q->queue[i]->status == DIFF_STATUS_DELETED) { - has_deleted = 1; - break; - } - wt_status_print_dirty_header(s, has_deleted); + + for (i = 0; i < q->nr; i++) { + struct diff_filepair *p; + struct string_list_item *it; + struct wt_status_change_data *d; + + p = q->queue[i]; + it = string_list_insert(p->two->path, &s->change); + d = it->util; + if (!d) { + d = xcalloc(1, sizeof(*d)); + it->util = d; + } + if (!d->index_status) + d->index_status = p->status; + switch (p->status) { + case DIFF_STATUS_COPIED: + case DIFF_STATUS_RENAMED: + d->head_path = xstrdup(p->one->path); + break; + } } - for (i = 0; i < q->nr; i++) - wt_status_print_filepair(s, WT_STATUS_CHANGED, q->queue[i]); - if (q->nr) - wt_status_print_trailer(s); } -static void wt_status_print_updated(struct wt_status *s) +static void wt_status_collect_changes_worktree(struct wt_status *s) { struct rev_info rev; + + init_revisions(&rev, NULL); + setup_revisions(0, NULL, &rev, NULL); + rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK; + rev.diffopt.format_callback = wt_status_collect_changed_cb; + rev.diffopt.format_callback_data = s; + run_diff_files(&rev, 0); +} + +static void wt_status_collect_changes_index(struct wt_status *s) +{ + struct rev_info rev; + init_revisions(&rev, NULL); 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 = wt_status_collect_updated_cb; rev.diffopt.format_callback_data = s; rev.diffopt.detect_rename = 1; rev.diffopt.rename_limit = 200; @@ -200,15 +245,104 @@ static void wt_status_print_updated(struct wt_status *s) run_diff_index(&rev, 1); } +static void wt_status_collect_changes_initial(struct wt_status *s) +{ + int i; + + for (i = 0; i < active_nr; i++) { + struct string_list_item *it; + struct wt_status_change_data *d; + struct cache_entry *ce = active_cache[i]; + + it = string_list_insert(ce->name, &s->change); + d = it->util; + if (!d) { + d = xcalloc(1, sizeof(*d)); + it->util = d; + } + if (ce_stage(ce)) + d->index_status = DIFF_STATUS_UNMERGED; + else + d->index_status = DIFF_STATUS_ADDED; + } +} + +void wt_status_collect_changes(struct wt_status *s) +{ + wt_status_collect_changes_worktree(s); + + if (s->is_initial) + wt_status_collect_changes_initial(s); + else + wt_status_collect_changes_index(s); +} + +static void wt_status_print_updated(struct wt_status *s) +{ + int shown_header = 0; + int i; + + for (i = 0; i < s->change.nr; i++) { + struct wt_status_change_data *d; + struct string_list_item *it; + it = &(s->change.items[i]); + d = it->util; + if (!d->index_status || + d->index_status == DIFF_STATUS_UNMERGED) + continue; + if (!shown_header) { + wt_status_print_cached_header(s); + s->commitable = 1; + shown_header = 1; + } + wt_status_print_change_data(s, WT_STATUS_UPDATED, it); + } + if (shown_header) + wt_status_print_trailer(s); +} + +/* + * -1 : has delete + * 0 : no change + * 1 : some change but no delete + */ +static int wt_status_check_worktree_changes(struct wt_status *s) +{ + int i; + int changes = 0; + + for (i = 0; i < s->change.nr; i++) { + struct wt_status_change_data *d; + d = s->change.items[i].util; + if (!d->worktree_status) + continue; + changes = 1; + if (d->worktree_status == DIFF_STATUS_DELETED) + return -1; + } + return changes; +} + static void wt_status_print_changed(struct wt_status *s) { - struct rev_info rev; - init_revisions(&rev, ""); - setup_revisions(0, NULL, &rev, NULL); - rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK; - rev.diffopt.format_callback = wt_status_print_changed_cb; - rev.diffopt.format_callback_data = s; - run_diff_files(&rev, 0); + int i; + int worktree_changes = wt_status_check_worktree_changes(s); + + if (!worktree_changes) + return; + + wt_status_print_dirty_header(s, worktree_changes < 0); + + for (i = 0; i < s->change.nr; i++) { + struct wt_status_change_data *d; + struct string_list_item *it; + it = &(s->change.items[i]); + d = it->util; + if (!d->worktree_status) + continue; + wt_status_print_change_data(s, WT_STATUS_CHANGED, it); + } + wt_status_print_trailer(s); } static void wt_status_print_submodule_summary(struct wt_status *s) @@ -337,6 +471,8 @@ void wt_status_print(struct wt_status *s) wt_status_print_tracking(s); } + wt_status_collect_changes(s); + if (s->is_initial) { color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#"); color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "# Initial commit"); -- cgit v1.2.1 From 4d4d5726aee31522e90df21ef62ee3377c5d8f8d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 5 Aug 2009 00:04:51 -0700 Subject: status: show worktree status of conflicted paths separately When a path is unmerged in the index, we used to always say "unmerged" in the "Changed but not updated" section, even when the path was deleted in the work tree. Remove unmerged entries from the "Updated" section, and create a new section "Unmerged paths". Describe how the different stages conflict in more detail in this new section. Note that with the current 3-way merge policy (with or without recursive), certain combinations of index stages should never happen. For example, having only stage #2 means that a path that did not exist in the common ancestor was added by us while the other branch did not do anything to it, which would have autoresolved to take our addition. The code nevertheless prepares for the possibility that future merge policies may leave a path in such a state. Signed-off-by: Junio C Hamano --- wt-status.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 3 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 9aab567753..97fedfaa19 100644 --- a/wt-status.c +++ b/wt-status.c @@ -20,6 +20,7 @@ static char wt_status_colors[][COLOR_MAXLEN] = { GIT_COLOR_RED, /* WT_STATUS_CHANGED */ GIT_COLOR_RED, /* WT_STATUS_UNTRACKED */ GIT_COLOR_RED, /* WT_STATUS_NOBRANCH */ + GIT_COLOR_RED, /* WT_STATUS_UNMERGED */ }; enum untracked_status_type show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES; @@ -37,6 +38,8 @@ static int parse_status_slot(const char *var, int offset) return WT_STATUS_UNTRACKED; if (!strcasecmp(var+offset, "nobranch")) return WT_STATUS_NOBRANCH; + if (!strcasecmp(var+offset, "unmerged")) + return WT_STATUS_UNMERGED; die("bad config variable '%s'", var); } @@ -59,6 +62,18 @@ void wt_status_prepare(struct wt_status *s) s->change.strdup_strings = 1; } +static void wt_status_print_unmerged_header(struct wt_status *s) +{ + const char *c = color(WT_STATUS_HEADER); + color_fprintf_ln(s->fp, c, "# Unmerged paths:"); + if (!s->is_initial) + color_fprintf_ln(s->fp, c, "# (use \"git reset %s ...\" to unstage)", s->reference); + else + color_fprintf_ln(s->fp, c, "# (use \"git rm --cached ...\" to unstage)"); + color_fprintf_ln(s->fp, c, "# (use \"git add ...\" to mark resolution)"); + color_fprintf_ln(s->fp, c, "#"); +} + static void wt_status_print_cached_header(struct wt_status *s) { const char *c = color(WT_STATUS_HEADER); @@ -99,6 +114,29 @@ static void wt_status_print_trailer(struct wt_status *s) #define quote_path quote_path_relative +static void wt_status_print_unmerged_data(struct wt_status *s, + struct string_list_item *it) +{ + const char *c = color(WT_STATUS_UNMERGED); + struct wt_status_change_data *d = it->util; + struct strbuf onebuf = STRBUF_INIT; + const char *one, *how = "bug"; + + one = quote_path(it->string, -1, &onebuf, s->prefix); + color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t"); + switch (d->stagemask) { + case 1: how = "both deleted:"; break; + case 2: how = "added by us:"; break; + case 3: how = "deleted by them:"; break; + case 4: how = "added by them:"; break; + case 5: how = "deleted by us:"; break; + case 6: how = "both added:"; break; + case 7: how = "both modified:"; break; + } + color_fprintf(s->fp, c, "%-20s%s\n", how, one); + strbuf_release(&onebuf); +} + static void wt_status_print_change_data(struct wt_status *s, int change_type, struct string_list_item *it) @@ -187,6 +225,26 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q, } } +static int unmerged_mask(const char *path) +{ + int pos, mask; + struct cache_entry *ce; + + pos = cache_name_pos(path, strlen(path)); + if (0 <= pos) + return 0; + + mask = 0; + pos = -pos-1; + while (pos < active_nr) { + ce = active_cache[pos++]; + if (strcmp(ce->name, path) || !ce_stage(ce)) + break; + mask |= (1 << (ce_stage(ce) - 1)); + } + return mask; +} + static void wt_status_collect_updated_cb(struct diff_queue_struct *q, struct diff_options *options, void *data) @@ -213,6 +271,9 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q, case DIFF_STATUS_RENAMED: d->head_path = xstrdup(p->one->path); break; + case DIFF_STATUS_UNMERGED: + d->stagemask = unmerged_mask(p->two->path); + break; } } } @@ -260,8 +321,10 @@ static void wt_status_collect_changes_initial(struct wt_status *s) d = xcalloc(1, sizeof(*d)); it->util = d; } - if (ce_stage(ce)) + if (ce_stage(ce)) { d->index_status = DIFF_STATUS_UNMERGED; + d->stagemask |= (1 << (ce_stage(ce) - 1)); + } else d->index_status = DIFF_STATUS_ADDED; } @@ -277,6 +340,29 @@ void wt_status_collect_changes(struct wt_status *s) wt_status_collect_changes_index(s); } +static void wt_status_print_unmerged(struct wt_status *s) +{ + int shown_header = 0; + int i; + + for (i = 0; i < s->change.nr; i++) { + struct wt_status_change_data *d; + struct string_list_item *it; + it = &(s->change.items[i]); + d = it->util; + if (!d->stagemask) + continue; + if (!shown_header) { + wt_status_print_unmerged_header(s); + shown_header = 1; + } + wt_status_print_unmerged_data(s, it); + } + if (shown_header) + wt_status_print_trailer(s); + +} + static void wt_status_print_updated(struct wt_status *s) { int shown_header = 0; @@ -314,7 +400,8 @@ static int wt_status_check_worktree_changes(struct wt_status *s) for (i = 0; i < s->change.nr; i++) { struct wt_status_change_data *d; d = s->change.items[i].util; - if (!d->worktree_status) + if (!d->worktree_status || + d->worktree_status == DIFF_STATUS_UNMERGED) continue; changes = 1; if (d->worktree_status == DIFF_STATUS_DELETED) @@ -338,7 +425,8 @@ static void wt_status_print_changed(struct wt_status *s) struct string_list_item *it; it = &(s->change.items[i]); d = it->util; - if (!d->worktree_status) + if (!d->worktree_status || + d->worktree_status == DIFF_STATUS_UNMERGED) continue; wt_status_print_change_data(s, WT_STATUS_CHANGED, it); } @@ -479,6 +567,7 @@ void wt_status_print(struct wt_status *s) color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#"); } + wt_status_print_unmerged(s); wt_status_print_updated(s); wt_status_print_changed(s); if (wt_status_submodule_summary) -- cgit v1.2.1 From d249b098893809c6de6e5e20063a22ac2c629ce7 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 9 Aug 2009 21:59:30 -0700 Subject: wt-status: move many global settings to wt_status structure Turn four global variables (wt_status_use_color, show_tracked_files, wt_status_relative_paths, and wt_status_submodule_summary) into fields of wt_status structure. They can also lose "wt_status_" prefix. Get rid of "untracked" field that was used only to keep track of otherwise available information redundantly. Signed-off-by: Junio C Hamano --- wt-status.c | 81 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 40 insertions(+), 41 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 97fedfaa19..af93bb52db 100644 --- a/wt-status.c +++ b/wt-status.c @@ -11,9 +11,6 @@ #include "run-command.h" #include "remote.h" -int wt_status_relative_paths = 1; -int wt_status_use_color = -1; -static int wt_status_submodule_summary; static char wt_status_colors[][COLOR_MAXLEN] = { GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */ GIT_COLOR_GREEN, /* WT_STATUS_UPDATED */ @@ -23,8 +20,6 @@ static char wt_status_colors[][COLOR_MAXLEN] = { GIT_COLOR_RED, /* WT_STATUS_UNMERGED */ }; -enum untracked_status_type show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES; - static int parse_status_slot(const char *var, int offset) { if (!strcasecmp(var+offset, "header")) @@ -43,9 +38,9 @@ static int parse_status_slot(const char *var, int offset) die("bad config variable '%s'", var); } -static const char *color(int slot) +static const char *color(int slot, struct wt_status *s) { - return wt_status_use_color > 0 ? wt_status_colors[slot] : ""; + return s->use_color > 0 ? wt_status_colors[slot] : ""; } void wt_status_prepare(struct wt_status *s) @@ -54,6 +49,9 @@ void wt_status_prepare(struct wt_status *s) const char *head; memset(s, 0, sizeof(*s)); + s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES; + s->use_color = -1; + s->relative_paths = 1; head = resolve_ref("HEAD", sha1, 0, NULL); s->branch = head ? xstrdup(head) : NULL; s->reference = "HEAD"; @@ -64,7 +62,7 @@ void wt_status_prepare(struct wt_status *s) static void wt_status_print_unmerged_header(struct wt_status *s) { - const char *c = color(WT_STATUS_HEADER); + const char *c = color(WT_STATUS_HEADER, s); color_fprintf_ln(s->fp, c, "# Unmerged paths:"); if (!s->is_initial) color_fprintf_ln(s->fp, c, "# (use \"git reset %s ...\" to unstage)", s->reference); @@ -76,7 +74,7 @@ static void wt_status_print_unmerged_header(struct wt_status *s) static void wt_status_print_cached_header(struct wt_status *s) { - const char *c = color(WT_STATUS_HEADER); + const char *c = color(WT_STATUS_HEADER, s); color_fprintf_ln(s->fp, c, "# Changes to be committed:"); if (!s->is_initial) { color_fprintf_ln(s->fp, c, "# (use \"git reset %s ...\" to unstage)", s->reference); @@ -89,7 +87,7 @@ static void wt_status_print_cached_header(struct wt_status *s) static void wt_status_print_dirty_header(struct wt_status *s, int has_deleted) { - const char *c = color(WT_STATUS_HEADER); + const char *c = color(WT_STATUS_HEADER, s); 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)"); @@ -101,7 +99,7 @@ static void wt_status_print_dirty_header(struct wt_status *s, static void wt_status_print_untracked_header(struct wt_status *s) { - const char *c = color(WT_STATUS_HEADER); + const char *c = color(WT_STATUS_HEADER, s); 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, "#"); @@ -109,7 +107,7 @@ static void wt_status_print_untracked_header(struct wt_status *s) static void wt_status_print_trailer(struct wt_status *s) { - color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#"); + color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#"); } #define quote_path quote_path_relative @@ -117,13 +115,13 @@ static void wt_status_print_trailer(struct wt_status *s) static void wt_status_print_unmerged_data(struct wt_status *s, struct string_list_item *it) { - const char *c = color(WT_STATUS_UNMERGED); + const char *c = color(WT_STATUS_UNMERGED, s); struct wt_status_change_data *d = it->util; struct strbuf onebuf = STRBUF_INIT; const char *one, *how = "bug"; one = quote_path(it->string, -1, &onebuf, s->prefix); - color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t"); + color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t"); switch (d->stagemask) { case 1: how = "both deleted:"; break; case 2: how = "added by us:"; break; @@ -142,7 +140,7 @@ static void wt_status_print_change_data(struct wt_status *s, struct string_list_item *it) { struct wt_status_change_data *d = it->util; - const char *c = color(change_type); + const char *c = color(change_type, s); int status = status; char *one_name; char *two_name; @@ -164,7 +162,7 @@ static void wt_status_print_change_data(struct wt_status *s, one = quote_path(one_name, -1, &onebuf, s->prefix); two = quote_path(two_name, -1, &twobuf, s->prefix); - color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t"); + color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t"); switch (status) { case DIFF_STATUS_ADDED: color_fprintf(s->fp, c, "new file: %s", one); @@ -450,7 +448,7 @@ static void wt_status_print_submodule_summary(struct wt_status *s) NULL }; - sprintf(summary_limit, "%d", wt_status_submodule_summary); + sprintf(summary_limit, "%d", s->submodule_summary); snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", s->index_file); memset(&sm_summary, 0, sizeof(sm_summary)); @@ -471,8 +469,7 @@ static void wt_status_print_untracked(struct wt_status *s) struct strbuf buf = STRBUF_INIT; memset(&dir, 0, sizeof(dir)); - - if (!s->untracked) + if (s->show_untracked_files != SHOW_ALL_UNTRACKED_FILES) dir.flags |= DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES; setup_standard_excludes(&dir); @@ -487,8 +484,8 @@ static void wt_status_print_untracked(struct wt_status *s) wt_status_print_untracked_header(s); shown_header = 1; } - color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t"); - color_fprintf_ln(s->fp, color(WT_STATUS_UNTRACKED), "%s", + color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t"); + color_fprintf_ln(s->fp, color(WT_STATUS_UNTRACKED, s), "%s", quote_path(ent->name, ent->len, &buf, s->prefix)); } @@ -532,15 +529,15 @@ static void wt_status_print_tracking(struct wt_status *s) return; for (cp = sb.buf; (ep = strchr(cp, '\n')) != NULL; cp = ep + 1) - color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), + color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "# %.*s", (int)(ep - cp), cp); - color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#"); + color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#"); } void wt_status_print(struct wt_status *s) { unsigned char sha1[20]; - const char *branch_color = color(WT_STATUS_HEADER); + const char *branch_color = color(WT_STATUS_HEADER, s); s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0; if (s->branch) { @@ -550,10 +547,10 @@ 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); + branch_color = color(WT_STATUS_NOBRANCH, s); on_what = "Not currently on any branch."; } - color_fprintf(s->fp, color(WT_STATUS_HEADER), "# "); + color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "# "); color_fprintf_ln(s->fp, branch_color, "%s%s", on_what, branch_name); if (!s->is_initial) wt_status_print_tracking(s); @@ -562,17 +559,17 @@ void wt_status_print(struct wt_status *s) wt_status_collect_changes(s); if (s->is_initial) { - 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), "#"); + color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#"); + color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "# Initial commit"); + color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#"); } wt_status_print_unmerged(s); wt_status_print_updated(s); wt_status_print_changed(s); - if (wt_status_submodule_summary) + if (s->submodule_summary) wt_status_print_submodule_summary(s); - if (show_untracked_files) + if (s->show_untracked_files) wt_status_print_untracked(s); else if (s->commitable) fprintf(s->fp, "# Untracked files not listed (use -u option to show untracked files)\n"); @@ -590,7 +587,7 @@ void wt_status_print(struct wt_status *s) printf("nothing added to commit but untracked files present (use \"git add\" to track)\n"); else if (s->is_initial) printf("nothing to commit (create/copy files and use \"git add\" to track)\n"); - else if (!show_untracked_files) + else if (!s->show_untracked_files) printf("nothing to commit (use -u to show untracked files)\n"); else printf("nothing to commit (working directory clean)\n"); @@ -599,15 +596,17 @@ void wt_status_print(struct wt_status *s) int git_status_config(const char *k, const char *v, void *cb) { + struct wt_status *s = cb; + 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; + s->submodule_summary = git_config_bool_or_int(k, v, &is_bool); + if (is_bool && s->submodule_summary) + s->submodule_summary = -1; return 0; } if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) { - wt_status_use_color = git_config_colorbool(k, v, -1); + s->use_color = git_config_colorbool(k, v, -1); return 0; } if (!prefixcmp(k, "status.color.") || !prefixcmp(k, "color.status.")) { @@ -618,21 +617,21 @@ int git_status_config(const char *k, const char *v, void *cb) return 0; } if (!strcmp(k, "status.relativepaths")) { - wt_status_relative_paths = git_config_bool(k, v); + s->relative_paths = git_config_bool(k, v); return 0; } if (!strcmp(k, "status.showuntrackedfiles")) { if (!v) return config_error_nonbool(k); else if (!strcmp(v, "no")) - show_untracked_files = SHOW_NO_UNTRACKED_FILES; + s->show_untracked_files = SHOW_NO_UNTRACKED_FILES; else if (!strcmp(v, "normal")) - show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES; + s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES; else if (!strcmp(v, "all")) - show_untracked_files = SHOW_ALL_UNTRACKED_FILES; + s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES; else return error("Invalid untracked files mode '%s'", v); return 0; } - return git_diff_ui_config(k, v, cb); + return git_diff_ui_config(k, v, NULL); } -- cgit v1.2.1 From 23900a964608bbfda6989a0a2cd4342f19f9194c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 9 Aug 2009 23:08:40 -0700 Subject: wt-status: move wt_status_colors[] into wt_status structure The benefit of this one alone is somewhat iffy, but for completeness this moves the wt_status_colors[] color palette to the wt_status structure to complete the libification started by the previous commit. Signed-off-by: Junio C Hamano --- wt-status.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index af93bb52db..cfbaf309ad 100644 --- a/wt-status.c +++ b/wt-status.c @@ -1,6 +1,5 @@ #include "cache.h" #include "wt-status.h" -#include "color.h" #include "object.h" #include "dir.h" #include "commit.h" @@ -11,7 +10,7 @@ #include "run-command.h" #include "remote.h" -static char wt_status_colors[][COLOR_MAXLEN] = { +static char default_wt_status_colors[][COLOR_MAXLEN] = { GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */ GIT_COLOR_GREEN, /* WT_STATUS_UPDATED */ GIT_COLOR_RED, /* WT_STATUS_CHANGED */ @@ -40,7 +39,7 @@ static int parse_status_slot(const char *var, int offset) static const char *color(int slot, struct wt_status *s) { - return s->use_color > 0 ? wt_status_colors[slot] : ""; + return s->use_color > 0 ? s->color_palette[slot] : ""; } void wt_status_prepare(struct wt_status *s) @@ -49,6 +48,8 @@ void wt_status_prepare(struct wt_status *s) const char *head; memset(s, 0, sizeof(*s)); + memcpy(s->color_palette, default_wt_status_colors, + sizeof(default_wt_status_colors)); s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES; s->use_color = -1; s->relative_paths = 1; @@ -613,7 +614,7 @@ int git_status_config(const char *k, const char *v, void *cb) int slot = parse_status_slot(k, 13); if (!v) return config_error_nonbool(k); - color_parse(v, k, wt_status_colors[slot]); + color_parse(v, k, s->color_palette[slot]); return 0; } if (!strcmp(k, "status.relativepaths")) { -- cgit v1.2.1 From f766b36783c7ceeb0427f5e1af862b9a67ae1c4c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 9 Aug 2009 23:12:19 -0700 Subject: Make git_status_config() file scope static to builtin-commit.c Signed-off-by: Junio C Hamano --- wt-status.c | 60 ------------------------------------------------------------ 1 file changed, 60 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index cfbaf309ad..4cbe03a70a 100644 --- a/wt-status.c +++ b/wt-status.c @@ -19,24 +19,6 @@ static char default_wt_status_colors[][COLOR_MAXLEN] = { GIT_COLOR_RED, /* WT_STATUS_UNMERGED */ }; -static int parse_status_slot(const char *var, int offset) -{ - if (!strcasecmp(var+offset, "header")) - return WT_STATUS_HEADER; - if (!strcasecmp(var+offset, "updated") - || !strcasecmp(var+offset, "added")) - return WT_STATUS_UPDATED; - if (!strcasecmp(var+offset, "changed")) - return WT_STATUS_CHANGED; - if (!strcasecmp(var+offset, "untracked")) - return WT_STATUS_UNTRACKED; - if (!strcasecmp(var+offset, "nobranch")) - return WT_STATUS_NOBRANCH; - if (!strcasecmp(var+offset, "unmerged")) - return WT_STATUS_UNMERGED; - die("bad config variable '%s'", var); -} - static const char *color(int slot, struct wt_status *s) { return s->use_color > 0 ? s->color_palette[slot] : ""; @@ -594,45 +576,3 @@ void wt_status_print(struct wt_status *s) printf("nothing to commit (working directory clean)\n"); } } - -int git_status_config(const char *k, const char *v, void *cb) -{ - struct wt_status *s = cb; - - if (!strcmp(k, "status.submodulesummary")) { - int is_bool; - s->submodule_summary = git_config_bool_or_int(k, v, &is_bool); - if (is_bool && s->submodule_summary) - s->submodule_summary = -1; - return 0; - } - if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) { - s->use_color = git_config_colorbool(k, v, -1); - return 0; - } - if (!prefixcmp(k, "status.color.") || !prefixcmp(k, "color.status.")) { - int slot = parse_status_slot(k, 13); - if (!v) - return config_error_nonbool(k); - color_parse(v, k, s->color_palette[slot]); - return 0; - } - if (!strcmp(k, "status.relativepaths")) { - s->relative_paths = git_config_bool(k, v); - return 0; - } - if (!strcmp(k, "status.showuntrackedfiles")) { - if (!v) - return config_error_nonbool(k); - else if (!strcmp(v, "no")) - s->show_untracked_files = SHOW_NO_UNTRACKED_FILES; - else if (!strcmp(v, "normal")) - s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES; - else if (!strcmp(v, "all")) - s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES; - else - return error("Invalid untracked files mode '%s'", v); - return 0; - } - return git_diff_ui_config(k, v, NULL); -} -- cgit v1.2.1 From 7637868362ab64fe22521c645006ba70c4ef83a9 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 10 Aug 2009 00:36:33 -0700 Subject: wt-status: collect untracked files in a separate "collect" phase In a way similar to updated and locally modified files are collected. Signed-off-by: Junio C Hamano --- wt-status.c | 58 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 22 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 4cbe03a70a..63598ce40c 100644 --- a/wt-status.c +++ b/wt-status.c @@ -41,6 +41,7 @@ void wt_status_prepare(struct wt_status *s) s->fp = stdout; s->index_file = get_index_file(); s->change.strdup_strings = 1; + s->untracked.strdup_strings = 1; } static void wt_status_print_unmerged_header(struct wt_status *s) @@ -311,7 +312,30 @@ static void wt_status_collect_changes_initial(struct wt_status *s) } } -void wt_status_collect_changes(struct wt_status *s) +static void wt_status_collect_untracked(struct wt_status *s) +{ + int i; + struct dir_struct dir; + + if (!s->show_untracked_files) + return; + memset(&dir, 0, sizeof(dir)); + if (s->show_untracked_files != SHOW_ALL_UNTRACKED_FILES) + dir.flags |= + DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES; + setup_standard_excludes(&dir); + + fill_directory(&dir, NULL); + for(i = 0; i < dir.nr; i++) { + struct dir_entry *ent = dir.entries[i]; + if (!cache_name_is_other(ent->name, ent->len)) + continue; + s->workdir_untracked = 1; + string_list_insert(ent->name, &s->untracked); + } +} + +void wt_status_collect(struct wt_status *s) { wt_status_collect_changes_worktree(s); @@ -319,6 +343,7 @@ void wt_status_collect_changes(struct wt_status *s) wt_status_collect_changes_initial(s); else wt_status_collect_changes_index(s); + wt_status_collect_untracked(s); } static void wt_status_print_unmerged(struct wt_status *s) @@ -446,31 +471,20 @@ static void wt_status_print_submodule_summary(struct wt_status *s) static void wt_status_print_untracked(struct wt_status *s) { - struct dir_struct dir; int i; - int shown_header = 0; struct strbuf buf = STRBUF_INIT; - memset(&dir, 0, sizeof(dir)); - if (s->show_untracked_files != SHOW_ALL_UNTRACKED_FILES) - dir.flags |= - DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES; - setup_standard_excludes(&dir); + if (!s->untracked.nr) + return; - fill_directory(&dir, NULL); - for(i = 0; i < dir.nr; i++) { - struct dir_entry *ent = dir.entries[i]; - if (!cache_name_is_other(ent->name, ent->len)) - continue; - if (!shown_header) { - s->workdir_untracked = 1; - wt_status_print_untracked_header(s); - shown_header = 1; - } + wt_status_print_untracked_header(s); + for (i = 0; i < s->untracked.nr; i++) { + struct string_list_item *it; + it = &(s->untracked.items[i]); color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t"); color_fprintf_ln(s->fp, color(WT_STATUS_UNTRACKED, s), "%s", - quote_path(ent->name, ent->len, - &buf, s->prefix)); + quote_path(it->string, strlen(it->string), + &buf, s->prefix)); } strbuf_release(&buf); } @@ -539,7 +553,7 @@ void wt_status_print(struct wt_status *s) wt_status_print_tracking(s); } - wt_status_collect_changes(s); + wt_status_collect(s); if (s->is_initial) { color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#"); @@ -566,7 +580,7 @@ void wt_status_print(struct wt_status *s) ; /* nothing */ else if (s->workdir_dirty) printf("no changes added to commit (use \"git add\" and/or \"git commit -a\")\n"); - else if (s->workdir_untracked) + else if (s->untracked.nr) printf("nothing added to commit but untracked files present (use \"git add\" to track)\n"); else if (s->is_initial) printf("nothing to commit (create/copy files and use \"git add\" to track)\n"); -- cgit v1.2.1 From 76e2f7ce323c7ddb3a7c29e56407da6a69a4fa53 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 7 Aug 2009 23:31:57 -0700 Subject: git stat: the beginning of "status that is not a dry-run of commit" Tentatively add "git stat" as a new command. This is not "preview of commit with the same arguments"; the path parameters are not paths to be added to the pristine index (aka "--only" option), but are taken as pathspecs to limit the output. Later in 1.7.0 release, it will take over "git status". Signed-off-by: Junio C Hamano --- wt-status.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 63598ce40c..249227c382 100644 --- a/wt-status.c +++ b/wt-status.c @@ -269,6 +269,7 @@ static void wt_status_collect_changes_worktree(struct wt_status *s) rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK; rev.diffopt.format_callback = wt_status_collect_changed_cb; rev.diffopt.format_callback_data = s; + rev.prune_data = s->pathspec; run_diff_files(&rev, 0); } @@ -285,6 +286,7 @@ static void wt_status_collect_changes_index(struct wt_status *s) rev.diffopt.detect_rename = 1; rev.diffopt.rename_limit = 200; rev.diffopt.break_opt = 0; + rev.prune_data = s->pathspec; run_diff_index(&rev, 1); } @@ -297,6 +299,8 @@ static void wt_status_collect_changes_initial(struct wt_status *s) struct wt_status_change_data *d; struct cache_entry *ce = active_cache[i]; + if (!ce_path_match(ce, s->pathspec)) + continue; it = string_list_insert(ce->name, &s->change); d = it->util; if (!d) { @@ -330,6 +334,8 @@ static void wt_status_collect_untracked(struct wt_status *s) struct dir_entry *ent = dir.entries[i]; if (!cache_name_is_other(ent->name, ent->len)) continue; + if (!match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL)) + continue; s->workdir_untracked = 1; string_list_insert(ent->name, &s->untracked); } @@ -533,10 +539,8 @@ static void wt_status_print_tracking(struct wt_status *s) void wt_status_print(struct wt_status *s) { - unsigned char sha1[20]; const char *branch_color = color(WT_STATUS_HEADER, s); - 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; @@ -553,8 +557,6 @@ void wt_status_print(struct wt_status *s) wt_status_print_tracking(s); } - wt_status_collect(s); - if (s->is_initial) { color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#"); color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "# Initial commit"); -- cgit v1.2.1 From eeefa7c90e1b754a2b01d73fd93aaf90afdc4914 Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Tue, 1 Sep 2009 01:35:10 -0400 Subject: Style fixes, add a space after if/for/while. The majority of code in core git appears to use a single space after if/for/while. This is an attempt to bring more code to this standard. These are entirely cosmetic changes. Signed-off-by: Brian Gianforcaro Signed-off-by: Junio C Hamano --- wt-status.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 63598ce40c..33954564c6 100644 --- a/wt-status.c +++ b/wt-status.c @@ -326,7 +326,7 @@ static void wt_status_collect_untracked(struct wt_status *s) setup_standard_excludes(&dir); fill_directory(&dir, NULL); - for(i = 0; i < dir.nr; i++) { + for (i = 0; i < dir.nr; i++) { struct dir_entry *ent = dir.entries[i]; if (!cache_name_is_other(ent->name, ent->len)) continue; -- cgit v1.2.1 From 228e7b5d4d6eca8616c7dc3d979478909dbdbfd1 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Tue, 1 Sep 2009 22:13:53 +0200 Subject: status: list unmerged files much later When resolving a conflicted merge, two lists in the status output need more attention from the user than other parts. - the list of updated paths is useful to review the amount of changes the merge brings in (the user cannot do much about them other than reviewing, though); and - the list of unmerged paths needs the most attention from the user; the user needs to resolve them in order to proceed. Since the output of git status does not by default go through the pager, the early parts of the output can scroll away at the top. It is better to put the more important information near the bottom. During a merge, local changes that are not in the index are minimum, and you should keep the untracked list small in any case, so moving the unmerged list from the top of the output to immediately after the list of updated paths would give us the optimum layout. Signed-off-by: Johannes Sixt Acked-by: Jeff King Signed-off-by: Junio C Hamano --- wt-status.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 33954564c6..85f3fcb8a2 100644 --- a/wt-status.c +++ b/wt-status.c @@ -561,8 +561,8 @@ void wt_status_print(struct wt_status *s) color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#"); } - wt_status_print_unmerged(s); wt_status_print_updated(s); + wt_status_print_unmerged(s); wt_status_print_changed(s); if (s->submodule_summary) wt_status_print_submodule_summary(s); -- cgit v1.2.1 From edf563fbaa2ab50734db4a61e9092f25fbb5a417 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 9 Sep 2009 07:43:03 -0400 Subject: status: make "how to stage" messages optional These messages are nice for new users, but experienced git users know how to manipulate the index, and these messages waste a lot of screen real estate. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- wt-status.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 85f3fcb8a2..38eb24536b 100644 --- a/wt-status.c +++ b/wt-status.c @@ -48,6 +48,8 @@ static void wt_status_print_unmerged_header(struct wt_status *s) { const char *c = color(WT_STATUS_HEADER, s); color_fprintf_ln(s->fp, c, "# Unmerged paths:"); + if (!advice_status_hints) + return; if (!s->is_initial) color_fprintf_ln(s->fp, c, "# (use \"git reset %s ...\" to unstage)", s->reference); else @@ -60,6 +62,8 @@ static void wt_status_print_cached_header(struct wt_status *s) { const char *c = color(WT_STATUS_HEADER, s); color_fprintf_ln(s->fp, c, "# Changes to be committed:"); + if (!advice_status_hints) + return; if (!s->is_initial) { color_fprintf_ln(s->fp, c, "# (use \"git reset %s ...\" to unstage)", s->reference); } else { @@ -73,6 +77,8 @@ static void wt_status_print_dirty_header(struct wt_status *s, { const char *c = color(WT_STATUS_HEADER, s); color_fprintf_ln(s->fp, c, "# Changed but not updated:"); + if (!advice_status_hints) + return; if (!has_deleted) color_fprintf_ln(s->fp, c, "# (use \"git add ...\" to update what will be committed)"); else @@ -85,6 +91,8 @@ static void wt_status_print_untracked_header(struct wt_status *s) { const char *c = color(WT_STATUS_HEADER, s); color_fprintf_ln(s->fp, c, "# Untracked files:"); + if (!advice_status_hints) + return; color_fprintf_ln(s->fp, c, "# (use \"git add ...\" to include in what will be committed)"); color_fprintf_ln(s->fp, c, "#"); } -- cgit v1.2.1 From 84dbe7b867cfaaa929ed1941f930d564514ae714 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Sat, 5 Dec 2009 16:04:37 +0100 Subject: builtin-commit: refactor short-status code into wt-status.c Currently, builtin-commit.c contains most code producing the short-status output, whereas wt-status.c contains most of the code for the long format. Refactor so that most of the long and short format producing code resides in wt-status.c and is named analogously. Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano --- wt-status.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 249227c382..8ef824e0d9 100644 --- a/wt-status.c +++ b/wt-status.c @@ -592,3 +592,92 @@ void wt_status_print(struct wt_status *s) printf("nothing to commit (working directory clean)\n"); } } + +static void wt_shortstatus_unmerged(int null_termination, struct string_list_item *it, + struct wt_status *s) +{ + struct wt_status_change_data *d = it->util; + const char *how = "??"; + + switch (d->stagemask) { + case 1: how = "DD"; break; /* both deleted */ + case 2: how = "AU"; break; /* added by us */ + case 3: how = "UD"; break; /* deleted by them */ + case 4: how = "UA"; break; /* added by them */ + case 5: how = "DU"; break; /* deleted by us */ + case 6: how = "AA"; break; /* both added */ + case 7: how = "UU"; break; /* both modified */ + } + printf("%s ", how); + if (null_termination) { + fprintf(stdout, "%s%c", it->string, 0); + } else { + struct strbuf onebuf = STRBUF_INIT; + const char *one; + one = quote_path(it->string, -1, &onebuf, s->prefix); + printf("%s\n", one); + strbuf_release(&onebuf); + } +} + +static void wt_shortstatus_status(int null_termination, struct string_list_item *it, + struct wt_status *s) +{ + struct wt_status_change_data *d = it->util; + + printf("%c%c ", + !d->index_status ? ' ' : d->index_status, + !d->worktree_status ? ' ' : d->worktree_status); + if (null_termination) { + fprintf(stdout, "%s%c", it->string, 0); + if (d->head_path) + fprintf(stdout, "%s%c", d->head_path, 0); + } else { + struct strbuf onebuf = STRBUF_INIT; + const char *one; + if (d->head_path) { + one = quote_path(d->head_path, -1, &onebuf, s->prefix); + printf("%s -> ", one); + strbuf_release(&onebuf); + } + one = quote_path(it->string, -1, &onebuf, s->prefix); + printf("%s\n", one); + strbuf_release(&onebuf); + } +} + +static void wt_shortstatus_untracked(int null_termination, struct string_list_item *it, + struct wt_status *s) +{ + if (null_termination) { + fprintf(stdout, "?? %s%c", it->string, 0); + } else { + struct strbuf onebuf = STRBUF_INIT; + const char *one; + one = quote_path(it->string, -1, &onebuf, s->prefix); + printf("?? %s\n", one); + strbuf_release(&onebuf); + } +} + +void wt_shortstatus_print(struct wt_status *s, int null_termination) +{ + int i; + for (i = 0; i < s->change.nr; i++) { + struct wt_status_change_data *d; + struct string_list_item *it; + + it = &(s->change.items[i]); + d = it->util; + if (d->stagemask) + wt_shortstatus_unmerged(null_termination, it, s); + else + wt_shortstatus_status(null_termination, it, s); + } + for (i = 0; i < s->untracked.nr; i++) { + struct string_list_item *it; + + it = &(s->untracked.items[i]); + wt_shortstatus_untracked(null_termination, it, s); + } +} -- cgit v1.2.1 From 3fe2a894e98566dd91e69982552454cfb381cf24 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Sat, 5 Dec 2009 16:04:38 +0100 Subject: status -s: obey color.status Make the short version of status obey the color.status boolean. We color the status letters only, because they carry the state information and are potentially colored differently, such as for a file with staged changes as well as changes in the worktree against the index. Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano --- wt-status.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 8ef824e0d9..696c6b0bf1 100644 --- a/wt-status.c +++ b/wt-status.c @@ -608,14 +608,14 @@ static void wt_shortstatus_unmerged(int null_termination, struct string_list_ite case 6: how = "AA"; break; /* both added */ case 7: how = "UU"; break; /* both modified */ } - printf("%s ", how); + color_fprintf(s->fp, color(WT_STATUS_UNMERGED, s), "%s", how); if (null_termination) { - fprintf(stdout, "%s%c", it->string, 0); + fprintf(stdout, " %s%c", it->string, 0); } else { struct strbuf onebuf = STRBUF_INIT; const char *one; one = quote_path(it->string, -1, &onebuf, s->prefix); - printf("%s\n", one); + printf(" %s\n", one); strbuf_release(&onebuf); } } @@ -625,9 +625,15 @@ static void wt_shortstatus_status(int null_termination, struct string_list_item { struct wt_status_change_data *d = it->util; - printf("%c%c ", - !d->index_status ? ' ' : d->index_status, - !d->worktree_status ? ' ' : d->worktree_status); + if (d->index_status) + color_fprintf(s->fp, color(WT_STATUS_UPDATED, s), "%c", d->index_status); + else + putchar(' '); + if (d->worktree_status) + color_fprintf(s->fp, color(WT_STATUS_CHANGED, s), "%c", d->worktree_status); + else + putchar(' '); + putchar(' '); if (null_termination) { fprintf(stdout, "%s%c", it->string, 0); if (d->head_path) @@ -655,7 +661,8 @@ static void wt_shortstatus_untracked(int null_termination, struct string_list_it struct strbuf onebuf = STRBUF_INIT; const char *one; one = quote_path(it->string, -1, &onebuf, s->prefix); - printf("?? %s\n", one); + color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), "??"); + printf(" %s\n", one); strbuf_release(&onebuf); } } -- cgit v1.2.1 From 4a7cc2fdf39c90e6eff84d30b86490cac2c33705 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 7 Dec 2009 00:17:15 -0500 Subject: status: disable color for porcelain format The porcelain format is identical to the shortstatus format, except that it should not respect any user configuration, including color. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- wt-status.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 696c6b0bf1..756defea1a 100644 --- a/wt-status.c +++ b/wt-status.c @@ -688,3 +688,9 @@ void wt_shortstatus_print(struct wt_status *s, int null_termination) wt_shortstatus_untracked(null_termination, it, s); } } + +void wt_porcelain_print(struct wt_status *s, int null_termination) +{ + s->use_color = 0; + wt_shortstatus_print(s, null_termination); +} -- cgit v1.2.1 From 8661768fc9cfdeeaae76693501b82940cfcbedc2 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 7 Dec 2009 00:26:25 -0500 Subject: status: reduce duplicated setup code We have three output formats: short, porcelain, and long. The short and long formats respect user-config, and the porcelain one does not. This led to us repeating config-related setup code for the short and long formats. Since the last commit, color config is explicitly cleared when showing the porcelain format. Let's do the same with relative-path configuration, which enables us to hoist the duplicated code from the switch statement in cmd_status. As a bonus, this fixes "commit --dry-run --porcelain", which was unconditionally setting up that configuration, anyway. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- wt-status.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 756defea1a..3fdcf97e11 100644 --- a/wt-status.c +++ b/wt-status.c @@ -692,5 +692,7 @@ void wt_shortstatus_print(struct wt_status *s, int null_termination) void wt_porcelain_print(struct wt_status *s, int null_termination) { s->use_color = 0; + s->relative_paths = 0; + s->prefix = NULL; wt_shortstatus_print(s, null_termination); } -- cgit v1.2.1 From dd20f8af1ae54773569b78b1b71d1ea663705d2c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 12 Dec 2009 00:18:12 -0800 Subject: commit/status: "git add " is not necessarily how to resolve When the desired resolution is to remove the path, "git rm " is the command the user needs to use. Just like in "Changed but not updated" section, suggest to use "git add/rm" as appropriate. Signed-off-by: Junio C Hamano --- wt-status.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 3fdcf97e11..56cd8741c0 100644 --- a/wt-status.c +++ b/wt-status.c @@ -52,7 +52,7 @@ static void wt_status_print_unmerged_header(struct wt_status *s) color_fprintf_ln(s->fp, c, "# (use \"git reset %s ...\" to unstage)", s->reference); else color_fprintf_ln(s->fp, c, "# (use \"git rm --cached ...\" to unstage)"); - color_fprintf_ln(s->fp, c, "# (use \"git add ...\" to mark resolution)"); + color_fprintf_ln(s->fp, c, "# (use \"git add/rm ...\" as appropriate to mark resolution)"); color_fprintf_ln(s->fp, c, "#"); } -- cgit v1.2.1 From 3c5884536563518ce6cd4dc782b0ebb670bf3b6d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 11 Dec 2009 23:53:41 -0800 Subject: status/commit: do not suggest "reset HEAD " while merging Suggesting "'reset HEAD ' to unstage" is dead wrong if we are about to record a merge commit. For either an unmerged path (i.e. with unresolved conflicts), or an updated path, it would result in discarding what the other branch did. Note that we do not do anything special in a case where we are amending a merge. The user is making an evil merge starting from an already committed merge, and running "reset HEAD " is the right way to get rid of the local edit that has been added to the index. Once "reset --unresolve " becomes available, we might want to suggest it for a merged path that has unresolve information, but until then, just remove the incorrect advice. We might also want to suggest "checkout --conflict " to revert the file in the work tree to the state of failed automerge for an unmerged path, but we never did that, and this commit does not change that. Signed-off-by: Junio C Hamano --- wt-status.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 56cd8741c0..c4589055bb 100644 --- a/wt-status.c +++ b/wt-status.c @@ -47,8 +47,11 @@ void wt_status_prepare(struct wt_status *s) static void wt_status_print_unmerged_header(struct wt_status *s) { const char *c = color(WT_STATUS_HEADER, s); + color_fprintf_ln(s->fp, c, "# Unmerged paths:"); - if (!s->is_initial) + if (s->in_merge) + ; + else if (!s->is_initial) color_fprintf_ln(s->fp, c, "# (use \"git reset %s ...\" to unstage)", s->reference); else color_fprintf_ln(s->fp, c, "# (use \"git rm --cached ...\" to unstage)"); @@ -59,12 +62,14 @@ static void wt_status_print_unmerged_header(struct wt_status *s) static void wt_status_print_cached_header(struct wt_status *s) { const char *c = color(WT_STATUS_HEADER, s); + color_fprintf_ln(s->fp, c, "# Changes to be committed:"); - if (!s->is_initial) { + if (s->in_merge) + ; /* NEEDSWORK: use "git reset --unresolve"??? */ + else if (!s->is_initial) color_fprintf_ln(s->fp, c, "# (use \"git reset %s ...\" to unstage)", s->reference); - } else { + else color_fprintf_ln(s->fp, c, "# (use \"git rm --cached ...\" to unstage)"); - } color_fprintf_ln(s->fp, c, "#"); } @@ -72,6 +77,7 @@ static void wt_status_print_dirty_header(struct wt_status *s, int has_deleted) { const char *c = color(WT_STATUS_HEADER, s); + 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)"); -- cgit v1.2.1 From 688cd6d2b9335f2ac20d02996215a0e6da1779b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 14 Jan 2010 22:02:21 +0700 Subject: status: only touch path we may need to check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch gets rid of whole-tree cache refresh and untracked file search. Instead only specified path will be looked at. Again some numbers on gentoo-x86, ~80k files: Unmodified Git: $ time git st eclass/ nothing to commit (working directory clean) real 0m3.211s user 0m1.977s sys 0m1.135s Modified Git: $ time ~/w/git/git st eclass/ nothing to commit (working directory clean) real 0m1.587s user 0m1.426s sys 0m0.111s Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- wt-status.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 5d56988016..65feb29f2e 100644 --- a/wt-status.c +++ b/wt-status.c @@ -343,7 +343,7 @@ static void wt_status_collect_untracked(struct wt_status *s) DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES; setup_standard_excludes(&dir); - fill_directory(&dir, NULL); + fill_directory(&dir, s->pathspec); for (i = 0; i < dir.nr; i++) { struct dir_entry *ent = dir.entries[i]; if (!cache_name_is_other(ent->name, ent->len)) -- cgit v1.2.1 From f17a5d34948363087db94a1cb2c3c715c1ada2d8 Mon Sep 17 00:00:00 2001 From: Jens Lehmann Date: Sun, 17 Jan 2010 20:42:31 +0100 Subject: git status: Show uncommitted submodule changes too when enabled When the configuration variable status.submodulesummary is not 0 or false, "git status" shows the submodule summary of the staged submodule commits. But it did not show the summary of those commits not yet staged in the supermodule, making it hard to see what will not be committed. The output of "submodule summary --for-status" has been changed from "# Modified submodules:" to "# Submodule changes to be committed:" for the already staged changes. "# Submodules changed but not updated:" has been added for changes that will not be committed. This is much clearer and consistent with the output for regular files. Signed-off-by: Jens Lehmann Signed-off-by: Junio C Hamano --- wt-status.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 5d56988016..deaac93d17 100644 --- a/wt-status.c +++ b/wt-status.c @@ -459,7 +459,7 @@ static void wt_status_print_changed(struct wt_status *s) wt_status_print_trailer(s); } -static void wt_status_print_submodule_summary(struct wt_status *s) +static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitted) { struct child_process sm_summary; char summary_limit[64]; @@ -468,11 +468,11 @@ static void wt_status_print_submodule_summary(struct wt_status *s) const char *argv[] = { "submodule", "summary", - "--cached", + uncommitted ? "--files" : "--cached", "--for-status", "--summary-limit", summary_limit, - s->amend ? "HEAD^" : "HEAD", + uncommitted ? NULL : (s->amend ? "HEAD^" : "HEAD"), NULL }; @@ -580,8 +580,10 @@ void wt_status_print(struct wt_status *s) wt_status_print_updated(s); wt_status_print_unmerged(s); wt_status_print_changed(s); - if (s->submodule_summary) - wt_status_print_submodule_summary(s); + if (s->submodule_summary) { + wt_status_print_submodule_summary(s, 0); /* staged */ + wt_status_print_submodule_summary(s, 1); /* unstaged */ + } if (s->show_untracked_files) wt_status_print_untracked(s); else if (s->commitable) -- cgit v1.2.1 From 9297f77e6d350f33de961e149dc33c77e7392db4 Mon Sep 17 00:00:00 2001 From: Jens Lehmann Date: Mon, 8 Mar 2010 13:53:19 +0100 Subject: git status: Show detailed dirty status of submodules in long format Since 1.7.0 there are three reasons a submodule is considered modified against the work tree: It contains new commits, modified content or untracked content. Lets show all reasons in the long format of git status, so the user can better asses the nature of the modification. This change does not affect the short and porcelain formats. Two new members are added to "struct wt_status_change_data" to store the information gathered by run_diff_files(). wt-status.c uses the new flag DIFF_OPT_DIRTY_SUBMODULES to tell diff-lib.c it wants to get detailed dirty information about submodules. A hint line for submodules is printed in the dirty header when dirty submodules are present. Signed-off-by: Jens Lehmann Signed-off-by: Junio C Hamano --- wt-status.c | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 5807fc3211..e0e915e46a 100644 --- a/wt-status.c +++ b/wt-status.c @@ -78,7 +78,8 @@ static void wt_status_print_cached_header(struct wt_status *s) } static void wt_status_print_dirty_header(struct wt_status *s, - int has_deleted) + int has_deleted, + int has_dirty_submodules) { const char *c = color(WT_STATUS_HEADER, s); @@ -90,6 +91,8 @@ static void wt_status_print_dirty_header(struct wt_status *s, 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)"); + if (has_dirty_submodules) + color_fprintf_ln(s->fp, c, "# (commit or discard the untracked or modified content in submodules)"); color_fprintf_ln(s->fp, c, "#"); } @@ -144,6 +147,7 @@ static void wt_status_print_change_data(struct wt_status *s, char *two_name; const char *one, *two; struct strbuf onebuf = STRBUF_INIT, twobuf = STRBUF_INIT; + struct strbuf extra = STRBUF_INIT; one_name = two_name = it->string; switch (change_type) { @@ -153,6 +157,17 @@ static void wt_status_print_change_data(struct wt_status *s, one_name = d->head_path; break; case WT_STATUS_CHANGED: + if (d->new_submodule_commits || d->dirty_submodule) { + strbuf_addstr(&extra, " ("); + if (d->new_submodule_commits) + strbuf_addf(&extra, "new commits, "); + if (d->dirty_submodule & DIRTY_SUBMODULE_MODIFIED) + strbuf_addf(&extra, "modified content, "); + if (d->dirty_submodule & DIRTY_SUBMODULE_UNTRACKED) + strbuf_addf(&extra, "untracked content, "); + strbuf_setlen(&extra, extra.len - 2); + strbuf_addch(&extra, ')'); + } status = d->worktree_status; break; } @@ -189,6 +204,10 @@ static void wt_status_print_change_data(struct wt_status *s, default: die("bug: unhandled diff status %c", status); } + if (extra.len) { + color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "%s", extra.buf); + strbuf_release(&extra); + } fprintf(s->fp, "\n"); strbuf_release(&onebuf); strbuf_release(&twobuf); @@ -218,6 +237,9 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q, } if (!d->worktree_status) d->worktree_status = p->status; + d->dirty_submodule = p->two->dirty_submodule; + if (S_ISGITLINK(p->two->mode)) + d->new_submodule_commits = !!hashcmp(p->one->sha1, p->two->sha1); } } @@ -281,6 +303,7 @@ static void wt_status_collect_changes_worktree(struct wt_status *s) init_revisions(&rev, NULL); setup_revisions(0, NULL, &rev, NULL); rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK; + DIFF_OPT_SET(&rev.diffopt, DIRTY_SUBMODULES); rev.diffopt.format_callback = wt_status_collect_changed_cb; rev.diffopt.format_callback_data = s; rev.prune_data = s->pathspec; @@ -418,33 +441,39 @@ static void wt_status_print_updated(struct wt_status *s) * 0 : no change * 1 : some change but no delete */ -static int wt_status_check_worktree_changes(struct wt_status *s) +static int wt_status_check_worktree_changes(struct wt_status *s, + int *dirty_submodules) { int i; int changes = 0; + *dirty_submodules = 0; + for (i = 0; i < s->change.nr; i++) { struct wt_status_change_data *d; d = s->change.items[i].util; if (!d->worktree_status || d->worktree_status == DIFF_STATUS_UNMERGED) continue; - changes = 1; + if (!changes) + changes = 1; + if (d->dirty_submodule) + *dirty_submodules = 1; if (d->worktree_status == DIFF_STATUS_DELETED) - return -1; + changes = -1; } return changes; } static void wt_status_print_changed(struct wt_status *s) { - int i; - int worktree_changes = wt_status_check_worktree_changes(s); + int i, dirty_submodules; + int worktree_changes = wt_status_check_worktree_changes(s, &dirty_submodules); if (!worktree_changes) return; - wt_status_print_dirty_header(s, worktree_changes < 0); + wt_status_print_dirty_header(s, worktree_changes < 0, dirty_submodules); for (i = 0; i < s->change.nr; i++) { struct wt_status_change_data *d; -- cgit v1.2.1 From 32962c9bd5149005b163dff230670872eb99286a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 8 Mar 2010 22:58:09 -0800 Subject: revision: introduce setup_revision_opt So far the last parameter to setup_revisions() was to specify the default ref when the command line did not give any (typically "HEAD"). This changes it to take a pointer to a structure so that we can add other information without touching too many codepaths in later patches. There is no functionality change. Signed-off-by: Junio C Hamano --- wt-status.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 5807fc3211..dcaec7f09e 100644 --- a/wt-status.c +++ b/wt-status.c @@ -290,10 +290,13 @@ static void wt_status_collect_changes_worktree(struct wt_status *s) static void wt_status_collect_changes_index(struct wt_status *s) { struct rev_info rev; + struct setup_revision_opt opt; init_revisions(&rev, NULL); - setup_revisions(0, NULL, &rev, - s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference); + memset(&opt, 0, sizeof(opt)); + opt.def = s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference; + setup_revisions(0, NULL, &rev, &opt); + rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK; rev.diffopt.format_callback = wt_status_collect_updated_cb; rev.diffopt.format_callback_data = s; @@ -512,11 +515,15 @@ static void wt_status_print_untracked(struct wt_status *s) static void wt_status_print_verbose(struct wt_status *s) { struct rev_info rev; + struct setup_revision_opt opt; init_revisions(&rev, NULL); DIFF_OPT_SET(&rev.diffopt, ALLOW_TEXTCONV); - setup_revisions(0, NULL, &rev, - s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference); + + memset(&opt, 0, sizeof(opt)); + opt.def = s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference; + setup_revisions(0, NULL, &rev, &opt); + rev.diffopt.output_format |= DIFF_FORMAT_PATCH; rev.diffopt.detect_rename = 1; rev.diffopt.file = s->fp; -- cgit v1.2.1 From 3bfc45047654c7dd38b32033321228e97fc8f60e Mon Sep 17 00:00:00 2001 From: Jens Lehmann Date: Sat, 13 Mar 2010 23:00:27 +0100 Subject: git status: ignoring untracked files must apply to submodules too Since 1.7.0 submodules are considered dirty when they contain untracked files. But when git status is called with the "-uno" option, the user asked to ignore untracked files, so they must be ignored in submodules too. To achieve this, the new flag DIFF_OPT_IGNORE_UNTRACKED_IN_SUBMODULES is introduced. Signed-off-by: Jens Lehmann Signed-off-by: Junio C Hamano --- wt-status.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index e0e915e46a..5848f1c908 100644 --- a/wt-status.c +++ b/wt-status.c @@ -304,6 +304,8 @@ static void wt_status_collect_changes_worktree(struct wt_status *s) setup_revisions(0, NULL, &rev, NULL); rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK; DIFF_OPT_SET(&rev.diffopt, DIRTY_SUBMODULES); + if (!s->show_untracked_files) + DIFF_OPT_SET(&rev.diffopt, IGNORE_UNTRACKED_IN_SUBMODULES); rev.diffopt.format_callback = wt_status_collect_changed_cb; rev.diffopt.format_callback_data = s; rev.prune_data = s->pathspec; -- cgit v1.2.1 From e28a243b0000e7b82adcc5eb7445ef132f22b9de Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 9 Apr 2010 23:34:40 -0700 Subject: wt-status: remove unused workdir_untracked member Signed-off-by: Junio C Hamano --- wt-status.c | 1 - 1 file changed, 1 deletion(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 8ca59a2d2a..db20b86102 100644 --- a/wt-status.c +++ b/wt-status.c @@ -378,7 +378,6 @@ static void wt_status_collect_untracked(struct wt_status *s) continue; if (!match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL)) continue; - s->workdir_untracked = 1; string_list_insert(ent->name, &s->untracked); } } -- cgit v1.2.1 From f5b26b1d14d3362fa41e51f4f78cdf56968733ba Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 9 Apr 2010 23:58:27 -0700 Subject: wt-status: plug memory leak while collecting untracked files Signed-off-by: Junio C Hamano --- wt-status.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index db20b86102..c88159ad06 100644 --- a/wt-status.c +++ b/wt-status.c @@ -379,7 +379,10 @@ static void wt_status_collect_untracked(struct wt_status *s) if (!match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL)) continue; string_list_insert(ent->name, &s->untracked); + free(ent); } + + free(dir.entries); } void wt_status_collect(struct wt_status *s) -- cgit v1.2.1 From 6cb3f6b28294cb2b3766370f42a570fb46ba4e97 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 10 Apr 2010 00:11:53 -0700 Subject: wt-status: collect ignored files Signed-off-by: Junio C Hamano --- wt-status.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index c88159ad06..f13c7da64f 100644 --- a/wt-status.c +++ b/wt-status.c @@ -42,6 +42,7 @@ void wt_status_prepare(struct wt_status *s) s->index_file = get_index_file(); s->change.strdup_strings = 1; s->untracked.strdup_strings = 1; + s->ignored.strdup_strings = 1; } static void wt_status_print_unmerged_header(struct wt_status *s) @@ -382,6 +383,21 @@ static void wt_status_collect_untracked(struct wt_status *s) free(ent); } + if (s->show_ignored_files) { + dir.nr = 0; + dir.flags = DIR_SHOW_IGNORED | DIR_SHOW_OTHER_DIRECTORIES; + fill_directory(&dir, s->pathspec); + for (i = 0; i < dir.nr; i++) { + struct dir_entry *ent = dir.entries[i]; + if (!cache_name_is_other(ent->name, ent->len)) + continue; + if (!match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL)) + continue; + string_list_insert(ent->name, &s->ignored); + free(ent); + } + } + free(dir.entries); } -- cgit v1.2.1 From 1b908b6fb48f4f8009804c097b14106df548247c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 10 Apr 2010 00:19:46 -0700 Subject: wt-status: rename and restructure status-print-untracked I will be reusing this to show ignored stuff in the next patch. Signed-off-by: Junio C Hamano --- wt-status.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index f13c7da64f..2c9a05dcb4 100644 --- a/wt-status.c +++ b/wt-status.c @@ -97,13 +97,15 @@ static void wt_status_print_dirty_header(struct wt_status *s, color_fprintf_ln(s->fp, c, "#"); } -static void wt_status_print_untracked_header(struct wt_status *s) +static void wt_status_print_other_header(struct wt_status *s, + const char *what, + const char *how) { const char *c = color(WT_STATUS_HEADER, s); - color_fprintf_ln(s->fp, c, "# Untracked files:"); + color_fprintf_ln(s->fp, c, "# %s files:", what); if (!advice_status_hints) return; - color_fprintf_ln(s->fp, c, "# (use \"git add ...\" to include in what will be committed)"); + color_fprintf_ln(s->fp, c, "# (use \"git %s ...\" to include in what will be committed)", how); color_fprintf_ln(s->fp, c, "#"); } @@ -541,7 +543,10 @@ static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitt run_command(&sm_summary); } -static void wt_status_print_untracked(struct wt_status *s) +static void wt_status_print_other(struct wt_status *s, + struct string_list *l, + const char *what, + const char *how) { int i; struct strbuf buf = STRBUF_INIT; @@ -549,10 +554,11 @@ static void wt_status_print_untracked(struct wt_status *s) if (!s->untracked.nr) return; - wt_status_print_untracked_header(s); - for (i = 0; i < s->untracked.nr; i++) { + wt_status_print_other_header(s, what, how); + + for (i = 0; i < l->nr; i++) { struct string_list_item *it; - it = &(s->untracked.items[i]); + it = &(l->items[i]); color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t"); color_fprintf_ln(s->fp, color(WT_STATUS_UNTRACKED, s), "%s", quote_path(it->string, strlen(it->string), @@ -641,7 +647,7 @@ void wt_status_print(struct wt_status *s) wt_status_print_submodule_summary(s, 1); /* unstaged */ } if (s->show_untracked_files) - wt_status_print_untracked(s); + wt_status_print_other(s, &s->untracked, "Untracked", "add"); else if (s->commitable) fprintf(s->fp, "# Untracked files not listed (use -u option to show untracked files)\n"); -- cgit v1.2.1 From 2381e39e5ff740883b98c5aca019950f9167b67f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 10 Apr 2010 00:33:17 -0700 Subject: status: --ignored option shows ignored files There is no stronger reason behind the choice of "!!" than just I happened to have typed them. Signed-off-by: Junio C Hamano --- wt-status.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 2c9a05dcb4..7bda9953e0 100644 --- a/wt-status.c +++ b/wt-status.c @@ -646,9 +646,11 @@ void wt_status_print(struct wt_status *s) wt_status_print_submodule_summary(s, 0); /* staged */ wt_status_print_submodule_summary(s, 1); /* unstaged */ } - if (s->show_untracked_files) + if (s->show_untracked_files) { wt_status_print_other(s, &s->untracked, "Untracked", "add"); - else if (s->commitable) + if (s->show_ignored_files) + wt_status_print_other(s, &s->ignored, "Ignored", "add -f"); + } else if (s->commitable) fprintf(s->fp, "# Untracked files not listed (use -u option to show untracked files)\n"); if (s->verbose) @@ -730,16 +732,16 @@ static void wt_shortstatus_status(int null_termination, struct string_list_item } } -static void wt_shortstatus_untracked(int null_termination, struct string_list_item *it, - struct wt_status *s) +static void wt_shortstatus_other(int null_termination, struct string_list_item *it, + struct wt_status *s, const char *sign) { if (null_termination) { - fprintf(stdout, "?? %s%c", it->string, 0); + fprintf(stdout, "%s %s%c", sign, it->string, 0); } else { struct strbuf onebuf = STRBUF_INIT; const char *one; one = quote_path(it->string, -1, &onebuf, s->prefix); - color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), "??"); + color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), sign); printf(" %s\n", one); strbuf_release(&onebuf); } @@ -763,7 +765,13 @@ void wt_shortstatus_print(struct wt_status *s, int null_termination) struct string_list_item *it; it = &(s->untracked.items[i]); - wt_shortstatus_untracked(null_termination, it, s); + wt_shortstatus_other(null_termination, 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, "!!"); } } -- cgit v1.2.1 From c1909e72952ec6b95f819a4ad8faa8d69f1d961d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 1 May 2010 22:05:14 -0700 Subject: wt-status: fix 'fprintf' compilation warning color_fprintf() has the same function signature as fprintf() and newer gcc warns when a non-constant string is fed as the format Signed-off-by: Junio C Hamano --- wt-status.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 7bda9953e0..84a9002b8e 100644 --- a/wt-status.c +++ b/wt-status.c @@ -741,7 +741,7 @@ static void wt_shortstatus_other(int null_termination, struct string_list_item * struct strbuf onebuf = STRBUF_INIT; const char *one; one = quote_path(it->string, -1, &onebuf, s->prefix); - color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), sign); + color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), "%s", sign); printf(" %s\n", one); strbuf_release(&onebuf); } -- cgit v1.2.1 From 980bde389491e65df3a6f26f755064013b65740c Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Thu, 22 Apr 2010 22:30:20 +0200 Subject: wt-status: take advice.statusHints seriously Currently, status gives a lot of hints even when advice.statusHints is false. Change this so that all hints depend on the config variable. Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano --- wt-status.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 8ca59a2d2a..d44486c826 100644 --- a/wt-status.c +++ b/wt-status.c @@ -625,7 +625,9 @@ void wt_status_print(struct wt_status *s) if (s->show_untracked_files) wt_status_print_untracked(s); else if (s->commitable) - fprintf(s->fp, "# Untracked files not listed (use -u option to show untracked files)\n"); + fprintf(s->fp, "# Untracked files not listed%s\n", + advice_status_hints + ? " (use -u option to show untracked files)" : ""); if (s->verbose) wt_status_print_verbose(s); @@ -635,15 +637,22 @@ void wt_status_print(struct wt_status *s) else if (s->nowarn) ; /* nothing */ else if (s->workdir_dirty) - printf("no changes added to commit (use \"git add\" and/or \"git commit -a\")\n"); + printf("no changes added to commit%s\n", + advice_status_hints + ? " (use \"git add\" and/or \"git commit -a\")" : ""); else if (s->untracked.nr) - printf("nothing added to commit but untracked files present (use \"git add\" to track)\n"); + printf("nothing added to commit but untracked files present%s\n", + advice_status_hints + ? " (use \"git add\" to track)" : ""); else if (s->is_initial) - printf("nothing to commit (create/copy files and use \"git add\" to track)\n"); + printf("nothing to commit%s\n", advice_status_hints + ? " (create/copy files and use \"git add\" to track)" : ""); else if (!s->show_untracked_files) - printf("nothing to commit (use -u to show untracked files)\n"); + printf("nothing to commit%s\n", advice_status_hints + ? " (use -u to show untracked files)" : ""); else - printf("nothing to commit (working directory clean)\n"); + printf("nothing to commit%s\n", advice_status_hints + ? " (working directory clean)" : ""); } } -- cgit v1.2.1 From 66dbfd55e38128db02eb340fcd89f54b734d4c6e Mon Sep 17 00:00:00 2001 From: "Gary V. Vaughan" Date: Fri, 14 May 2010 09:31:33 +0000 Subject: Rewrite dynamic structure initializations to runtime assignment Unfortunately, there are still plenty of production systems with vendor compilers that choke unless all compound declarations can be determined statically at compile time, for example hpux10.20 (I can provide a comprehensive list of our supported platforms that exhibit this problem if necessary). This patch simply breaks apart any compound declarations with dynamic initialisation expressions, and moves the initialisation until after the last declaration in the same block, in all the places necessary to have the offending compilers accept the code. Signed-off-by: Gary V. Vaughan Signed-off-by: Junio C Hamano --- wt-status.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 8ca59a2d2a..24bbd8b915 100644 --- a/wt-status.c +++ b/wt-status.c @@ -498,17 +498,18 @@ static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitt struct child_process sm_summary; char summary_limit[64]; char index[PATH_MAX]; - const char *env[] = { index, NULL }; - const char *argv[] = { - "submodule", - "summary", - uncommitted ? "--files" : "--cached", - "--for-status", - "--summary-limit", - summary_limit, - uncommitted ? NULL : (s->amend ? "HEAD^" : "HEAD"), - NULL - }; + const char *env[] = { NULL, NULL }; + const char *argv[8]; + + env[0] = index; + argv[0] = "submodule"; + argv[1] = "summary"; + argv[2] = uncommitted ? "--files" : "--cached"; + argv[3] = "--for-status"; + argv[4] = "--summary-limit"; + argv[5] = summary_limit; + argv[6] = uncommitted ? NULL : (s->amend ? "HEAD^" : "HEAD"); + argv[7] = NULL; sprintf(summary_limit, "%d", s->submodule_summary); snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", s->index_file); -- cgit v1.2.1 From 05a59a087c29c0b5dd267ec0bd488829427cc3d7 Mon Sep 17 00:00:00 2001 From: Daniel Knittl-Frank Date: Tue, 25 May 2010 15:45:51 +0200 Subject: Show branch information in short output of git status This patch adds a first line in the output of `git status -s` when given the option `-b` or `--branch`, showing which branch the user is currently on, and in case of tracking branches the number of commits on each branch. Signed-off-by: Daniel Knittl-Frank Signed-off-by: Junio C Hamano --- wt-status.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 14e0acce8c..636ecdd896 100644 --- a/wt-status.c +++ b/wt-status.c @@ -9,6 +9,7 @@ #include "quote.h" #include "run-command.h" #include "remote.h" +#include "refs.h" static char default_wt_status_colors[][COLOR_MAXLEN] = { GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */ @@ -17,6 +18,8 @@ static char default_wt_status_colors[][COLOR_MAXLEN] = { GIT_COLOR_RED, /* WT_STATUS_UNTRACKED */ GIT_COLOR_RED, /* WT_STATUS_NOBRANCH */ GIT_COLOR_RED, /* WT_STATUS_UNMERGED */ + GIT_COLOR_GREEN, /* WT_STATUS_LOCAL_BRANCH */ + GIT_COLOR_RED, /* WT_STATUS_REMOTE_BRANCH */ }; static const char *color(int slot, struct wt_status *s) @@ -756,9 +759,69 @@ static void wt_shortstatus_other(int null_termination, struct string_list_item * } } -void wt_shortstatus_print(struct wt_status *s, int null_termination) +static void wt_shortstatus_print_tracking(struct wt_status *s) +{ + struct branch *branch; + const char *header_color = color(WT_STATUS_HEADER, s); + const char *branch_color_local = color(WT_STATUS_LOCAL_BRANCH, s); + const char *branch_color_remote = color(WT_STATUS_REMOTE_BRANCH, s); + + const char *base; + const char *branch_name; + int num_ours, num_theirs; + + color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "## "); + + if (!s->branch) + return; + branch_name = s->branch; + + if (!prefixcmp(branch_name, "refs/heads/")) + branch_name += 11; + else if (!strcmp(branch_name, "HEAD")) { + branch_name = "HEAD (no branch)"; + branch_color_local = color(WT_STATUS_NOBRANCH, s); + } + + branch = branch_get(s->branch + 11); + 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); + return; + } + + base = branch->merge[0]->dst; + base = shorten_unambiguous_ref(base, 0); + color_fprintf(s->fp, branch_color_local, "%s", branch_name); + color_fprintf(s->fp, header_color, "..."); + color_fprintf(s->fp, branch_color_remote, "%s", base); + + color_fprintf(s->fp, header_color, " ["); + if (!num_ours) { + color_fprintf(s->fp, header_color, "behind "); + color_fprintf(s->fp, branch_color_remote, "%d", num_theirs); + } else if (!num_theirs) { + color_fprintf(s->fp, header_color, "ahead "); + color_fprintf(s->fp, branch_color_local, "%d", num_ours); + } else { + color_fprintf(s->fp, header_color, "ahead "); + color_fprintf(s->fp, branch_color_local, "%d", num_ours); + color_fprintf(s->fp, header_color, ", behind "); + color_fprintf(s->fp, branch_color_remote, "%d", num_theirs); + } + + color_fprintf_ln(s->fp, header_color, "]"); +} + +void wt_shortstatus_print(struct wt_status *s, int null_termination, int show_branch) { int i; + + if (show_branch) + wt_shortstatus_print_tracking(s); + for (i = 0; i < s->change.nr; i++) { struct wt_status_change_data *d; struct string_list_item *it; @@ -789,5 +852,5 @@ void wt_porcelain_print(struct wt_status *s, int null_termination) s->use_color = 0; s->relative_paths = 0; s->prefix = NULL; - wt_shortstatus_print(s, null_termination); + wt_shortstatus_print(s, null_termination, 0); } -- cgit v1.2.1 From 46a958b3daa1da336683ec82d7f321d0f51b39c8 Mon Sep 17 00:00:00 2001 From: Jens Lehmann Date: Fri, 25 Jun 2010 16:56:47 +0200 Subject: Add the option "--ignore-submodules" to "git status" In some use cases it is not desirable that "git status" considers submodules that only contain untracked content as dirty. This may happen e.g. when the submodule is not under the developers control and not all build generated files have been added to .gitignore by the upstream developers. Using the "untracked" parameter for the "--ignore-submodules" option disables checking for untracked content and lets git diff report them as changed only when they have new commits or modified content. Sometimes it is not wanted to have submodules show up as changed when they just contain changes to their work tree (this was the behavior before 1.7.0). An example for that are scripts which just want to check for submodule commits while ignoring any changes to the work tree. Also users having large submodules known not to change might want to use this option, as the - sometimes substantial - time it takes to scan the submodule work tree(s) is saved when using the "dirty" parameter. And if you want to ignore any changes to submodules, you can now do that by using this option without parameters or with "all" (when the config option status.submodulesummary is set, using "all" will also suppress the output of the submodule summary). A new function handle_ignore_submodules_arg() is introduced to parse this option new to "git status" in a single location, as "git diff" already knew it. Signed-off-by: Jens Lehmann Signed-off-by: Junio C Hamano --- wt-status.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 8ca59a2d2a..894d66f8fc 100644 --- a/wt-status.c +++ b/wt-status.c @@ -9,6 +9,7 @@ #include "quote.h" #include "run-command.h" #include "remote.h" +#include "submodule.h" static char default_wt_status_colors[][COLOR_MAXLEN] = { GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */ @@ -306,6 +307,8 @@ static void wt_status_collect_changes_worktree(struct wt_status *s) DIFF_OPT_SET(&rev.diffopt, DIRTY_SUBMODULES); if (!s->show_untracked_files) DIFF_OPT_SET(&rev.diffopt, IGNORE_UNTRACKED_IN_SUBMODULES); + if (s->ignore_submodule_arg) + handle_ignore_submodules_arg(&rev.diffopt, s->ignore_submodule_arg); rev.diffopt.format_callback = wt_status_collect_changed_cb; rev.diffopt.format_callback_data = s; rev.prune_data = s->pathspec; @@ -322,6 +325,9 @@ static void wt_status_collect_changes_index(struct wt_status *s) opt.def = s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference; setup_revisions(0, NULL, &rev, &opt); + if (s->ignore_submodule_arg) + handle_ignore_submodules_arg(&rev.diffopt, s->ignore_submodule_arg); + rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK; rev.diffopt.format_callback = wt_status_collect_updated_cb; rev.diffopt.format_callback_data = s; @@ -618,7 +624,9 @@ void wt_status_print(struct wt_status *s) wt_status_print_updated(s); wt_status_print_unmerged(s); wt_status_print_changed(s); - if (s->submodule_summary) { + if (s->submodule_summary && + (!s->ignore_submodule_arg || + strcmp(s->ignore_submodule_arg, "all"))) { wt_status_print_submodule_summary(s, 0); /* staged */ wt_status_print_submodule_summary(s, 1); /* unstaged */ } -- cgit v1.2.1 From 78a395d371ec9fd14297178ec98b8b1042a64fb6 Mon Sep 17 00:00:00 2001 From: Julian Phillips Date: Sat, 26 Jun 2010 00:41:35 +0100 Subject: string_list: Fix argument order for string_list_insert Update the definition and callers of string_list_insert to use the string_list as the first argument. This helps make the string_list API easier to use by being more consistent. Signed-off-by: Julian Phillips Signed-off-by: Junio C Hamano --- wt-status.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 14e0acce8c..1653cfa9d6 100644 --- a/wt-status.c +++ b/wt-status.c @@ -232,7 +232,7 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q, struct wt_status_change_data *d; p = q->queue[i]; - it = string_list_insert(p->one->path, &s->change); + it = string_list_insert(&s->change, p->one->path); d = it->util; if (!d) { d = xcalloc(1, sizeof(*d)); @@ -279,7 +279,7 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q, struct wt_status_change_data *d; p = q->queue[i]; - it = string_list_insert(p->two->path, &s->change); + it = string_list_insert(&s->change, p->two->path); d = it->util; if (!d) { d = xcalloc(1, sizeof(*d)); @@ -346,7 +346,7 @@ static void wt_status_collect_changes_initial(struct wt_status *s) if (!ce_path_match(ce, s->pathspec)) continue; - it = string_list_insert(ce->name, &s->change); + it = string_list_insert(&s->change, ce->name); d = it->util; if (!d) { d = xcalloc(1, sizeof(*d)); @@ -381,7 +381,7 @@ static void wt_status_collect_untracked(struct wt_status *s) continue; if (!match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL)) continue; - string_list_insert(ent->name, &s->untracked); + string_list_insert(&s->untracked, ent->name); free(ent); } @@ -395,7 +395,7 @@ static void wt_status_collect_untracked(struct wt_status *s) continue; if (!match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL)) continue; - string_list_insert(ent->name, &s->ignored); + string_list_insert(&s->ignored, ent->name); free(ent); } } -- cgit v1.2.1 From aee9c7d6540fe6f66fbbe7be420caa26ae0fa2d9 Mon Sep 17 00:00:00 2001 From: Jens Lehmann Date: Fri, 6 Aug 2010 00:39:25 +0200 Subject: Submodules: Add the new "ignore" config option for diff and status The new "ignore" config option controls the default behavior for "git status" and the diff family. It specifies under what circumstances they consider submodules as modified and can be set separately for each submodule. The command line option "--ignore-submodules=" has been extended to accept the new parameter "none" for both status and diff. Users that chose submodules to get rid of long work tree scanning times might want to set the "dirty" option for those submodules. This brings back the pre 1.7.0 behavior, where submodule work trees were never scanned for modifications. By using "--ignore-submodules=none" on the command line the status and diff commands can be told to do a full scan. This option can be set to the following values (which have the same name and meaning as for the "--ignore-submodules" option of status and diff): "all": All changes to the submodule will be ignored. "dirty": Only differences of the commit recorded in the superproject and the submodules HEAD will be considered modifications, all changes to the work tree of the submodule will be ignored. When using this value, the submodule will not be scanned for work tree changes at all, leading to a performance benefit on large submodules. "untracked": Only untracked files in the submodules work tree are ignored, a changed HEAD and/or modified files in the submodule will mark it as modified. "none" (which is the default): Either untracked or modified files in a submodules work tree or a difference between the subdmodules HEAD and the commit recorded in the superproject will make it show up as changed. This value is added as a new parameter for the "--ignore-submodules" option of the diff family and "git status" so the user can override the settings in the configuration. Signed-off-by: Jens Lehmann Signed-off-by: Junio C Hamano --- wt-status.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 2f9e33c8fa..54b6b03b9c 100644 --- a/wt-status.c +++ b/wt-status.c @@ -313,8 +313,10 @@ static void wt_status_collect_changes_worktree(struct wt_status *s) DIFF_OPT_SET(&rev.diffopt, DIRTY_SUBMODULES); if (!s->show_untracked_files) DIFF_OPT_SET(&rev.diffopt, IGNORE_UNTRACKED_IN_SUBMODULES); - if (s->ignore_submodule_arg) + if (s->ignore_submodule_arg) { + DIFF_OPT_SET(&rev.diffopt, OVERRIDE_SUBMODULE_CONFIG); handle_ignore_submodules_arg(&rev.diffopt, s->ignore_submodule_arg); + } rev.diffopt.format_callback = wt_status_collect_changed_cb; rev.diffopt.format_callback_data = s; rev.prune_data = s->pathspec; @@ -331,8 +333,10 @@ static void wt_status_collect_changes_index(struct wt_status *s) opt.def = s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference; setup_revisions(0, NULL, &rev, &opt); - if (s->ignore_submodule_arg) + if (s->ignore_submodule_arg) { + DIFF_OPT_SET(&rev.diffopt, OVERRIDE_SUBMODULE_CONFIG); handle_ignore_submodules_arg(&rev.diffopt, s->ignore_submodule_arg); + } rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK; rev.diffopt.format_callback = wt_status_collect_updated_cb; -- cgit v1.2.1 From b822423ed20df158a478c9522373bffb04fa5ecc Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Sun, 26 Sep 2010 21:49:13 -0500 Subject: wt-status.c: don't leak directory entries when processing untracked,ignored When iterating through the list of directory entries, searching for untracked entries, only the entries added to the string_list were free'd. The rest (tracked or not matching the pathspec) were leaked. Ditto for the "ignored" loop. Rearrange the loops so that all entries are free'd. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- wt-status.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 54b6b03b9c..fc2438f60b 100644 --- a/wt-status.c +++ b/wt-status.c @@ -390,11 +390,9 @@ static void wt_status_collect_untracked(struct wt_status *s) fill_directory(&dir, s->pathspec); for (i = 0; i < dir.nr; i++) { struct dir_entry *ent = dir.entries[i]; - if (!cache_name_is_other(ent->name, ent->len)) - continue; - if (!match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL)) - continue; - string_list_insert(&s->untracked, ent->name); + if (cache_name_is_other(ent->name, ent->len) && + match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL)) + string_list_insert(&s->untracked, ent->name); free(ent); } @@ -404,11 +402,9 @@ static void wt_status_collect_untracked(struct wt_status *s) fill_directory(&dir, s->pathspec); for (i = 0; i < dir.nr; i++) { struct dir_entry *ent = dir.entries[i]; - if (!cache_name_is_other(ent->name, ent->len)) - continue; - if (!match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL)) - continue; - string_list_insert(&s->ignored, ent->name); + if (cache_name_is_other(ent->name, ent->len) && + match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL)) + string_list_insert(&s->ignored, ent->name); free(ent); } } -- cgit v1.2.1 From 8009d83c7e7af0a298ef858609a8201d01086396 Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Tue, 2 Nov 2010 16:31:19 +0100 Subject: Better "Changed but not updated" message in git-status Older Gits talked about "updating" a file to add its content to the index, but this terminology is confusing for new users. "to stage" is far more intuitive and already used in e.g. the "git stage" command name. Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- wt-status.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index fc2438f60b..d9f3d9fe93 100644 --- a/wt-status.c +++ b/wt-status.c @@ -88,7 +88,7 @@ static void wt_status_print_dirty_header(struct wt_status *s, { const char *c = color(WT_STATUS_HEADER, s); - color_fprintf_ln(s->fp, c, "# Changed but not updated:"); + color_fprintf_ln(s->fp, c, "# Changes not staged for commit:"); if (!advice_status_hints) return; if (!has_deleted) -- cgit v1.2.1 From dbfdc625a5aad10c47e3ffa446d0b92e341a7b44 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Mon, 8 Nov 2010 18:44:38 -0800 Subject: status: Quote paths with spaces in short format According to the documentation for git-status, in short-format mode, paths with spaces or unprintable characters are quoted. However 28fba29 (Do not quote SP., 2005-10-17) removed the behavior that quotes paths that have spaces but not unprintable characters. Unfortunately this makes the output of `git status --porcelain` non-parseable in certain (rather unusual) edge cases. In the interest of removing ambiguity when parsing the output of `git status --porcelain`, restore the behavior of quoting paths with spaces in git-status's short-format mode. Signed-off-by: Kevin Ballard Signed-off-by: Junio C Hamano --- wt-status.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index fc2438f60b..9624865e21 100644 --- a/wt-status.c +++ b/wt-status.c @@ -744,10 +744,20 @@ static void wt_shortstatus_status(int null_termination, struct string_list_item const char *one; if (d->head_path) { one = quote_path(d->head_path, -1, &onebuf, s->prefix); + if (*one != '"' && strchr(one, ' ') != NULL) { + putchar('"'); + strbuf_addch(&onebuf, '"'); + one = onebuf.buf; + } printf("%s -> ", one); strbuf_release(&onebuf); } one = quote_path(it->string, -1, &onebuf, s->prefix); + if (*one != '"' && strchr(one, ' ') != NULL) { + putchar('"'); + strbuf_addch(&onebuf, '"'); + one = onebuf.buf; + } printf("%s\n", one); strbuf_release(&onebuf); } -- cgit v1.2.1 From 1d282327d7354dd3a1caefa4af06562aa816710d Mon Sep 17 00:00:00 2001 From: Aleksi Aalto Date: Thu, 18 Nov 2010 01:40:05 +0200 Subject: status: show branchname with a configurable color You can tell "git status" to paint the name of the current branch in its output (the line that says "On branch ...") by setting the configuration variable color.status.branch; it is by default turned off. Signed-off-by: Aleksi Aalto Signed-off-by: Junio C Hamano --- wt-status.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index d9f3d9fe93..19c9cb1d23 100644 --- a/wt-status.c +++ b/wt-status.c @@ -21,6 +21,7 @@ static char default_wt_status_colors[][COLOR_MAXLEN] = { GIT_COLOR_RED, /* WT_STATUS_UNMERGED */ GIT_COLOR_GREEN, /* WT_STATUS_LOCAL_BRANCH */ GIT_COLOR_RED, /* WT_STATUS_REMOTE_BRANCH */ + GIT_COLOR_NORMAL, /* WT_STATUS_ONBRANCH */ }; static const char *color(int slot, struct wt_status *s) @@ -625,7 +626,8 @@ static void wt_status_print_tracking(struct wt_status *s) void wt_status_print(struct wt_status *s) { - const char *branch_color = color(WT_STATUS_HEADER, s); + const char *branch_color = color(WT_STATUS_ONBRANCH, s); + const char *branch_status_color = color(WT_STATUS_HEADER, s); if (s->branch) { const char *on_what = "On branch "; @@ -634,11 +636,12 @@ 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, s); + branch_status_color = color(WT_STATUS_NOBRANCH, s); on_what = "Not currently on any branch."; } color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "# "); - color_fprintf_ln(s->fp, branch_color, "%s%s", on_what, branch_name); + color_fprintf(s->fp, branch_status_color, "%s", on_what); + color_fprintf_ln(s->fp, branch_color, "%s", branch_name); if (!s->is_initial) wt_status_print_tracking(s); } -- cgit v1.2.1 From 148135fc24dce1e61cfd7fcedea4210095099e78 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 9 Dec 2010 12:27:08 -0500 Subject: default color.status.branch to "same as header" This gives it the same behavior as we had prior to 1d28232 (status: show branchname with a configurable color). To do this we need the concept of a "NIL" color, which is provided by color.[ch]. The implementation is very simple; in particular, there are no precautions taken against code accidentally printing the NIL. This should be fine in practice because: 1. You can't input a NIL color in the config, so it must come from the in-code defaults. Which means it is up the client code to handle the NILs it defines. 2. If we do ever print a NIL, it will be obvious what the problem is, and the bug can be fixed. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- wt-status.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 19c9cb1d23..ffe86b9802 100644 --- a/wt-status.c +++ b/wt-status.c @@ -21,12 +21,15 @@ static char default_wt_status_colors[][COLOR_MAXLEN] = { GIT_COLOR_RED, /* WT_STATUS_UNMERGED */ GIT_COLOR_GREEN, /* WT_STATUS_LOCAL_BRANCH */ GIT_COLOR_RED, /* WT_STATUS_REMOTE_BRANCH */ - GIT_COLOR_NORMAL, /* WT_STATUS_ONBRANCH */ + GIT_COLOR_NIL, /* WT_STATUS_ONBRANCH */ }; static const char *color(int slot, struct wt_status *s) { - return s->use_color > 0 ? s->color_palette[slot] : ""; + const char *c = s->use_color > 0 ? s->color_palette[slot] : ""; + if (slot == WT_STATUS_ONBRANCH && color_is_nil(c)) + c = s->color_palette[WT_STATUS_HEADER]; + return c; } void wt_status_prepare(struct wt_status *s) -- cgit v1.2.1 From afe069d16618190a6f7e84ef8451970e274aedb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Fri, 17 Dec 2010 19:43:06 +0700 Subject: struct rev_info: convert prune_data to struct pathspec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- wt-status.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 123582b6cb..1ea330ed17 100644 --- a/wt-status.c +++ b/wt-status.c @@ -323,7 +323,7 @@ static void wt_status_collect_changes_worktree(struct wt_status *s) } rev.diffopt.format_callback = wt_status_collect_changed_cb; rev.diffopt.format_callback_data = s; - rev.prune_data = s->pathspec; + init_pathspec(&rev.prune_data, s->pathspec); run_diff_files(&rev, 0); } @@ -348,7 +348,7 @@ static void wt_status_collect_changes_index(struct wt_status *s) rev.diffopt.detect_rename = 1; rev.diffopt.rename_limit = 200; rev.diffopt.break_opt = 0; - rev.prune_data = s->pathspec; + init_pathspec(&rev.prune_data, s->pathspec); run_diff_index(&rev, 1); } -- cgit v1.2.1 From eb9cb55b944796374402ab4e2639300dc9b0b409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Fri, 17 Dec 2010 19:43:07 +0700 Subject: Convert ce_path_match() to use struct pathspec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- wt-status.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 1ea330ed17..a82b11d341 100644 --- a/wt-status.c +++ b/wt-status.c @@ -354,14 +354,16 @@ static void wt_status_collect_changes_index(struct wt_status *s) static void wt_status_collect_changes_initial(struct wt_status *s) { + struct pathspec pathspec; int i; + init_pathspec(&pathspec, s->pathspec); for (i = 0; i < active_nr; i++) { struct string_list_item *it; struct wt_status_change_data *d; struct cache_entry *ce = active_cache[i]; - if (!ce_path_match(ce, s->pathspec)) + if (!ce_path_match(ce, &pathspec)) continue; it = string_list_insert(&s->change, ce->name); d = it->util; @@ -376,6 +378,7 @@ static void wt_status_collect_changes_initial(struct wt_status *s) else d->index_status = DIFF_STATUS_ADDED; } + free_pathspec(&pathspec); } static void wt_status_collect_untracked(struct wt_status *s) -- cgit v1.2.1 From 37f7a8579363a98efc48dfb6964a519034fc9acc Mon Sep 17 00:00:00 2001 From: Jay Soffian Date: Sat, 19 Feb 2011 23:12:29 -0500 Subject: Teach commit about CHERRY_PICK_HEAD Previously the user was advised to use commit -c CHERRY_PICK_HEAD after a conflicting cherry-pick. While this would preserve the original commit's authorship, it would sadly discard cherry-pick's carefully crafted MERGE_MSG (which contains the list of conflicts as well as the original commit-id in the case of cherry-pick -x). On the other hand, if a bare 'commit' were performed, it would preserve the MERGE_MSG while resetting the authorship. In other words, there was no way to simultaneously take the authorship from CHERRY_PICK_HEAD and the commit message from MERGE_MSG. This change fixes that situation. A bare 'commit' will now take the authorship from CHERRY_PICK_HEAD and the commit message from MERGE_MSG. If the user wishes to reset authorship, that must now be done explicitly via --reset-author. A side-benefit of passing commit authorship along this way is that we can eliminate redundant authorship parsing code from revert.c. (Also removed an unused include from revert.c) Signed-off-by: Jay Soffian Signed-off-by: Junio C Hamano --- wt-status.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 123582b6cb..fbaaf54dad 100644 --- a/wt-status.c +++ b/wt-status.c @@ -60,7 +60,7 @@ static void wt_status_print_unmerged_header(struct wt_status *s) color_fprintf_ln(s->fp, c, "# Unmerged paths:"); if (!advice_status_hints) return; - if (s->in_merge) + if (s->whence != FROM_COMMIT) ; else if (!s->is_initial) color_fprintf_ln(s->fp, c, "# (use \"git reset %s ...\" to unstage)", s->reference); @@ -77,7 +77,7 @@ static void wt_status_print_cached_header(struct wt_status *s) color_fprintf_ln(s->fp, c, "# Changes to be committed:"); if (!advice_status_hints) return; - if (s->in_merge) + if (s->whence != FROM_COMMIT) ; /* NEEDSWORK: use "git reset --unresolve"??? */ else if (!s->is_initial) color_fprintf_ln(s->fp, c, "# (use \"git reset %s ...\" to unstage)", s->reference); -- cgit v1.2.1 From e0335fcdad28da578904bb33fcf1dfbcdf172599 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Fri, 25 Feb 2011 23:09:41 -0600 Subject: wt-status: add helpers for printing wt-status lines Introduce status_printf{,_ln,_more} wrapper functions around color_vfprintf() which take care of adding "#" to the beginning of status lines automatically. The semantics: - status_printf() is just like color_fprintf() but it adds a "# " at the beginning of each line of output; - status_printf_ln() is a convenience function that additionally adds "\n" at the end; - status_printf_more() is a variant of status_printf() used to continue lines that have already started. It suppresses the "#" at the beginning of the first line. Helped-by: Junio C Hamano Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- wt-status.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 123582b6cb..1abd7c3382 100644 --- a/wt-status.c +++ b/wt-status.c @@ -32,6 +32,80 @@ static const char *color(int slot, struct wt_status *s) return c; } +static void status_vprintf(struct wt_status *s, int at_bol, const char *color, + const char *fmt, va_list ap, const char *trail) +{ + struct strbuf sb = STRBUF_INIT; + struct strbuf linebuf = STRBUF_INIT; + const char *line, *eol; + + strbuf_vaddf(&sb, fmt, ap); + if (!sb.len) { + strbuf_addch(&sb, '#'); + if (!trail) + strbuf_addch(&sb, ' '); + color_print_strbuf(s->fp, color, &sb); + if (trail) + fprintf(s->fp, "%s", trail); + strbuf_release(&sb); + return; + } + for (line = sb.buf; *line; line = eol + 1) { + eol = strchr(line, '\n'); + + strbuf_reset(&linebuf); + if (at_bol) { + strbuf_addch(&linebuf, '#'); + if (*line != '\n' && *line != '\t') + strbuf_addch(&linebuf, ' '); + } + if (eol) + strbuf_add(&linebuf, line, eol - line); + else + strbuf_addstr(&linebuf, line); + color_print_strbuf(s->fp, color, &linebuf); + if (eol) + fprintf(s->fp, "\n"); + else + break; + at_bol = 1; + } + if (trail) + fprintf(s->fp, "%s", trail); + strbuf_release(&linebuf); + strbuf_release(&sb); +} + +void status_printf_ln(struct wt_status *s, const char *color, + const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + status_vprintf(s, 1, color, fmt, ap, "\n"); + va_end(ap); +} + +void status_printf(struct wt_status *s, const char *color, + const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + status_vprintf(s, 1, color, fmt, ap, NULL); + va_end(ap); +} + +void status_printf_more(struct wt_status *s, const char *color, + const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + status_vprintf(s, 0, color, fmt, ap, NULL); + va_end(ap); +} + void wt_status_prepare(struct wt_status *s) { unsigned char sha1[20]; -- cgit v1.2.1 From 098d0e0e8e7467bea5306d5bc98b283bfe0174fb Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Fri, 25 Feb 2011 23:11:37 -0600 Subject: commit, status: use status_printf{,_ln,_more} helpers wt-status code is used to provide a reminder of changes included and not included for the commit message template opened in the operator's text editor by "git commit". Therefore each line of its output begins with the comment character "#": # Please enter the commit message for your changes. Lines starting Use the new status_printf{,_ln,_more} functions to take care of adding "#" to the beginning of such status lines automatically. Using these will have two advantages over the current code: - The obvious one is to force separation of the "#" from the translatable part of the message when git learns to translate its output. - Another advantage is that this makes it easier for us to drop "#" prefix in "git status" output in later versions of git if we want to. Explained-by: Junio C Hamano Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- wt-status.c | 86 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 43 insertions(+), 43 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 1abd7c3382..c14cbe48d1 100644 --- a/wt-status.c +++ b/wt-status.c @@ -131,33 +131,33 @@ static void wt_status_print_unmerged_header(struct wt_status *s) { const char *c = color(WT_STATUS_HEADER, s); - color_fprintf_ln(s->fp, c, "# Unmerged paths:"); + status_printf_ln(s, c, "Unmerged paths:"); if (!advice_status_hints) return; if (s->in_merge) ; else if (!s->is_initial) - color_fprintf_ln(s->fp, c, "# (use \"git reset %s ...\" to unstage)", s->reference); + status_printf_ln(s, c, " (use \"git reset %s ...\" to unstage)", s->reference); else - color_fprintf_ln(s->fp, c, "# (use \"git rm --cached ...\" to unstage)"); - color_fprintf_ln(s->fp, c, "# (use \"git add/rm ...\" as appropriate to mark resolution)"); - color_fprintf_ln(s->fp, c, "#"); + status_printf_ln(s, c, " (use \"git rm --cached ...\" to unstage)"); + status_printf_ln(s, c, " (use \"git add/rm ...\" as appropriate to mark resolution)"); + status_printf_ln(s, c, ""); } static void wt_status_print_cached_header(struct wt_status *s) { const char *c = color(WT_STATUS_HEADER, s); - color_fprintf_ln(s->fp, c, "# Changes to be committed:"); + status_printf_ln(s, c, "Changes to be committed:"); if (!advice_status_hints) return; if (s->in_merge) ; /* NEEDSWORK: use "git reset --unresolve"??? */ else if (!s->is_initial) - color_fprintf_ln(s->fp, c, "# (use \"git reset %s ...\" to unstage)", s->reference); + status_printf_ln(s, c, " (use \"git reset %s ...\" to unstage)", s->reference); else - color_fprintf_ln(s->fp, c, "# (use \"git rm --cached ...\" to unstage)"); - color_fprintf_ln(s->fp, c, "#"); + status_printf_ln(s, c, " (use \"git rm --cached ...\" to unstage)"); + status_printf_ln(s, c, ""); } static void wt_status_print_dirty_header(struct wt_status *s, @@ -166,17 +166,17 @@ static void wt_status_print_dirty_header(struct wt_status *s, { const char *c = color(WT_STATUS_HEADER, s); - color_fprintf_ln(s->fp, c, "# Changes not staged for commit:"); + status_printf_ln(s, c, "Changes not staged for commit:"); if (!advice_status_hints) return; if (!has_deleted) - color_fprintf_ln(s->fp, c, "# (use \"git add ...\" to update what will be committed)"); + status_printf_ln(s, 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)"); + status_printf_ln(s, c, " (use \"git add/rm ...\" to update what will be committed)"); + status_printf_ln(s, c, " (use \"git checkout -- ...\" to discard changes in working directory)"); if (has_dirty_submodules) - color_fprintf_ln(s->fp, c, "# (commit or discard the untracked or modified content in submodules)"); - color_fprintf_ln(s->fp, c, "#"); + status_printf_ln(s, c, " (commit or discard the untracked or modified content in submodules)"); + status_printf_ln(s, c, ""); } static void wt_status_print_other_header(struct wt_status *s, @@ -184,16 +184,16 @@ static void wt_status_print_other_header(struct wt_status *s, const char *how) { const char *c = color(WT_STATUS_HEADER, s); - color_fprintf_ln(s->fp, c, "# %s files:", what); + status_printf_ln(s, c, "%s files:", what); if (!advice_status_hints) return; - color_fprintf_ln(s->fp, c, "# (use \"git %s ...\" to include in what will be committed)", how); - color_fprintf_ln(s->fp, c, "#"); + status_printf_ln(s, c, " (use \"git %s ...\" to include in what will be committed)", how); + status_printf_ln(s, c, ""); } static void wt_status_print_trailer(struct wt_status *s) { - color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#"); + status_printf_ln(s, color(WT_STATUS_HEADER, s), ""); } #define quote_path quote_path_relative @@ -207,7 +207,7 @@ static void wt_status_print_unmerged_data(struct wt_status *s, const char *one, *how = "bug"; one = quote_path(it->string, -1, &onebuf, s->prefix); - color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t"); + status_printf(s, color(WT_STATUS_HEADER, s), "\t"); switch (d->stagemask) { case 1: how = "both deleted:"; break; case 2: how = "added by us:"; break; @@ -217,7 +217,7 @@ static void wt_status_print_unmerged_data(struct wt_status *s, case 6: how = "both added:"; break; case 7: how = "both modified:"; break; } - color_fprintf(s->fp, c, "%-20s%s\n", how, one); + status_printf_more(s, c, "%-20s%s\n", how, one); strbuf_release(&onebuf); } @@ -260,40 +260,40 @@ static void wt_status_print_change_data(struct wt_status *s, one = quote_path(one_name, -1, &onebuf, s->prefix); two = quote_path(two_name, -1, &twobuf, s->prefix); - color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t"); + status_printf(s, color(WT_STATUS_HEADER, s), "\t"); switch (status) { case DIFF_STATUS_ADDED: - color_fprintf(s->fp, c, "new file: %s", one); + status_printf_more(s, c, "new file: %s", one); break; case DIFF_STATUS_COPIED: - color_fprintf(s->fp, c, "copied: %s -> %s", one, two); + status_printf_more(s, c, "copied: %s -> %s", one, two); break; case DIFF_STATUS_DELETED: - color_fprintf(s->fp, c, "deleted: %s", one); + status_printf_more(s, c, "deleted: %s", one); break; case DIFF_STATUS_MODIFIED: - color_fprintf(s->fp, c, "modified: %s", one); + status_printf_more(s, c, "modified: %s", one); break; case DIFF_STATUS_RENAMED: - color_fprintf(s->fp, c, "renamed: %s -> %s", one, two); + status_printf_more(s, c, "renamed: %s -> %s", one, two); break; case DIFF_STATUS_TYPE_CHANGED: - color_fprintf(s->fp, c, "typechange: %s", one); + status_printf_more(s, c, "typechange: %s", one); break; case DIFF_STATUS_UNKNOWN: - color_fprintf(s->fp, c, "unknown: %s", one); + status_printf_more(s, c, "unknown: %s", one); break; case DIFF_STATUS_UNMERGED: - color_fprintf(s->fp, c, "unmerged: %s", one); + status_printf_more(s, c, "unmerged: %s", one); break; default: die("bug: unhandled diff status %c", status); } if (extra.len) { - color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "%s", extra.buf); + status_printf_more(s, color(WT_STATUS_HEADER, s), "%s", extra.buf); strbuf_release(&extra); } - fprintf(s->fp, "\n"); + status_printf_more(s, GIT_COLOR_NORMAL, "\n"); strbuf_release(&onebuf); strbuf_release(&twobuf); } @@ -647,9 +647,9 @@ static void wt_status_print_other(struct wt_status *s, for (i = 0; i < l->nr; i++) { struct string_list_item *it; it = &(l->items[i]); - color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t"); - color_fprintf_ln(s->fp, color(WT_STATUS_UNTRACKED, s), "%s", - quote_path(it->string, strlen(it->string), + 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)); } strbuf_release(&buf); @@ -716,17 +716,17 @@ void wt_status_print(struct wt_status *s) branch_status_color = color(WT_STATUS_NOBRANCH, s); on_what = "Not currently on any branch."; } - color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "# "); - color_fprintf(s->fp, branch_status_color, "%s", on_what); - color_fprintf_ln(s->fp, branch_color, "%s", branch_name); + status_printf(s, color(WT_STATUS_HEADER, s), ""); + status_printf_more(s, branch_status_color, "%s", on_what); + status_printf_more(s, branch_color, "%s\n", branch_name); if (!s->is_initial) wt_status_print_tracking(s); } if (s->is_initial) { - color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#"); - color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "# Initial commit"); - color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#"); + status_printf_ln(s, color(WT_STATUS_HEADER, s), ""); + status_printf_ln(s, color(WT_STATUS_HEADER, s), "Initial commit"); + status_printf_ln(s, color(WT_STATUS_HEADER, s), ""); } wt_status_print_updated(s); @@ -743,7 +743,7 @@ void wt_status_print(struct wt_status *s) if (s->show_ignored_files) wt_status_print_other(s, &s->ignored, "Ignored", "add -f"); } else if (s->commitable) - fprintf(s->fp, "# Untracked files not listed%s\n", + status_printf_ln(s, GIT_COLOR_NORMAL, "Untracked files not listed%s", advice_status_hints ? " (use -u option to show untracked files)" : ""); @@ -751,7 +751,7 @@ void wt_status_print(struct wt_status *s) wt_status_print_verbose(s); if (!s->commitable) { if (s->amend) - fprintf(s->fp, "# No changes\n"); + status_printf_ln(s, GIT_COLOR_NORMAL, "No changes"); else if (s->nowarn) ; /* nothing */ else if (s->workdir_dirty) -- cgit v1.2.1 From becbdae82bb8bb193c2f1e9d8b32a60bdef8b0e4 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Fri, 25 Feb 2011 23:09:41 -0600 Subject: wt-status: add helpers for printing wt-status lines Introduce status_printf{,_ln,_more} wrapper functions around color_vfprintf() which take care of adding "#" to the beginning of status lines automatically. The semantics: - status_printf() is just like color_fprintf() but it adds a "# " at the beginning of each line of output; - status_printf_ln() is a convenience function that additionally adds "\n" at the end; - status_printf_more() is a variant of status_printf() used to continue lines that have already started. It suppresses the "#" at the beginning of the first line. Helped-by: Junio C Hamano Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- wt-status.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 123582b6cb..1abd7c3382 100644 --- a/wt-status.c +++ b/wt-status.c @@ -32,6 +32,80 @@ static const char *color(int slot, struct wt_status *s) return c; } +static void status_vprintf(struct wt_status *s, int at_bol, const char *color, + const char *fmt, va_list ap, const char *trail) +{ + struct strbuf sb = STRBUF_INIT; + struct strbuf linebuf = STRBUF_INIT; + const char *line, *eol; + + strbuf_vaddf(&sb, fmt, ap); + if (!sb.len) { + strbuf_addch(&sb, '#'); + if (!trail) + strbuf_addch(&sb, ' '); + color_print_strbuf(s->fp, color, &sb); + if (trail) + fprintf(s->fp, "%s", trail); + strbuf_release(&sb); + return; + } + for (line = sb.buf; *line; line = eol + 1) { + eol = strchr(line, '\n'); + + strbuf_reset(&linebuf); + if (at_bol) { + strbuf_addch(&linebuf, '#'); + if (*line != '\n' && *line != '\t') + strbuf_addch(&linebuf, ' '); + } + if (eol) + strbuf_add(&linebuf, line, eol - line); + else + strbuf_addstr(&linebuf, line); + color_print_strbuf(s->fp, color, &linebuf); + if (eol) + fprintf(s->fp, "\n"); + else + break; + at_bol = 1; + } + if (trail) + fprintf(s->fp, "%s", trail); + strbuf_release(&linebuf); + strbuf_release(&sb); +} + +void status_printf_ln(struct wt_status *s, const char *color, + const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + status_vprintf(s, 1, color, fmt, ap, "\n"); + va_end(ap); +} + +void status_printf(struct wt_status *s, const char *color, + const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + status_vprintf(s, 1, color, fmt, ap, NULL); + va_end(ap); +} + +void status_printf_more(struct wt_status *s, const char *color, + const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + status_vprintf(s, 0, color, fmt, ap, NULL); + va_end(ap); +} + void wt_status_prepare(struct wt_status *s) { unsigned char sha1[20]; -- cgit v1.2.1 From b926c0d10df6c5bdc8bf9a2fc1431e8edb673e4d Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Fri, 25 Feb 2011 23:11:37 -0600 Subject: commit, status: use status_printf{,_ln,_more} helpers wt-status code is used to provide a reminder of changes included and not included for the commit message template opened in the operator's text editor by "git commit". Therefore each line of its output begins with the comment character "#": # Please enter the commit message for your changes. Lines starting Use the new status_printf{,_ln,_more} functions to take care of adding "#" to the beginning of such status lines automatically. Using these will have two advantages over the current code: - The obvious one is to force separation of the "#" from the translatable part of the message when git learns to translate its output. - Another advantage is that this makes it easier for us to drop "#" prefix in "git status" output in later versions of git if we want to. Explained-by: Junio C Hamano Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- wt-status.c | 86 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 43 insertions(+), 43 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 1abd7c3382..c14cbe48d1 100644 --- a/wt-status.c +++ b/wt-status.c @@ -131,33 +131,33 @@ static void wt_status_print_unmerged_header(struct wt_status *s) { const char *c = color(WT_STATUS_HEADER, s); - color_fprintf_ln(s->fp, c, "# Unmerged paths:"); + status_printf_ln(s, c, "Unmerged paths:"); if (!advice_status_hints) return; if (s->in_merge) ; else if (!s->is_initial) - color_fprintf_ln(s->fp, c, "# (use \"git reset %s ...\" to unstage)", s->reference); + status_printf_ln(s, c, " (use \"git reset %s ...\" to unstage)", s->reference); else - color_fprintf_ln(s->fp, c, "# (use \"git rm --cached ...\" to unstage)"); - color_fprintf_ln(s->fp, c, "# (use \"git add/rm ...\" as appropriate to mark resolution)"); - color_fprintf_ln(s->fp, c, "#"); + status_printf_ln(s, c, " (use \"git rm --cached ...\" to unstage)"); + status_printf_ln(s, c, " (use \"git add/rm ...\" as appropriate to mark resolution)"); + status_printf_ln(s, c, ""); } static void wt_status_print_cached_header(struct wt_status *s) { const char *c = color(WT_STATUS_HEADER, s); - color_fprintf_ln(s->fp, c, "# Changes to be committed:"); + status_printf_ln(s, c, "Changes to be committed:"); if (!advice_status_hints) return; if (s->in_merge) ; /* NEEDSWORK: use "git reset --unresolve"??? */ else if (!s->is_initial) - color_fprintf_ln(s->fp, c, "# (use \"git reset %s ...\" to unstage)", s->reference); + status_printf_ln(s, c, " (use \"git reset %s ...\" to unstage)", s->reference); else - color_fprintf_ln(s->fp, c, "# (use \"git rm --cached ...\" to unstage)"); - color_fprintf_ln(s->fp, c, "#"); + status_printf_ln(s, c, " (use \"git rm --cached ...\" to unstage)"); + status_printf_ln(s, c, ""); } static void wt_status_print_dirty_header(struct wt_status *s, @@ -166,17 +166,17 @@ static void wt_status_print_dirty_header(struct wt_status *s, { const char *c = color(WT_STATUS_HEADER, s); - color_fprintf_ln(s->fp, c, "# Changes not staged for commit:"); + status_printf_ln(s, c, "Changes not staged for commit:"); if (!advice_status_hints) return; if (!has_deleted) - color_fprintf_ln(s->fp, c, "# (use \"git add ...\" to update what will be committed)"); + status_printf_ln(s, 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)"); + status_printf_ln(s, c, " (use \"git add/rm ...\" to update what will be committed)"); + status_printf_ln(s, c, " (use \"git checkout -- ...\" to discard changes in working directory)"); if (has_dirty_submodules) - color_fprintf_ln(s->fp, c, "# (commit or discard the untracked or modified content in submodules)"); - color_fprintf_ln(s->fp, c, "#"); + status_printf_ln(s, c, " (commit or discard the untracked or modified content in submodules)"); + status_printf_ln(s, c, ""); } static void wt_status_print_other_header(struct wt_status *s, @@ -184,16 +184,16 @@ static void wt_status_print_other_header(struct wt_status *s, const char *how) { const char *c = color(WT_STATUS_HEADER, s); - color_fprintf_ln(s->fp, c, "# %s files:", what); + status_printf_ln(s, c, "%s files:", what); if (!advice_status_hints) return; - color_fprintf_ln(s->fp, c, "# (use \"git %s ...\" to include in what will be committed)", how); - color_fprintf_ln(s->fp, c, "#"); + status_printf_ln(s, c, " (use \"git %s ...\" to include in what will be committed)", how); + status_printf_ln(s, c, ""); } static void wt_status_print_trailer(struct wt_status *s) { - color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#"); + status_printf_ln(s, color(WT_STATUS_HEADER, s), ""); } #define quote_path quote_path_relative @@ -207,7 +207,7 @@ static void wt_status_print_unmerged_data(struct wt_status *s, const char *one, *how = "bug"; one = quote_path(it->string, -1, &onebuf, s->prefix); - color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t"); + status_printf(s, color(WT_STATUS_HEADER, s), "\t"); switch (d->stagemask) { case 1: how = "both deleted:"; break; case 2: how = "added by us:"; break; @@ -217,7 +217,7 @@ static void wt_status_print_unmerged_data(struct wt_status *s, case 6: how = "both added:"; break; case 7: how = "both modified:"; break; } - color_fprintf(s->fp, c, "%-20s%s\n", how, one); + status_printf_more(s, c, "%-20s%s\n", how, one); strbuf_release(&onebuf); } @@ -260,40 +260,40 @@ static void wt_status_print_change_data(struct wt_status *s, one = quote_path(one_name, -1, &onebuf, s->prefix); two = quote_path(two_name, -1, &twobuf, s->prefix); - color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t"); + status_printf(s, color(WT_STATUS_HEADER, s), "\t"); switch (status) { case DIFF_STATUS_ADDED: - color_fprintf(s->fp, c, "new file: %s", one); + status_printf_more(s, c, "new file: %s", one); break; case DIFF_STATUS_COPIED: - color_fprintf(s->fp, c, "copied: %s -> %s", one, two); + status_printf_more(s, c, "copied: %s -> %s", one, two); break; case DIFF_STATUS_DELETED: - color_fprintf(s->fp, c, "deleted: %s", one); + status_printf_more(s, c, "deleted: %s", one); break; case DIFF_STATUS_MODIFIED: - color_fprintf(s->fp, c, "modified: %s", one); + status_printf_more(s, c, "modified: %s", one); break; case DIFF_STATUS_RENAMED: - color_fprintf(s->fp, c, "renamed: %s -> %s", one, two); + status_printf_more(s, c, "renamed: %s -> %s", one, two); break; case DIFF_STATUS_TYPE_CHANGED: - color_fprintf(s->fp, c, "typechange: %s", one); + status_printf_more(s, c, "typechange: %s", one); break; case DIFF_STATUS_UNKNOWN: - color_fprintf(s->fp, c, "unknown: %s", one); + status_printf_more(s, c, "unknown: %s", one); break; case DIFF_STATUS_UNMERGED: - color_fprintf(s->fp, c, "unmerged: %s", one); + status_printf_more(s, c, "unmerged: %s", one); break; default: die("bug: unhandled diff status %c", status); } if (extra.len) { - color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "%s", extra.buf); + status_printf_more(s, color(WT_STATUS_HEADER, s), "%s", extra.buf); strbuf_release(&extra); } - fprintf(s->fp, "\n"); + status_printf_more(s, GIT_COLOR_NORMAL, "\n"); strbuf_release(&onebuf); strbuf_release(&twobuf); } @@ -647,9 +647,9 @@ static void wt_status_print_other(struct wt_status *s, for (i = 0; i < l->nr; i++) { struct string_list_item *it; it = &(l->items[i]); - color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t"); - color_fprintf_ln(s->fp, color(WT_STATUS_UNTRACKED, s), "%s", - quote_path(it->string, strlen(it->string), + 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)); } strbuf_release(&buf); @@ -716,17 +716,17 @@ void wt_status_print(struct wt_status *s) branch_status_color = color(WT_STATUS_NOBRANCH, s); on_what = "Not currently on any branch."; } - color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "# "); - color_fprintf(s->fp, branch_status_color, "%s", on_what); - color_fprintf_ln(s->fp, branch_color, "%s", branch_name); + status_printf(s, color(WT_STATUS_HEADER, s), ""); + status_printf_more(s, branch_status_color, "%s", on_what); + status_printf_more(s, branch_color, "%s\n", branch_name); if (!s->is_initial) wt_status_print_tracking(s); } if (s->is_initial) { - color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#"); - color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "# Initial commit"); - color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#"); + status_printf_ln(s, color(WT_STATUS_HEADER, s), ""); + status_printf_ln(s, color(WT_STATUS_HEADER, s), "Initial commit"); + status_printf_ln(s, color(WT_STATUS_HEADER, s), ""); } wt_status_print_updated(s); @@ -743,7 +743,7 @@ void wt_status_print(struct wt_status *s) if (s->show_ignored_files) wt_status_print_other(s, &s->ignored, "Ignored", "add -f"); } else if (s->commitable) - fprintf(s->fp, "# Untracked files not listed%s\n", + status_printf_ln(s, GIT_COLOR_NORMAL, "Untracked files not listed%s", advice_status_hints ? " (use -u option to show untracked files)" : ""); @@ -751,7 +751,7 @@ void wt_status_print(struct wt_status *s) wt_status_print_verbose(s); if (!s->commitable) { if (s->amend) - fprintf(s->fp, "# No changes\n"); + status_printf_ln(s, GIT_COLOR_NORMAL, "No changes"); else if (s->nowarn) ; /* nothing */ else if (s->workdir_dirty) -- cgit v1.2.1 From 355ec7a1303af862a76961603ea2a2a11a0d204c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 22 Feb 2011 23:42:13 +0000 Subject: i18n: git-status basic messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gettextize the most common git-status messages. Many tests checked for these explicitly. Change them to skip under GETTEXT_POISON=YesPlease. Some of the tests in t7508-status.sh needed to be split up when I added C_LOCALE_OUTPUT to them, since parts of them affected later tests (some of which aren't being skipped) indirectly. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- wt-status.c | 86 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 43 insertions(+), 43 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index c14cbe48d1..055022241f 100644 --- a/wt-status.c +++ b/wt-status.c @@ -131,16 +131,16 @@ static void wt_status_print_unmerged_header(struct wt_status *s) { const char *c = color(WT_STATUS_HEADER, s); - status_printf_ln(s, c, "Unmerged paths:"); + status_printf_ln(s, c, _("Unmerged paths:")); if (!advice_status_hints) return; if (s->in_merge) ; else if (!s->is_initial) - status_printf_ln(s, c, " (use \"git reset %s ...\" to unstage)", s->reference); + status_printf_ln(s, c, _(" (use \"git reset %s ...\" to unstage)"), s->reference); else - status_printf_ln(s, c, " (use \"git rm --cached ...\" to unstage)"); - status_printf_ln(s, c, " (use \"git add/rm ...\" as appropriate to mark resolution)"); + status_printf_ln(s, c, _(" (use \"git rm --cached ...\" to unstage)")); + status_printf_ln(s, c, _(" (use \"git add/rm ...\" as appropriate to mark resolution)")); status_printf_ln(s, c, ""); } @@ -154,9 +154,9 @@ static void wt_status_print_cached_header(struct wt_status *s) if (s->in_merge) ; /* NEEDSWORK: use "git reset --unresolve"??? */ else if (!s->is_initial) - status_printf_ln(s, c, " (use \"git reset %s ...\" to unstage)", s->reference); + status_printf_ln(s, c, _(" (use \"git reset %s ...\" to unstage)"), s->reference); else - status_printf_ln(s, c, " (use \"git rm --cached ...\" to unstage)"); + status_printf_ln(s, c, _(" (use \"git rm --cached ...\" to unstage)")); status_printf_ln(s, c, ""); } @@ -166,16 +166,16 @@ static void wt_status_print_dirty_header(struct wt_status *s, { const char *c = color(WT_STATUS_HEADER, s); - status_printf_ln(s, c, "Changes not staged for commit:"); + status_printf_ln(s, c, _("Changes not staged for commit:")); if (!advice_status_hints) return; if (!has_deleted) - status_printf_ln(s, c, " (use \"git add ...\" to update what will be committed)"); + status_printf_ln(s, c, _(" (use \"git add ...\" to update what will be committed)")); else - status_printf_ln(s, c, " (use \"git add/rm ...\" to update what will be committed)"); - status_printf_ln(s, c, " (use \"git checkout -- ...\" to discard changes in working directory)"); + status_printf_ln(s, c, _(" (use \"git add/rm ...\" to update what will be committed)")); + status_printf_ln(s, c, _(" (use \"git checkout -- ...\" to discard changes in working directory)")); if (has_dirty_submodules) - status_printf_ln(s, c, " (commit or discard the untracked or modified content in submodules)"); + status_printf_ln(s, c, _(" (commit or discard the untracked or modified content in submodules)")); status_printf_ln(s, c, ""); } @@ -184,10 +184,10 @@ static void wt_status_print_other_header(struct wt_status *s, const char *how) { const char *c = color(WT_STATUS_HEADER, s); - status_printf_ln(s, c, "%s files:", what); + status_printf_ln(s, c, _("%s files:"), what); if (!advice_status_hints) return; - status_printf_ln(s, c, " (use \"git %s ...\" to include in what will be committed)", how); + status_printf_ln(s, c, _(" (use \"git %s ...\" to include in what will be committed)"), how); status_printf_ln(s, c, ""); } @@ -204,18 +204,18 @@ static void wt_status_print_unmerged_data(struct wt_status *s, const char *c = color(WT_STATUS_UNMERGED, s); struct wt_status_change_data *d = it->util; struct strbuf onebuf = STRBUF_INIT; - const char *one, *how = "bug"; + const char *one, *how = _("bug"); one = quote_path(it->string, -1, &onebuf, s->prefix); status_printf(s, color(WT_STATUS_HEADER, s), "\t"); switch (d->stagemask) { - case 1: how = "both deleted:"; break; - case 2: how = "added by us:"; break; - case 3: how = "deleted by them:"; break; - case 4: how = "added by them:"; break; - case 5: how = "deleted by us:"; break; - case 6: how = "both added:"; break; - case 7: how = "both modified:"; break; + case 1: how = _("both deleted:"); break; + case 2: how = _("added by us:"); break; + case 3: how = _("deleted by them:"); break; + case 4: how = _("added by them:"); break; + case 5: how = _("deleted by us:"); break; + case 6: how = _("both added:"); break; + case 7: how = _("both modified:"); break; } status_printf_more(s, c, "%-20s%s\n", how, one); strbuf_release(&onebuf); @@ -245,11 +245,11 @@ static void wt_status_print_change_data(struct wt_status *s, if (d->new_submodule_commits || d->dirty_submodule) { strbuf_addstr(&extra, " ("); if (d->new_submodule_commits) - strbuf_addf(&extra, "new commits, "); + strbuf_addf(&extra, _("new commits, ")); if (d->dirty_submodule & DIRTY_SUBMODULE_MODIFIED) - strbuf_addf(&extra, "modified content, "); + strbuf_addf(&extra, _("modified content, ")); if (d->dirty_submodule & DIRTY_SUBMODULE_UNTRACKED) - strbuf_addf(&extra, "untracked content, "); + strbuf_addf(&extra, _("untracked content, ")); strbuf_setlen(&extra, extra.len - 2); strbuf_addch(&extra, ')'); } @@ -263,31 +263,31 @@ static void wt_status_print_change_data(struct wt_status *s, status_printf(s, color(WT_STATUS_HEADER, s), "\t"); switch (status) { case DIFF_STATUS_ADDED: - status_printf_more(s, c, "new file: %s", one); + status_printf_more(s, c, _("new file: %s"), one); break; case DIFF_STATUS_COPIED: - status_printf_more(s, c, "copied: %s -> %s", one, two); + status_printf_more(s, c, _("copied: %s -> %s"), one, two); break; case DIFF_STATUS_DELETED: - status_printf_more(s, c, "deleted: %s", one); + status_printf_more(s, c, _("deleted: %s"), one); break; case DIFF_STATUS_MODIFIED: - status_printf_more(s, c, "modified: %s", one); + status_printf_more(s, c, _("modified: %s"), one); break; case DIFF_STATUS_RENAMED: status_printf_more(s, c, "renamed: %s -> %s", one, two); break; case DIFF_STATUS_TYPE_CHANGED: - status_printf_more(s, c, "typechange: %s", one); + status_printf_more(s, c, _("typechange: %s"), one); break; case DIFF_STATUS_UNKNOWN: - status_printf_more(s, c, "unknown: %s", one); + status_printf_more(s, c, _("unknown: %s"), one); break; case DIFF_STATUS_UNMERGED: - status_printf_more(s, c, "unmerged: %s", one); + status_printf_more(s, c, _("unmerged: %s"), one); break; default: - die("bug: unhandled diff status %c", status); + die(_("bug: unhandled diff status %c"), status); } if (extra.len) { status_printf_more(s, color(WT_STATUS_HEADER, s), "%s", extra.buf); @@ -707,14 +707,14 @@ void wt_status_print(struct wt_status *s) const char *branch_status_color = color(WT_STATUS_HEADER, s); if (s->branch) { - const char *on_what = "On branch "; + const char *on_what = _("On branch "); const char *branch_name = s->branch; if (!prefixcmp(branch_name, "refs/heads/")) branch_name += 11; else if (!strcmp(branch_name, "HEAD")) { branch_name = ""; branch_status_color = color(WT_STATUS_NOBRANCH, s); - on_what = "Not currently on any branch."; + on_what = _("Not currently on any branch."); } status_printf(s, color(WT_STATUS_HEADER, s), ""); status_printf_more(s, branch_status_color, "%s", on_what); @@ -739,29 +739,29 @@ void wt_status_print(struct wt_status *s) wt_status_print_submodule_summary(s, 1); /* unstaged */ } if (s->show_untracked_files) { - wt_status_print_other(s, &s->untracked, "Untracked", "add"); + wt_status_print_other(s, &s->untracked, _("Untracked"), "add"); if (s->show_ignored_files) - wt_status_print_other(s, &s->ignored, "Ignored", "add -f"); + wt_status_print_other(s, &s->ignored, _("Ignored"), "add -f"); } else if (s->commitable) - status_printf_ln(s, GIT_COLOR_NORMAL, "Untracked files not listed%s", + status_printf_ln(s, GIT_COLOR_NORMAL, _("Untracked files not listed%s"), advice_status_hints - ? " (use -u option to show untracked files)" : ""); + ? _(" (use -u option to show untracked files)") : ""); if (s->verbose) wt_status_print_verbose(s); if (!s->commitable) { if (s->amend) - status_printf_ln(s, GIT_COLOR_NORMAL, "No changes"); + status_printf_ln(s, GIT_COLOR_NORMAL, _("No changes")); else if (s->nowarn) ; /* nothing */ else if (s->workdir_dirty) - printf("no changes added to commit%s\n", + printf(_("no changes added to commit%s\n"), advice_status_hints - ? " (use \"git add\" and/or \"git commit -a\")" : ""); + ? _(" (use \"git add\" and/or \"git commit -a\")") : ""); else if (s->untracked.nr) - printf("nothing added to commit but untracked files present%s\n", + printf(_("nothing added to commit but untracked files present%s\n"), advice_status_hints - ? " (use \"git add\" to track)" : ""); + ? _(" (use \"git add\" to track)") : ""); else if (s->is_initial) printf("nothing to commit%s\n", advice_status_hints ? " (create/copy files and use \"git add\" to track)" : ""); -- cgit v1.2.1 From 8ec9bc0dd5852e5468db576b0cba39f9179d4610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 22 Feb 2011 23:42:14 +0000 Subject: i18n: git-status "nothing to commit" messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gettextize the "nothing to commit" messages. Many tests explicitly checked for this message. Change them to skip under GETTEXT_POISON=YesPlease. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- wt-status.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 055022241f..e9abfc82de 100644 --- a/wt-status.c +++ b/wt-status.c @@ -763,14 +763,14 @@ void wt_status_print(struct wt_status *s) advice_status_hints ? _(" (use \"git add\" to track)") : ""); else if (s->is_initial) - printf("nothing to commit%s\n", advice_status_hints - ? " (create/copy files and use \"git add\" to track)" : ""); + printf(_("nothing to commit%s\n"), advice_status_hints + ? _(" (create/copy files and use \"git add\" to track)") : ""); else if (!s->show_untracked_files) - printf("nothing to commit%s\n", advice_status_hints - ? " (use -u to show untracked files)" : ""); + printf(_("nothing to commit%s\n"), advice_status_hints + ? _(" (use -u to show untracked files)") : ""); else - printf("nothing to commit%s\n", advice_status_hints - ? " (working directory clean)" : ""); + printf(_("nothing to commit%s\n"), advice_status_hints + ? _(" (working directory clean)") : ""); } } -- cgit v1.2.1 From 98f5e24b9020578e4526eb1cc9588871350e5c01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 22 Feb 2011 23:42:15 +0000 Subject: i18n: git-status shortstatus messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make the messages added in v1.7.2-rc0~54^2~1 translatable. Some of these could use the to be implemented plural support in the gettext library. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- wt-status.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index e9abfc82de..a1aa5b29f6 100644 --- a/wt-status.c +++ b/wt-status.c @@ -878,13 +878,13 @@ static void wt_shortstatus_print_tracking(struct wt_status *s) if (!prefixcmp(branch_name, "refs/heads/")) branch_name += 11; else if (!strcmp(branch_name, "HEAD")) { - branch_name = "HEAD (no branch)"; + branch_name = _("HEAD (no branch)"); branch_color_local = color(WT_STATUS_NOBRANCH, s); } branch = branch_get(s->branch + 11); if (s->is_initial) - color_fprintf(s->fp, header_color, "Initial commit on "); + 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); @@ -899,15 +899,15 @@ static void wt_shortstatus_print_tracking(struct wt_status *s) color_fprintf(s->fp, header_color, " ["); if (!num_ours) { - color_fprintf(s->fp, header_color, "behind "); + color_fprintf(s->fp, header_color, _("behind ")); color_fprintf(s->fp, branch_color_remote, "%d", num_theirs); } else if (!num_theirs) { - color_fprintf(s->fp, header_color, "ahead "); + color_fprintf(s->fp, header_color, _("ahead ")); color_fprintf(s->fp, branch_color_local, "%d", num_ours); } else { - color_fprintf(s->fp, header_color, "ahead "); + color_fprintf(s->fp, header_color, _("ahead ")); color_fprintf(s->fp, branch_color_local, "%d", num_ours); - color_fprintf(s->fp, header_color, ", behind "); + color_fprintf(s->fp, header_color, _(", behind ")); color_fprintf(s->fp, branch_color_remote, "%d", num_theirs); } -- cgit v1.2.1 From 919a4ce0c110a22c00aa854aa16638786b143feb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 22 Feb 2011 23:42:16 +0000 Subject: i18n: git-status "Changes to be committed" message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gettextize the "# Changes to be committed:" messages. Several tests explicitly checked for this message. Change them to skip under GETTEXT_POISON=YesPlease. Since these tests didn't check for the rest of the git-status(1) output this change has been split up from the "git-status basic messages" patch. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- wt-status.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index a1aa5b29f6..321c4f8723 100644 --- a/wt-status.c +++ b/wt-status.c @@ -148,7 +148,7 @@ static void wt_status_print_cached_header(struct wt_status *s) { const char *c = color(WT_STATUS_HEADER, s); - status_printf_ln(s, c, "Changes to be committed:"); + status_printf_ln(s, c, _("Changes to be committed:")); if (!advice_status_hints) return; if (s->in_merge) -- cgit v1.2.1 From b3b298afcbcb5cf5b497928fc9bcd17624112233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 22 Feb 2011 23:42:17 +0000 Subject: i18n: git-status "Initial commit" message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gettextize the "# Initial commit" message. A test in t7501-commit.sh explicitly checked for this message. Change it to skip under GETTEXT_POISON=YesPlease. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- wt-status.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 321c4f8723..f0b8c68883 100644 --- a/wt-status.c +++ b/wt-status.c @@ -725,7 +725,7 @@ void wt_status_print(struct wt_status *s) if (s->is_initial) { status_printf_ln(s, color(WT_STATUS_HEADER, s), ""); - status_printf_ln(s, color(WT_STATUS_HEADER, s), "Initial commit"); + status_printf_ln(s, color(WT_STATUS_HEADER, s), _("Initial commit")); status_printf_ln(s, color(WT_STATUS_HEADER, s), ""); } -- cgit v1.2.1 From d2b044bee5c174647003056e4ba23207e9b26ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 22 Feb 2011 23:42:18 +0000 Subject: i18n: git-status "renamed: " message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gettextize the "renamed: %s -> %s" message which appears as part of git-status(1) output. Two tests in t4001-diff-rename.sh explicitly checked for this message. Change them to skip under GETTEXT_POISON=YesPlease. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- wt-status.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index f0b8c68883..9ff0590122 100644 --- a/wt-status.c +++ b/wt-status.c @@ -275,7 +275,7 @@ static void wt_status_print_change_data(struct wt_status *s, status_printf_more(s, c, _("modified: %s"), one); break; case DIFF_STATUS_RENAMED: - status_printf_more(s, c, "renamed: %s -> %s", one, two); + status_printf_more(s, c, _("renamed: %s -> %s"), one, two); break; case DIFF_STATUS_TYPE_CHANGED: status_printf_more(s, c, _("typechange: %s"), one); -- cgit v1.2.1