@@ -111,13 +111,11 @@ 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 int null_termination ;
115
114
static enum {
116
115
STATUS_FORMAT_LONG ,
117
116
STATUS_FORMAT_SHORT ,
118
117
STATUS_FORMAT_PORCELAIN
119
118
} status_format = STATUS_FORMAT_LONG ;
120
- static int status_show_branch ;
121
119
122
120
static int opt_parse_m (const struct option * opt , const char * arg , int unset )
123
121
{
@@ -131,59 +129,6 @@ static int opt_parse_m(const struct option *opt, const char *arg, int unset)
131
129
return 0 ;
132
130
}
133
131
134
- static struct option builtin_commit_options [] = {
135
- OPT__QUIET (& quiet , "suppress summary after successful commit" ),
136
- OPT__VERBOSE (& verbose , "show diff in commit message template" ),
137
-
138
- OPT_GROUP ("Commit message options" ),
139
- OPT_FILENAME ('F' , "file" , & logfile , "read message from file" ),
140
- OPT_STRING (0 , "author" , & force_author , "author" , "override author for commit" ),
141
- OPT_STRING (0 , "date" , & force_date , "date" , "override date for commit" ),
142
- OPT_CALLBACK ('m' , "message" , & message , "message" , "commit message" , opt_parse_m ),
143
- OPT_STRING ('c' , "reedit-message" , & edit_message , "commit" , "reuse and edit message from specified commit" ),
144
- OPT_STRING ('C' , "reuse-message" , & use_message , "commit" , "reuse message from specified commit" ),
145
- OPT_STRING (0 , "fixup" , & fixup_message , "commit" , "use autosquash formatted message to fixup specified commit" ),
146
- OPT_STRING (0 , "squash" , & squash_message , "commit" , "use autosquash formatted message to squash specified commit" ),
147
- OPT_BOOLEAN (0 , "reset-author" , & renew_authorship , "the commit is authored by me now (used with -C/-c/--amend)" ),
148
- OPT_BOOLEAN ('s' , "signoff" , & signoff , "add Signed-off-by:" ),
149
- OPT_FILENAME ('t' , "template" , & template_file , "use specified template file" ),
150
- OPT_BOOL ('e' , "edit" , & edit_flag , "force edit of commit" ),
151
- OPT_STRING (0 , "cleanup" , & cleanup_arg , "default" , "how to strip spaces and #comments from message" ),
152
- OPT_BOOLEAN (0 , "status" , & include_status , "include status in commit message template" ),
153
- { OPTION_STRING , 'S' , "gpg-sign" , & sign_commit , "key id" ,
154
- "GPG sign commit" , PARSE_OPT_OPTARG , NULL , (intptr_t ) "" },
155
- /* end commit message options */
156
-
157
- OPT_GROUP ("Commit contents options" ),
158
- OPT_BOOLEAN ('a' , "all" , & all , "commit all changed files" ),
159
- OPT_BOOLEAN ('i' , "include" , & also , "add specified files to index for commit" ),
160
- OPT_BOOLEAN (0 , "interactive" , & interactive , "interactively add files" ),
161
- OPT_BOOLEAN ('p' , "patch" , & patch_interactive , "interactively add changes" ),
162
- OPT_BOOLEAN ('o' , "only" , & only , "commit only specified files" ),
163
- OPT_BOOLEAN ('n' , "no-verify" , & no_verify , "bypass pre-commit hook" ),
164
- OPT_BOOLEAN (0 , "dry-run" , & dry_run , "show what would be committed" ),
165
- OPT_SET_INT (0 , "short" , & status_format , "show status concisely" ,
166
- STATUS_FORMAT_SHORT ),
167
- OPT_BOOLEAN (0 , "branch" , & status_show_branch , "show branch information" ),
168
- OPT_SET_INT (0 , "porcelain" , & status_format ,
169
- "machine-readable output" , STATUS_FORMAT_PORCELAIN ),
170
- OPT_BOOLEAN ('z' , "null" , & null_termination ,
171
- "terminate entries with NUL" ),
172
- OPT_BOOLEAN (0 , "amend" , & amend , "amend previous commit" ),
173
- OPT_BOOLEAN (0 , "no-post-rewrite" , & no_post_rewrite , "bypass post-rewrite hook" ),
174
- { OPTION_STRING , 'u' , "untracked-files" , & untracked_files_arg , "mode" , "show untracked files, optional modes: all, normal, no. (Default: all)" , PARSE_OPT_OPTARG , NULL , (intptr_t )"all" },
175
- /* end commit contents options */
176
-
177
- { OPTION_BOOLEAN , 0 , "allow-empty" , & allow_empty , NULL ,
178
- "ok to record an empty change" ,
179
- PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
180
- { OPTION_BOOLEAN , 0 , "allow-empty-message" , & allow_empty_message , NULL ,
181
- "ok to record a change with an empty message" ,
182
- PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
183
-
184
- OPT_END ()
185
- };
186
-
187
132
static void determine_whence (struct wt_status * s )
188
133
{
189
134
if (file_exists (git_path ("MERGE_HEAD" )))
@@ -501,10 +446,10 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
501
446
502
447
switch (status_format ) {
503
448
case STATUS_FORMAT_SHORT :
504
- wt_shortstatus_print (s , null_termination , status_show_branch );
449
+ wt_shortstatus_print (s );
505
450
break ;
506
451
case STATUS_FORMAT_PORCELAIN :
507
- wt_porcelain_print (s , null_termination );
452
+ wt_porcelain_print (s );
508
453
break ;
509
454
case STATUS_FORMAT_LONG :
510
455
wt_status_print (s );
@@ -1037,15 +982,15 @@ static const char *read_commit_message(const char *name)
1037
982
}
1038
983
1039
984
static int parse_and_validate_options (int argc , const char * argv [],
985
+ const struct option * options ,
1040
986
const char * const usage [],
1041
987
const char * prefix ,
1042
988
struct commit * current_head ,
1043
989
struct wt_status * s )
1044
990
{
1045
991
int f = 0 ;
1046
992
1047
- argc = parse_options (argc , argv , prefix , builtin_commit_options , usage ,
1048
- 0 );
993
+ argc = parse_options (argc , argv , prefix , options , usage , 0 );
1049
994
1050
995
if (force_author && !strchr (force_author , '>' ))
1051
996
force_author = find_author_by_nickname (force_author );
@@ -1130,7 +1075,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
1130
1075
if (all && argc > 0 )
1131
1076
die (_ ("Paths with -a does not make sense." ));
1132
1077
1133
- if (null_termination && status_format == STATUS_FORMAT_LONG )
1078
+ if (s -> null_termination && status_format == STATUS_FORMAT_LONG )
1134
1079
status_format = STATUS_FORMAT_PORCELAIN ;
1135
1080
if (status_format != STATUS_FORMAT_LONG )
1136
1081
dry_run = 1 ;
@@ -1219,19 +1164,19 @@ static int git_status_config(const char *k, const char *v, void *cb)
1219
1164
1220
1165
int cmd_status (int argc , const char * * argv , const char * prefix )
1221
1166
{
1222
- struct wt_status s ;
1167
+ static struct wt_status s ;
1223
1168
int fd ;
1224
1169
unsigned char sha1 [20 ];
1225
1170
static struct option builtin_status_options [] = {
1226
1171
OPT__VERBOSE (& verbose , "be verbose" ),
1227
1172
OPT_SET_INT ('s' , "short" , & status_format ,
1228
1173
"show status concisely" , STATUS_FORMAT_SHORT ),
1229
- OPT_BOOLEAN ('b' , "branch" , & status_show_branch ,
1174
+ OPT_BOOLEAN ('b' , "branch" , & s . show_branch ,
1230
1175
"show branch information" ),
1231
1176
OPT_SET_INT (0 , "porcelain" , & status_format ,
1232
1177
"machine-readable output" ,
1233
1178
STATUS_FORMAT_PORCELAIN ),
1234
- OPT_BOOLEAN ('z' , "null" , & null_termination ,
1179
+ OPT_BOOLEAN ('z' , "null" , & s . null_termination ,
1235
1180
"terminate entries with NUL" ),
1236
1181
{ OPTION_STRING , 'u' , "untracked-files" , & untracked_files_arg ,
1237
1182
"mode" ,
@@ -1259,7 +1204,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1259
1204
finalize_colopts (& colopts , -1 );
1260
1205
s .colopts = colopts ;
1261
1206
1262
- if (null_termination && status_format == STATUS_FORMAT_LONG )
1207
+ if (s . null_termination && status_format == STATUS_FORMAT_LONG )
1263
1208
status_format = STATUS_FORMAT_PORCELAIN ;
1264
1209
1265
1210
handle_untracked_files_arg (& s );
@@ -1284,10 +1229,10 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1284
1229
1285
1230
switch (status_format ) {
1286
1231
case STATUS_FORMAT_SHORT :
1287
- wt_shortstatus_print (& s , null_termination , status_show_branch );
1232
+ wt_shortstatus_print (& s );
1288
1233
break ;
1289
1234
case STATUS_FORMAT_PORCELAIN :
1290
- wt_porcelain_print (& s , null_termination );
1235
+ wt_porcelain_print (& s );
1291
1236
break ;
1292
1237
case STATUS_FORMAT_LONG :
1293
1238
s .verbose = verbose ;
@@ -1422,6 +1367,60 @@ static int run_rewrite_hook(const unsigned char *oldsha1,
1422
1367
1423
1368
int cmd_commit (int argc , const char * * argv , const char * prefix )
1424
1369
{
1370
+ static struct wt_status s ;
1371
+ static struct option builtin_commit_options [] = {
1372
+ OPT__QUIET (& quiet , "suppress summary after successful commit" ),
1373
+ OPT__VERBOSE (& verbose , "show diff in commit message template" ),
1374
+
1375
+ OPT_GROUP ("Commit message options" ),
1376
+ OPT_FILENAME ('F' , "file" , & logfile , "read message from file" ),
1377
+ OPT_STRING (0 , "author" , & force_author , "author" , "override author for commit" ),
1378
+ OPT_STRING (0 , "date" , & force_date , "date" , "override date for commit" ),
1379
+ OPT_CALLBACK ('m' , "message" , & message , "message" , "commit message" , opt_parse_m ),
1380
+ OPT_STRING ('c' , "reedit-message" , & edit_message , "commit" , "reuse and edit message from specified commit" ),
1381
+ OPT_STRING ('C' , "reuse-message" , & use_message , "commit" , "reuse message from specified commit" ),
1382
+ OPT_STRING (0 , "fixup" , & fixup_message , "commit" , "use autosquash formatted message to fixup specified commit" ),
1383
+ OPT_STRING (0 , "squash" , & squash_message , "commit" , "use autosquash formatted message to squash specified commit" ),
1384
+ OPT_BOOLEAN (0 , "reset-author" , & renew_authorship , "the commit is authored by me now (used with -C/-c/--amend)" ),
1385
+ OPT_BOOLEAN ('s' , "signoff" , & signoff , "add Signed-off-by:" ),
1386
+ OPT_FILENAME ('t' , "template" , & template_file , "use specified template file" ),
1387
+ OPT_BOOL ('e' , "edit" , & edit_flag , "force edit of commit" ),
1388
+ OPT_STRING (0 , "cleanup" , & cleanup_arg , "default" , "how to strip spaces and #comments from message" ),
1389
+ OPT_BOOLEAN (0 , "status" , & include_status , "include status in commit message template" ),
1390
+ { OPTION_STRING , 'S' , "gpg-sign" , & sign_commit , "key id" ,
1391
+ "GPG sign commit" , PARSE_OPT_OPTARG , NULL , (intptr_t ) "" },
1392
+ /* end commit message options */
1393
+
1394
+ OPT_GROUP ("Commit contents options" ),
1395
+ OPT_BOOLEAN ('a' , "all" , & all , "commit all changed files" ),
1396
+ OPT_BOOLEAN ('i' , "include" , & also , "add specified files to index for commit" ),
1397
+ OPT_BOOLEAN (0 , "interactive" , & interactive , "interactively add files" ),
1398
+ OPT_BOOLEAN ('p' , "patch" , & patch_interactive , "interactively add changes" ),
1399
+ OPT_BOOLEAN ('o' , "only" , & only , "commit only specified files" ),
1400
+ OPT_BOOLEAN ('n' , "no-verify" , & no_verify , "bypass pre-commit hook" ),
1401
+ OPT_BOOLEAN (0 , "dry-run" , & dry_run , "show what would be committed" ),
1402
+ OPT_SET_INT (0 , "short" , & status_format , "show status concisely" ,
1403
+ STATUS_FORMAT_SHORT ),
1404
+ OPT_BOOLEAN (0 , "branch" , & s .show_branch , "show branch information" ),
1405
+ OPT_SET_INT (0 , "porcelain" , & status_format ,
1406
+ "machine-readable output" , STATUS_FORMAT_PORCELAIN ),
1407
+ OPT_BOOLEAN ('z' , "null" , & s .null_termination ,
1408
+ "terminate entries with NUL" ),
1409
+ OPT_BOOLEAN (0 , "amend" , & amend , "amend previous commit" ),
1410
+ OPT_BOOLEAN (0 , "no-post-rewrite" , & no_post_rewrite , "bypass post-rewrite hook" ),
1411
+ { OPTION_STRING , 'u' , "untracked-files" , & untracked_files_arg , "mode" , "show untracked files, optional modes: all, normal, no. (Default: all)" , PARSE_OPT_OPTARG , NULL , (intptr_t )"all" },
1412
+ /* end commit contents options */
1413
+
1414
+ { OPTION_BOOLEAN , 0 , "allow-empty" , & allow_empty , NULL ,
1415
+ "ok to record an empty change" ,
1416
+ PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
1417
+ { OPTION_BOOLEAN , 0 , "allow-empty-message" , & allow_empty_message , NULL ,
1418
+ "ok to record a change with an empty message" ,
1419
+ PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
1420
+
1421
+ OPT_END ()
1422
+ };
1423
+
1425
1424
struct strbuf sb = STRBUF_INIT ;
1426
1425
struct strbuf author_ident = STRBUF_INIT ;
1427
1426
const char * index_file , * reflog_msg ;
@@ -1431,7 +1430,6 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1431
1430
struct commit_list * parents = NULL , * * pptr = & parents ;
1432
1431
struct stat statbuf ;
1433
1432
int allow_fast_forward = 1 ;
1434
- struct wt_status s ;
1435
1433
struct commit * current_head = NULL ;
1436
1434
struct commit_extra_header * extra = NULL ;
1437
1435
@@ -1449,7 +1447,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1449
1447
if (!current_head || parse_commit (current_head ))
1450
1448
die (_ ("could not parse HEAD commit" ));
1451
1449
}
1452
- argc = parse_and_validate_options (argc , argv , builtin_commit_usage ,
1450
+ argc = parse_and_validate_options (argc , argv , builtin_commit_options ,
1451
+ builtin_commit_usage ,
1453
1452
prefix , current_head , & s );
1454
1453
if (dry_run )
1455
1454
return dry_run_commit (argc , argv , prefix , current_head , & s );
0 commit comments