Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 4d2292e

Browse files
committed
status: refactor colopts handling
The current code reads the config and command-line options into a separate "colopts" variable, and then copies the contents of that variable into the "struct wt_status". We can eliminate the extra variable and copy just write straight into the wt_status struct. This simplifies the "status" code a little bit. Unfortunately, it makes the "commit" code one line more complex; a side effect of the separate variable was that "commit" did not copy the colopts variable, so any column.status configuration had no effect. The result still ends up cleaner, though. In the previous version, it was unclear whether commit simply forgot to copy the colopt variable, or whether it was intentional. Now it explicitly turns off column options. Furthermore, if commit later learns to respect column.status, this will make the end result simpler. I punted on just adding that feature now, because it was sufficiently non-obvious that it should not go into a refactoring patch. Signed-off-by: Jeff King <[email protected]>
1 parent 5410ae4 commit 4d2292e

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

builtin/commit.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
8989
static int no_post_rewrite, allow_empty_message;
9090
static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
9191
static char *sign_commit;
92-
static unsigned int colopts;
9392

9493
/*
9594
* The default commit message cleanup mode will remove the lines
@@ -1121,7 +1120,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
11211120
struct wt_status *s = cb;
11221121

11231122
if (!prefixcmp(k, "column."))
1124-
return git_column_config(k, v, "status", &colopts);
1123+
return git_column_config(k, v, "status", &s->colopts);
11251124
if (!strcmp(k, "status.submodulesummary")) {
11261125
int is_bool;
11271126
s->submodule_summary = git_config_bool_or_int(k, v, &is_bool);
@@ -1187,7 +1186,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
11871186
{ OPTION_STRING, 0, "ignore-submodules", &ignore_submodule_arg, "when",
11881187
"ignore changes to submodules, optional when: all, dirty, untracked. (Default: all)",
11891188
PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
1190-
OPT_COLUMN(0, "column", &colopts, "list untracked files in columns"),
1189+
OPT_COLUMN(0, "column", &s.colopts, "list untracked files in columns"),
11911190
OPT_END(),
11921191
};
11931192

@@ -1201,8 +1200,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
12011200
argc = parse_options(argc, argv, prefix,
12021201
builtin_status_options,
12031202
builtin_status_usage, 0);
1204-
finalize_colopts(&colopts, -1);
1205-
s.colopts = colopts;
1203+
finalize_colopts(&s.colopts, -1);
12061204

12071205
if (s.null_termination && status_format == STATUS_FORMAT_LONG)
12081206
status_format = STATUS_FORMAT_PORCELAIN;
@@ -1439,6 +1437,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
14391437
wt_status_prepare(&s);
14401438
git_config(git_commit_config, &s);
14411439
determine_whence(&s);
1440+
s.colopts = 0;
14421441

14431442
if (get_sha1("HEAD", sha1))
14441443
current_head = NULL;

wt-status.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct wt_status {
5656
enum untracked_status_type show_untracked_files;
5757
const char *ignore_submodule_arg;
5858
char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
59-
int colopts;
59+
unsigned colopts;
6060
int null_termination;
6161
int show_branch;
6262

0 commit comments

Comments
 (0)