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 <peff@peff.net>

Jeff King committed May 7, 2012 at 15:35 UTC 4d2292e9a90465cbfa23f1c170c11423d11830df
2 files changed +5 -6
builtin/commit.c
+4 -5
@@ -89,7 +89,6 @@ static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
89 static int no_post_rewrite, allow_empty_message;
90 static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
91 static char *sign_commit;
92 -static unsigned int colopts;
92
93 /*
94 * 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)
1120 struct wt_status *s = cb;
1121
1122 if (!prefixcmp(k, "column."))
1124 - return git_column_config(k, v, "status", &colopts);
1123 + return git_column_config(k, v, "status", &s->colopts);
1124 if (!strcmp(k, "status.submodulesummary")) {
1125 int is_bool;
1126 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)
1186 { OPTION_STRING, 0, "ignore-submodules", &ignore_submodule_arg, "when",
1187 "ignore changes to submodules, optional when: all, dirty, untracked. (Default: all)",
1188 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"),
1190 OPT_END(),
1191 };
1192
@@ -1201,8 +1200,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1200 argc = parse_options(argc, argv, prefix,
1201 builtin_status_options,
1202 builtin_status_usage, 0);
1204 - finalize_colopts(&colopts, -1);
1205 - s.colopts = colopts;
1203 + finalize_colopts(&s.colopts, -1);
1204
1205 if (s.null_termination && status_format == STATUS_FORMAT_LONG)
1206 status_format = STATUS_FORMAT_PORCELAIN;
@@ -1439,6 +1437,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1437 wt_status_prepare(&s);
1438 git_config(git_commit_config, &s);
1439 determine_whence(&s);
1440 + s.colopts = 0;
1441
1442 if (get_sha1("HEAD", sha1))
1443 current_head = NULL;
wt-status.h
+1 -1
@@ -56,7 +56,7 @@ struct wt_status {
56 enum untracked_status_type show_untracked_files;
57 const char *ignore_submodule_arg;
58 char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
59 - int colopts;
59 + unsigned colopts;
60 int null_termination;
61 int show_branch;
62