aboutsummaryrefslogtreecommitdiff
path: root/wt-status.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-08-09 21:59:30 -0700
committerJunio C Hamano <gitster@pobox.com>2009-08-10 12:50:30 -0700
commitd249b098893809c6de6e5e20063a22ac2c629ce7 (patch)
tree03b6147a28dfab2ca55bdbfd95f9d9fae6dc0e02 /wt-status.c
parent3a5d13a3c32e0f39d8fc83330255fac27af5d853 (diff)
downloadgit-d249b098893809c6de6e5e20063a22ac2c629ce7.tar.gz
git-d249b098893809c6de6e5e20063a22ac2c629ce7.tar.xz
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 <gitster@pobox.com>
Diffstat (limited to 'wt-status.c')
-rw-r--r--wt-status.c81
1 files changed, 40 insertions, 41 deletions
diff --git a/wt-status.c b/wt-status.c
index 97fedfaa1..af93bb52d 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 <file>...\" 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 <file>...\" 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 <file>...\" 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 <file>...\" 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);
}