Skip to content

Commit d249b09

Browse files
committed
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 <[email protected]>
1 parent 3a5d13a commit d249b09

File tree

3 files changed

+93
-84
lines changed

3 files changed

+93
-84
lines changed

builtin-commit.c

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -343,27 +343,24 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int
343343
return false_lock.filename;
344344
}
345345

346-
static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn)
346+
static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn,
347+
struct wt_status *s)
347348
{
348-
struct wt_status s;
349-
350-
wt_status_prepare(&s);
351-
if (wt_status_relative_paths)
352-
s.prefix = prefix;
349+
if (s->relative_paths)
350+
s->prefix = prefix;
353351

354352
if (amend) {
355-
s.amend = 1;
356-
s.reference = "HEAD^1";
353+
s->amend = 1;
354+
s->reference = "HEAD^1";
357355
}
358-
s.verbose = verbose;
359-
s.untracked = (show_untracked_files == SHOW_ALL_UNTRACKED_FILES);
360-
s.index_file = index_file;
361-
s.fp = fp;
362-
s.nowarn = nowarn;
356+
s->verbose = verbose;
357+
s->index_file = index_file;
358+
s->fp = fp;
359+
s->nowarn = nowarn;
363360

364-
wt_status_print(&s);
361+
wt_status_print(s);
365362

366-
return s.commitable;
363+
return s->commitable;
367364
}
368365

369366
static int is_a_merge(const unsigned char *sha1)
@@ -417,7 +414,8 @@ static void determine_author_info(void)
417414
author_date = date;
418415
}
419416

420-
static int prepare_to_commit(const char *index_file, const char *prefix)
417+
static int prepare_to_commit(const char *index_file, const char *prefix,
418+
struct wt_status *s)
421419
{
422420
struct stat statbuf;
423421
int commitable, saved_color_setting;
@@ -559,10 +557,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
559557
if (ident_shown)
560558
fprintf(fp, "#\n");
561559

562-
saved_color_setting = wt_status_use_color;
563-
wt_status_use_color = 0;
564-
commitable = run_status(fp, index_file, prefix, 1);
565-
wt_status_use_color = saved_color_setting;
560+
saved_color_setting = s->use_color;
561+
s->use_color = 0;
562+
commitable = run_status(fp, index_file, prefix, 1, s);
563+
s->use_color = saved_color_setting;
566564
} else {
567565
unsigned char sha1[20];
568566
const char *parent = "HEAD";
@@ -583,7 +581,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
583581

584582
if (!commitable && !in_merge && !allow_empty &&
585583
!(amend && is_a_merge(head_sha1))) {
586-
run_status(stdout, index_file, prefix, 0);
584+
run_status(stdout, index_file, prefix, 0, s);
587585
return 0;
588586
}
589587

@@ -695,7 +693,8 @@ static const char *find_author_by_nickname(const char *name)
695693

696694
static int parse_and_validate_options(int argc, const char *argv[],
697695
const char * const usage[],
698-
const char *prefix)
696+
const char *prefix,
697+
struct wt_status *s)
699698
{
700699
int f = 0;
701700

@@ -798,11 +797,11 @@ static int parse_and_validate_options(int argc, const char *argv[],
798797
if (!untracked_files_arg)
799798
; /* default already initialized */
800799
else if (!strcmp(untracked_files_arg, "no"))
801-
show_untracked_files = SHOW_NO_UNTRACKED_FILES;
800+
s->show_untracked_files = SHOW_NO_UNTRACKED_FILES;
802801
else if (!strcmp(untracked_files_arg, "normal"))
803-
show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
802+
s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
804803
else if (!strcmp(untracked_files_arg, "all"))
805-
show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
804+
s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
806805
else
807806
die("Invalid untracked files mode '%s'", untracked_files_arg);
808807

@@ -814,28 +813,33 @@ static int parse_and_validate_options(int argc, const char *argv[],
814813
return argc;
815814
}
816815

817-
static int dry_run_commit(int argc, const char **argv, const char *prefix)
816+
static int dry_run_commit(int argc, const char **argv, const char *prefix,
817+
struct wt_status *s)
818818
{
819819
int commitable;
820820
const char *index_file;
821821

822822
index_file = prepare_index(argc, argv, prefix, 1);
823-
commitable = run_status(stdout, index_file, prefix, 0);
823+
commitable = run_status(stdout, index_file, prefix, 0, s);
824824
rollback_index_files();
825825

826826
return commitable ? 0 : 1;
827827
}
828828

829829
int cmd_status(int argc, const char **argv, const char *prefix)
830830
{
831-
git_config(git_status_config, NULL);
832-
if (wt_status_use_color == -1)
833-
wt_status_use_color = git_use_color_default;
831+
struct wt_status s;
832+
833+
wt_status_prepare(&s);
834+
git_config(git_status_config, &s);
835+
if (s.use_color == -1)
836+
s.use_color = git_use_color_default;
834837
if (diff_use_color_default == -1)
835838
diff_use_color_default = git_use_color_default;
836839

837-
argc = parse_and_validate_options(argc, argv, builtin_status_usage, prefix);
838-
return dry_run_commit(argc, argv, prefix);
840+
argc = parse_and_validate_options(argc, argv, builtin_status_usage,
841+
prefix, &s);
842+
return dry_run_commit(argc, argv, prefix, &s);
839843
}
840844

841845
static void print_summary(const char *prefix, const unsigned char *sha1)
@@ -887,10 +891,12 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
887891

888892
static int git_commit_config(const char *k, const char *v, void *cb)
889893
{
894+
struct wt_status *s = cb;
895+
890896
if (!strcmp(k, "commit.template"))
891897
return git_config_string(&template_file, k, v);
892898

893-
return git_status_config(k, v, cb);
899+
return git_status_config(k, v, s);
894900
}
895901

896902
int cmd_commit(int argc, const char **argv, const char *prefix)
@@ -903,21 +909,24 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
903909
struct commit_list *parents = NULL, **pptr = &parents;
904910
struct stat statbuf;
905911
int allow_fast_forward = 1;
912+
struct wt_status s;
906913

907-
git_config(git_commit_config, NULL);
914+
wt_status_prepare(&s);
915+
git_config(git_commit_config, &s);
908916

909-
if (wt_status_use_color == -1)
910-
wt_status_use_color = git_use_color_default;
917+
if (s.use_color == -1)
918+
s.use_color = git_use_color_default;
911919

912-
argc = parse_and_validate_options(argc, argv, builtin_commit_usage, prefix);
920+
argc = parse_and_validate_options(argc, argv, builtin_commit_usage,
921+
prefix, &s);
913922
if (dry_run)
914-
return dry_run_commit(argc, argv, prefix);
923+
return dry_run_commit(argc, argv, prefix, &s);
915924

916925
index_file = prepare_index(argc, argv, prefix, 0);
917926

918927
/* Set up everything for writing the commit object. This includes
919928
running hooks, writing the trees, and interacting with the user. */
920-
if (!prepare_to_commit(index_file, prefix)) {
929+
if (!prepare_to_commit(index_file, prefix, &s)) {
921930
rollback_index_files();
922931
return 1;
923932
}

0 commit comments

Comments
 (0)