status: refactor format option parsing
This makes it possible to have more than two formats. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Sep 5, 2009 at 04:54 UTC
dd2be243d62260d4c825c22fdd2f61a7da12de22
1 file changed
+14
-7
builtin-commit.c
+14
-7
@@ -991,12 +991,16 @@ static void short_print(struct wt_status *s, int null_termination)
991
int cmd_status(int argc, const char **argv, const char *prefix)
992
{
993
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;
999
unsigned char sha1[20];
1000
static struct option builtin_status_options[] = {
1001
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),
1004
OPT_BOOLEAN('z', "null", &null_termination,
1005
"terminate entries with NUL"),
1006
{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg,
@@ -1006,8 +1010,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1010
OPT_END(),
1011
};
1012
1009
- if (null_termination)
1010
- shortstatus = 1;
1013
+ if (null_termination && status_format == STATUS_FORMAT_LONG)
1014
+ status_format = STATUS_FORMAT_SHORT;
1015
1016
wt_status_prepare(&s);
1017
git_config(git_status_config, &s);
@@ -1024,9 +1028,11 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1028
s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
1029
wt_status_collect(&s);
1030
1027
- if (shortstatus)
1031
+ switch (status_format) {
1032
+ case STATUS_FORMAT_SHORT:
1033
short_print(&s, null_termination);
1029
- else {
1034
+ break;
1035
+ case STATUS_FORMAT_LONG:
1036
s.verbose = verbose;
1037
if (s.relative_paths)
1038
s.prefix = prefix;
@@ -1035,6 +1041,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1041
if (diff_use_color_default == -1)
1042
diff_use_color_default = git_use_color_default;
1043
wt_status_print(&s);
1044
+ break;
1045
}
1046
return 0;
1047
}