Code

utf8.c: remove print_spaces()
[git.git] / wt-status.c
index cfbaf309ad1716a820a1d73b9fba889a1e530285..38eb24536b34e40af4c43eb1631e08624e8993d6 100644 (file)
@@ -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] : "";
@@ -59,12 +41,15 @@ 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)
 {
        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 <file>...\" to unstage)", s->reference);
        else
@@ -77,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 <file>...\" to unstage)", s->reference);
        } else {
@@ -90,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 <file>...\" to update what will be committed)");
        else
@@ -102,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 <file>...\" to include in what will be committed)");
        color_fprintf_ln(s->fp, c, "#");
 }
@@ -329,7 +320,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);
 
@@ -337,6 +351,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)
@@ -464,31 +479,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);
 }
@@ -557,7 +561,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), "#");
@@ -565,8 +569,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);
@@ -584,7 +588,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");
@@ -594,45 +598,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);
-}