Skip to content

Commit dd2be24

Browse files
peffgitster
authored andcommitted
status: refactor format option parsing
This makes it possible to have more than two formats. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 01d8ba1 commit dd2be24

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

builtin-commit.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -991,12 +991,16 @@ static void short_print(struct wt_status *s, int null_termination)
991991
int cmd_status(int argc, const char **argv, const char *prefix)
992992
{
993993
struct wt_status s;
994-
static int null_termination, shortstatus;
994+
static int null_termination;
995+
static enum {
996+
STATUS_FORMAT_LONG,
997+
STATUS_FORMAT_SHORT,
998+
} status_format = STATUS_FORMAT_LONG;
995999
unsigned char sha1[20];
9961000
static struct option builtin_status_options[] = {
9971001
OPT__VERBOSE(&verbose),
998-
OPT_BOOLEAN('s', "short", &shortstatus,
999-
"show status concisely"),
1002+
OPT_SET_INT('s', "short", &status_format,
1003+
"show status concisely", STATUS_FORMAT_SHORT),
10001004
OPT_BOOLEAN('z', "null", &null_termination,
10011005
"terminate entries with NUL"),
10021006
{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg,
@@ -1006,8 +1010,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
10061010
OPT_END(),
10071011
};
10081012

1009-
if (null_termination)
1010-
shortstatus = 1;
1013+
if (null_termination && status_format == STATUS_FORMAT_LONG)
1014+
status_format = STATUS_FORMAT_SHORT;
10111015

10121016
wt_status_prepare(&s);
10131017
git_config(git_status_config, &s);
@@ -1024,9 +1028,11 @@ int cmd_status(int argc, const char **argv, const char *prefix)
10241028
s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
10251029
wt_status_collect(&s);
10261030

1027-
if (shortstatus)
1031+
switch (status_format) {
1032+
case STATUS_FORMAT_SHORT:
10281033
short_print(&s, null_termination);
1029-
else {
1034+
break;
1035+
case STATUS_FORMAT_LONG:
10301036
s.verbose = verbose;
10311037
if (s.relative_paths)
10321038
s.prefix = prefix;
@@ -1035,6 +1041,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
10351041
if (diff_use_color_default == -1)
10361042
diff_use_color_default = git_use_color_default;
10371043
wt_status_print(&s);
1044+
break;
10381045
}
10391046
return 0;
10401047
}

0 commit comments

Comments
 (0)