@@ -111,12 +111,14 @@ static int show_ignored_in_status;
111
111
static const char * only_include_assumed ;
112
112
static struct strbuf message = STRBUF_INIT ;
113
113
114
- static enum {
114
+ static enum status_format {
115
115
STATUS_FORMAT_NONE = 0 ,
116
116
STATUS_FORMAT_LONG ,
117
117
STATUS_FORMAT_SHORT ,
118
- STATUS_FORMAT_PORCELAIN
119
- } status_format ;
118
+ STATUS_FORMAT_PORCELAIN ,
119
+
120
+ STATUS_FORMAT_UNSPECIFIED
121
+ } status_format = STATUS_FORMAT_UNSPECIFIED ;
120
122
121
123
static int opt_parse_m (const struct option * opt , const char * arg , int unset )
122
124
{
@@ -457,6 +459,9 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
457
459
case STATUS_FORMAT_PORCELAIN :
458
460
wt_porcelain_print (s );
459
461
break ;
462
+ case STATUS_FORMAT_UNSPECIFIED :
463
+ die ("BUG: finalize_deferred_config() should have been called" );
464
+ break ;
460
465
case STATUS_FORMAT_NONE :
461
466
case STATUS_FORMAT_LONG :
462
467
wt_status_print (s );
@@ -958,6 +963,42 @@ static const char *read_commit_message(const char *name)
958
963
return logmsg_reencode (commit , NULL , out_enc );
959
964
}
960
965
966
+ /*
967
+ * Enumerate what needs to be propagated when --porcelain
968
+ * is not in effect here.
969
+ */
970
+ static struct status_deferred_config {
971
+ enum status_format status_format ;
972
+ int show_branch ;
973
+ } status_deferred_config = {
974
+ STATUS_FORMAT_UNSPECIFIED ,
975
+ -1 /* unspecified */
976
+ };
977
+
978
+ static void finalize_deferred_config (struct wt_status * s )
979
+ {
980
+ int use_deferred_config = (status_format != STATUS_FORMAT_PORCELAIN &&
981
+ !s -> null_termination );
982
+
983
+ if (s -> null_termination ) {
984
+ if (status_format == STATUS_FORMAT_NONE ||
985
+ status_format == STATUS_FORMAT_UNSPECIFIED )
986
+ status_format = STATUS_FORMAT_PORCELAIN ;
987
+ else if (status_format == STATUS_FORMAT_LONG )
988
+ die (_ ("--long and -z are incompatible" ));
989
+ }
990
+
991
+ if (use_deferred_config && status_format == STATUS_FORMAT_UNSPECIFIED )
992
+ status_format = status_deferred_config .status_format ;
993
+ if (status_format == STATUS_FORMAT_UNSPECIFIED )
994
+ status_format = STATUS_FORMAT_NONE ;
995
+
996
+ if (use_deferred_config && s -> show_branch < 0 )
997
+ s -> show_branch = status_deferred_config .show_branch ;
998
+ if (s -> show_branch < 0 )
999
+ s -> show_branch = 0 ;
1000
+ }
1001
+
961
1002
static int parse_and_validate_options (int argc , const char * argv [],
962
1003
const struct option * options ,
963
1004
const char * const usage [],
@@ -968,6 +1009,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
968
1009
int f = 0 ;
969
1010
970
1011
argc = parse_options (argc , argv , prefix , options , usage , 0 );
1012
+ finalize_deferred_config (s );
971
1013
972
1014
if (force_author && !strchr (force_author , '>' ))
973
1015
force_author = find_author_by_nickname (force_author );
@@ -1052,12 +1094,6 @@ static int parse_and_validate_options(int argc, const char *argv[],
1052
1094
if (all && argc > 0 )
1053
1095
die (_ ("Paths with -a does not make sense." ));
1054
1096
1055
- if (s -> null_termination ) {
1056
- if (status_format == STATUS_FORMAT_NONE )
1057
- status_format = STATUS_FORMAT_PORCELAIN ;
1058
- else if (status_format == STATUS_FORMAT_LONG )
1059
- die (_ ("--long and -z are incompatible" ));
1060
- }
1061
1097
if (status_format != STATUS_FORMAT_NONE )
1062
1098
dry_run = 1 ;
1063
1099
@@ -1112,13 +1148,13 @@ static int git_status_config(const char *k, const char *v, void *cb)
1112
1148
}
1113
1149
if (!strcmp (k , "status.short" )) {
1114
1150
if (git_config_bool (k , v ))
1115
- status_format = STATUS_FORMAT_SHORT ;
1151
+ status_deferred_config . status_format = STATUS_FORMAT_SHORT ;
1116
1152
else
1117
- status_format = STATUS_FORMAT_NONE ;
1153
+ status_deferred_config . status_format = STATUS_FORMAT_NONE ;
1118
1154
return 0 ;
1119
1155
}
1120
1156
if (!strcmp (k , "status.branch" )) {
1121
- s -> show_branch = git_config_bool (k , v );
1157
+ status_deferred_config . show_branch = git_config_bool (k , v );
1122
1158
return 0 ;
1123
1159
}
1124
1160
if (!strcmp (k , "status.color" ) || !strcmp (k , "color.status" )) {
@@ -1163,8 +1199,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1163
1199
OPT__VERBOSE (& verbose , N_ ("be verbose" )),
1164
1200
OPT_SET_INT ('s' , "short" , & status_format ,
1165
1201
N_ ("show status concisely" ), STATUS_FORMAT_SHORT ),
1166
- OPT_BOOLEAN ('b' , "branch" , & s .show_branch ,
1167
- N_ ("show branch information" )),
1202
+ OPT_BOOL ('b' , "branch" , & s .show_branch ,
1203
+ N_ ("show branch information" )),
1168
1204
OPT_SET_INT (0 , "porcelain" , & status_format ,
1169
1205
N_ ("machine-readable output" ),
1170
1206
STATUS_FORMAT_PORCELAIN ),
@@ -1197,13 +1233,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1197
1233
builtin_status_options ,
1198
1234
builtin_status_usage , 0 );
1199
1235
finalize_colopts (& s .colopts , -1 );
1200
-
1201
- if (s .null_termination ) {
1202
- if (status_format == STATUS_FORMAT_NONE )
1203
- status_format = STATUS_FORMAT_PORCELAIN ;
1204
- else if (status_format == STATUS_FORMAT_LONG )
1205
- die (_ ("--long and -z are incompatible" ));
1206
- }
1236
+ finalize_deferred_config (& s );
1207
1237
1208
1238
handle_untracked_files_arg (& s );
1209
1239
if (show_ignored_in_status )
@@ -1232,6 +1262,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1232
1262
case STATUS_FORMAT_PORCELAIN :
1233
1263
wt_porcelain_print (& s );
1234
1264
break ;
1265
+ case STATUS_FORMAT_UNSPECIFIED :
1266
+ die ("BUG: finalize_deferred_config() should have been called" );
1267
+ break ;
1235
1268
case STATUS_FORMAT_NONE :
1236
1269
case STATUS_FORMAT_LONG :
1237
1270
s .verbose = verbose ;
@@ -1400,7 +1433,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1400
1433
OPT_BOOLEAN (0 , "dry-run" , & dry_run , N_ ("show what would be committed" )),
1401
1434
OPT_SET_INT (0 , "short" , & status_format , N_ ("show status concisely" ),
1402
1435
STATUS_FORMAT_SHORT ),
1403
- OPT_BOOLEAN (0 , "branch" , & s .show_branch , N_ ("show branch information" )),
1436
+ OPT_BOOL (0 , "branch" , & s .show_branch , N_ ("show branch information" )),
1404
1437
OPT_SET_INT (0 , "porcelain" , & status_format ,
1405
1438
N_ ("machine-readable output" ), STATUS_FORMAT_PORCELAIN ),
1406
1439
OPT_SET_INT (0 , "long" , & status_format ,
0 commit comments