From e28a243b0000e7b82adcc5eb7445ef132f22b9de Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 9 Apr 2010 23:34:40 -0700 Subject: [PATCH 1/6] wt-status: remove unused workdir_untracked member Signed-off-by: Junio C Hamano --- wt-status.c | 1 - wt-status.h | 1 - 2 files changed, 2 deletions(-) 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); } } diff --git a/wt-status.h b/wt-status.h index 91206739f3..2c49f465f8 100644 --- a/wt-status.h +++ b/wt-status.h @@ -47,7 +47,6 @@ struct wt_status { /* These are computed during processing of the individual sections */ int commitable; int workdir_dirty; - int workdir_untracked; const char *index_file; FILE *fp; const char *prefix; From f5b26b1d14d3362fa41e51f4f78cdf56968733ba Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 9 Apr 2010 23:58:27 -0700 Subject: [PATCH 2/6] wt-status: plug memory leak while collecting untracked files Signed-off-by: Junio C Hamano --- wt-status.c | 3 +++ 1 file changed, 3 insertions(+) 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) From 6cb3f6b28294cb2b3766370f42a570fb46ba4e97 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 10 Apr 2010 00:11:53 -0700 Subject: [PATCH 3/6] wt-status: collect ignored files Signed-off-by: Junio C Hamano --- wt-status.c | 16 ++++++++++++++++ wt-status.h | 2 ++ 2 files changed, 18 insertions(+) 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); } diff --git a/wt-status.h b/wt-status.h index 2c49f465f8..1093e65ae0 100644 --- a/wt-status.h +++ b/wt-status.h @@ -41,6 +41,7 @@ struct wt_status { int use_color; int relative_paths; int submodule_summary; + int show_ignored_files; enum untracked_status_type show_untracked_files; char color_palette[WT_STATUS_UNMERGED+1][COLOR_MAXLEN]; @@ -52,6 +53,7 @@ struct wt_status { const char *prefix; struct string_list change; struct string_list untracked; + struct string_list ignored; }; void wt_status_prepare(struct wt_status *s); From 1b908b6fb48f4f8009804c097b14106df548247c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 10 Apr 2010 00:19:46 -0700 Subject: [PATCH 4/6] 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(-) 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"); From 2381e39e5ff740883b98c5aca019950f9167b67f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 10 Apr 2010 00:33:17 -0700 Subject: [PATCH 5/6] 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 --- builtin/commit.c | 6 +++++- wt-status.c | 22 +++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index c5ab683d5b..761ca07047 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -83,6 +83,7 @@ static enum { static char *cleanup_arg; static int use_editor = 1, initial_commit, in_merge, include_status = 1; +static int show_ignored_in_status; static const char *only_include_assumed; static struct strbuf message; @@ -1031,6 +1032,8 @@ int cmd_status(int argc, const char **argv, const char *prefix) "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" }, + OPT_BOOLEAN(0, "ignored", &show_ignored_in_status, + "show ignored files"), OPT_END(), }; @@ -1044,7 +1047,8 @@ int cmd_status(int argc, const char **argv, const char *prefix) builtin_status_options, builtin_status_usage, 0); handle_untracked_files_arg(&s); - + if (show_ignored_in_status) + s.show_ignored_files = 1; if (*argv) s.pathspec = get_pathspec(prefix, argv); 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, "!!"); } } From c1909e72952ec6b95f819a4ad8faa8d69f1d961d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 1 May 2010 22:05:14 -0700 Subject: [PATCH 6/6] 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(-) 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); }