summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3a5d13a)
raw | patch | inline | side by side (parent: 3a5d13a)
author | Junio C Hamano <gitster@pobox.com> | |
Mon, 10 Aug 2009 04:59:30 +0000 (21:59 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 10 Aug 2009 19:50:30 +0000 (12:50 -0700) |
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>
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>
builtin-commit.c | patch | blob | history | |
wt-status.c | patch | blob | history | |
wt-status.h | patch | blob | history |
diff --git a/builtin-commit.c b/builtin-commit.c
index 3a7e35d60fa024c5ead68371e93b295fa568634a..716eec832d527feada6b02727e3b72f438b6acf8 100644 (file)
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -343,27 +343,24 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int
return false_lock.filename;
}
-static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn)
+static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn,
+ struct wt_status *s)
{
- struct wt_status s;
-
- wt_status_prepare(&s);
- if (wt_status_relative_paths)
- s.prefix = prefix;
+ if (s->relative_paths)
+ s->prefix = prefix;
if (amend) {
- s.amend = 1;
- s.reference = "HEAD^1";
+ s->amend = 1;
+ s->reference = "HEAD^1";
}
- s.verbose = verbose;
- s.untracked = (show_untracked_files == SHOW_ALL_UNTRACKED_FILES);
- s.index_file = index_file;
- s.fp = fp;
- s.nowarn = nowarn;
+ s->verbose = verbose;
+ s->index_file = index_file;
+ s->fp = fp;
+ s->nowarn = nowarn;
- wt_status_print(&s);
+ wt_status_print(s);
- return s.commitable;
+ return s->commitable;
}
static int is_a_merge(const unsigned char *sha1)
author_date = date;
}
-static int prepare_to_commit(const char *index_file, const char *prefix)
+static int prepare_to_commit(const char *index_file, const char *prefix,
+ struct wt_status *s)
{
struct stat statbuf;
int commitable, saved_color_setting;
if (ident_shown)
fprintf(fp, "#\n");
- saved_color_setting = wt_status_use_color;
- wt_status_use_color = 0;
- commitable = run_status(fp, index_file, prefix, 1);
- wt_status_use_color = saved_color_setting;
+ saved_color_setting = s->use_color;
+ s->use_color = 0;
+ commitable = run_status(fp, index_file, prefix, 1, s);
+ s->use_color = saved_color_setting;
} else {
unsigned char sha1[20];
const char *parent = "HEAD";
if (!commitable && !in_merge && !allow_empty &&
!(amend && is_a_merge(head_sha1))) {
- run_status(stdout, index_file, prefix, 0);
+ run_status(stdout, index_file, prefix, 0, s);
return 0;
}
static int parse_and_validate_options(int argc, const char *argv[],
const char * const usage[],
- const char *prefix)
+ const char *prefix,
+ struct wt_status *s)
{
int f = 0;
if (!untracked_files_arg)
; /* default already initialized */
else if (!strcmp(untracked_files_arg, "no"))
- show_untracked_files = SHOW_NO_UNTRACKED_FILES;
+ s->show_untracked_files = SHOW_NO_UNTRACKED_FILES;
else if (!strcmp(untracked_files_arg, "normal"))
- show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
+ s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
else if (!strcmp(untracked_files_arg, "all"))
- show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
+ s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
else
die("Invalid untracked files mode '%s'", untracked_files_arg);
return argc;
}
-static int dry_run_commit(int argc, const char **argv, const char *prefix)
+static int dry_run_commit(int argc, const char **argv, const char *prefix,
+ struct wt_status *s)
{
int commitable;
const char *index_file;
index_file = prepare_index(argc, argv, prefix, 1);
- commitable = run_status(stdout, index_file, prefix, 0);
+ commitable = run_status(stdout, index_file, prefix, 0, s);
rollback_index_files();
return commitable ? 0 : 1;
int cmd_status(int argc, const char **argv, const char *prefix)
{
- git_config(git_status_config, NULL);
- if (wt_status_use_color == -1)
- wt_status_use_color = git_use_color_default;
+ struct wt_status s;
+
+ wt_status_prepare(&s);
+ git_config(git_status_config, &s);
+ if (s.use_color == -1)
+ s.use_color = git_use_color_default;
if (diff_use_color_default == -1)
diff_use_color_default = git_use_color_default;
- argc = parse_and_validate_options(argc, argv, builtin_status_usage, prefix);
- return dry_run_commit(argc, argv, prefix);
+ argc = parse_and_validate_options(argc, argv, builtin_status_usage,
+ prefix, &s);
+ return dry_run_commit(argc, argv, prefix, &s);
}
static void print_summary(const char *prefix, const unsigned char *sha1)
static int git_commit_config(const char *k, const char *v, void *cb)
{
+ struct wt_status *s = cb;
+
if (!strcmp(k, "commit.template"))
return git_config_string(&template_file, k, v);
- return git_status_config(k, v, cb);
+ return git_status_config(k, v, s);
}
int cmd_commit(int argc, const char **argv, const char *prefix)
struct commit_list *parents = NULL, **pptr = &parents;
struct stat statbuf;
int allow_fast_forward = 1;
+ struct wt_status s;
- git_config(git_commit_config, NULL);
+ wt_status_prepare(&s);
+ git_config(git_commit_config, &s);
- if (wt_status_use_color == -1)
- wt_status_use_color = git_use_color_default;
+ if (s.use_color == -1)
+ s.use_color = git_use_color_default;
- argc = parse_and_validate_options(argc, argv, builtin_commit_usage, prefix);
+ argc = parse_and_validate_options(argc, argv, builtin_commit_usage,
+ prefix, &s);
if (dry_run)
- return dry_run_commit(argc, argv, prefix);
+ return dry_run_commit(argc, argv, prefix, &s);
index_file = prepare_index(argc, argv, prefix, 0);
/* Set up everything for writing the commit object. This includes
running hooks, writing the trees, and interacting with the user. */
- if (!prepare_to_commit(index_file, prefix)) {
+ if (!prepare_to_commit(index_file, prefix, &s)) {
rollback_index_files();
return 1;
}
diff --git a/wt-status.c b/wt-status.c
index 97fedfaa196777277577b0057743ae9f5f25ecc2..af93bb52db9e1f0fb88b88975af169b5037d7ce4 100644 (file)
--- a/wt-status.c
+++ b/wt-status.c
#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 */
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"))
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)
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";
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);
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);
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)");
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, "#");
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
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;
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;
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);
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));
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);
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));
}
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) {
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);
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");
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");
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.")) {
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);
}
diff --git a/wt-status.h b/wt-status.h
index f80142ffdecb928d7c9e3f72e0d9f9d27102118c..cd06a4d955208962de6df37cfe1ff452918d12f1 100644 (file)
--- a/wt-status.h
+++ b/wt-status.h
SHOW_NORMAL_UNTRACKED_FILES,
SHOW_ALL_UNTRACKED_FILES
};
-extern enum untracked_status_type show_untracked_files;
struct wt_status_change_data {
int worktree_status;
const char *reference;
int verbose;
int amend;
- int untracked;
int nowarn;
+ int use_color;
+ int relative_paths;
+ int submodule_summary;
+ enum untracked_status_type show_untracked_files;
+
/* These are computed during processing of the individual sections */
int commitable;
int workdir_dirty;
};
int git_status_config(const char *var, const char *value, void *cb);
-extern int wt_status_use_color;
-extern int wt_status_relative_paths;
void wt_status_prepare(struct wt_status *s);
void wt_status_print(struct wt_status *s);
void wt_status_collect_changes(struct wt_status *s);