@@ -109,13 +109,11 @@ static int show_ignored_in_status;
109
109
static const char * only_include_assumed ;
110
110
static struct strbuf message = STRBUF_INIT ;
111
111
112
- static int null_termination ;
113
112
static enum {
114
113
STATUS_FORMAT_LONG ,
115
114
STATUS_FORMAT_SHORT ,
116
115
STATUS_FORMAT_PORCELAIN
117
116
} status_format = STATUS_FORMAT_LONG ;
118
- static int status_show_branch ;
119
117
120
118
static int opt_parse_m (const struct option * opt , const char * arg , int unset )
121
119
{
@@ -129,59 +127,6 @@ static int opt_parse_m(const struct option *opt, const char *arg, int unset)
129
127
return 0 ;
130
128
}
131
129
132
- static struct option builtin_commit_options [] = {
133
- OPT__QUIET (& quiet , "suppress summary after successful commit" ),
134
- OPT__VERBOSE (& verbose , "show diff in commit message template" ),
135
-
136
- OPT_GROUP ("Commit message options" ),
137
- OPT_FILENAME ('F' , "file" , & logfile , "read message from file" ),
138
- OPT_STRING (0 , "author" , & force_author , "author" , "override author for commit" ),
139
- OPT_STRING (0 , "date" , & force_date , "date" , "override date for commit" ),
140
- OPT_CALLBACK ('m' , "message" , & message , "message" , "commit message" , opt_parse_m ),
141
- OPT_STRING ('c' , "reedit-message" , & edit_message , "commit" , "reuse and edit message from specified commit" ),
142
- OPT_STRING ('C' , "reuse-message" , & use_message , "commit" , "reuse message from specified commit" ),
143
- OPT_STRING (0 , "fixup" , & fixup_message , "commit" , "use autosquash formatted message to fixup specified commit" ),
144
- OPT_STRING (0 , "squash" , & squash_message , "commit" , "use autosquash formatted message to squash specified commit" ),
145
- OPT_BOOLEAN (0 , "reset-author" , & renew_authorship , "the commit is authored by me now (used with -C/-c/--amend)" ),
146
- OPT_BOOLEAN ('s' , "signoff" , & signoff , "add Signed-off-by:" ),
147
- OPT_FILENAME ('t' , "template" , & template_file , "use specified template file" ),
148
- OPT_BOOL ('e' , "edit" , & edit_flag , "force edit of commit" ),
149
- OPT_STRING (0 , "cleanup" , & cleanup_arg , "default" , "how to strip spaces and #comments from message" ),
150
- OPT_BOOLEAN (0 , "status" , & include_status , "include status in commit message template" ),
151
- { OPTION_STRING , 'S' , "gpg-sign" , & sign_commit , "key id" ,
152
- "GPG sign commit" , PARSE_OPT_OPTARG , NULL , (intptr_t ) "" },
153
- /* end commit message options */
154
-
155
- OPT_GROUP ("Commit contents options" ),
156
- OPT_BOOLEAN ('a' , "all" , & all , "commit all changed files" ),
157
- OPT_BOOLEAN ('i' , "include" , & also , "add specified files to index for commit" ),
158
- OPT_BOOLEAN (0 , "interactive" , & interactive , "interactively add files" ),
159
- OPT_BOOLEAN ('p' , "patch" , & patch_interactive , "interactively add changes" ),
160
- OPT_BOOLEAN ('o' , "only" , & only , "commit only specified files" ),
161
- OPT_BOOLEAN ('n' , "no-verify" , & no_verify , "bypass pre-commit hook" ),
162
- OPT_BOOLEAN (0 , "dry-run" , & dry_run , "show what would be committed" ),
163
- OPT_SET_INT (0 , "short" , & status_format , "show status concisely" ,
164
- STATUS_FORMAT_SHORT ),
165
- OPT_BOOLEAN (0 , "branch" , & status_show_branch , "show branch information" ),
166
- OPT_SET_INT (0 , "porcelain" , & status_format ,
167
- "machine-readable output" , STATUS_FORMAT_PORCELAIN ),
168
- OPT_BOOLEAN ('z' , "null" , & null_termination ,
169
- "terminate entries with NUL" ),
170
- OPT_BOOLEAN (0 , "amend" , & amend , "amend previous commit" ),
171
- OPT_BOOLEAN (0 , "no-post-rewrite" , & no_post_rewrite , "bypass post-rewrite hook" ),
172
- { 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" },
173
- /* end commit contents options */
174
-
175
- { OPTION_BOOLEAN , 0 , "allow-empty" , & allow_empty , NULL ,
176
- "ok to record an empty change" ,
177
- PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
178
- { OPTION_BOOLEAN , 0 , "allow-empty-message" , & allow_empty_message , NULL ,
179
- "ok to record a change with an empty message" ,
180
- PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
181
-
182
- OPT_END ()
183
- };
184
-
185
130
static void determine_whence (struct wt_status * s )
186
131
{
187
132
if (file_exists (git_path ("MERGE_HEAD" )))
@@ -513,10 +458,10 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
513
458
514
459
switch (status_format ) {
515
460
case STATUS_FORMAT_SHORT :
516
- wt_shortstatus_print (s , null_termination , status_show_branch );
461
+ wt_shortstatus_print (s );
517
462
break ;
518
463
case STATUS_FORMAT_PORCELAIN :
519
- wt_porcelain_print (s , null_termination );
464
+ wt_porcelain_print (s );
520
465
break ;
521
466
case STATUS_FORMAT_LONG :
522
467
wt_status_print (s );
@@ -1046,15 +991,15 @@ static const char *read_commit_message(const char *name)
1046
991
}
1047
992
1048
993
static int parse_and_validate_options (int argc , const char * argv [],
994
+ const struct option * options ,
1049
995
const char * const usage [],
1050
996
const char * prefix ,
1051
997
struct commit * current_head ,
1052
998
struct wt_status * s )
1053
999
{
1054
1000
int f = 0 ;
1055
1001
1056
- argc = parse_options (argc , argv , prefix , builtin_commit_options , usage ,
1057
- 0 );
1002
+ argc = parse_options (argc , argv , prefix , options , usage , 0 );
1058
1003
1059
1004
if (force_author && !strchr (force_author , '>' ))
1060
1005
force_author = find_author_by_nickname (force_author );
@@ -1135,7 +1080,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
1135
1080
if (all && argc > 0 )
1136
1081
die (_ ("Paths with -a does not make sense." ));
1137
1082
1138
- if (null_termination && status_format == STATUS_FORMAT_LONG )
1083
+ if (s -> null_termination && status_format == STATUS_FORMAT_LONG )
1139
1084
status_format = STATUS_FORMAT_PORCELAIN ;
1140
1085
if (status_format != STATUS_FORMAT_LONG )
1141
1086
dry_run = 1 ;
@@ -1222,19 +1167,19 @@ static int git_status_config(const char *k, const char *v, void *cb)
1222
1167
1223
1168
int cmd_status (int argc , const char * * argv , const char * prefix )
1224
1169
{
1225
- struct wt_status s ;
1170
+ static struct wt_status s ;
1226
1171
int fd ;
1227
1172
unsigned char sha1 [20 ];
1228
1173
static struct option builtin_status_options [] = {
1229
1174
OPT__VERBOSE (& verbose , "be verbose" ),
1230
1175
OPT_SET_INT ('s' , "short" , & status_format ,
1231
1176
"show status concisely" , STATUS_FORMAT_SHORT ),
1232
- OPT_BOOLEAN ('b' , "branch" , & status_show_branch ,
1177
+ OPT_BOOLEAN ('b' , "branch" , & s . show_branch ,
1233
1178
"show branch information" ),
1234
1179
OPT_SET_INT (0 , "porcelain" , & status_format ,
1235
1180
"machine-readable output" ,
1236
1181
STATUS_FORMAT_PORCELAIN ),
1237
- OPT_BOOLEAN ('z' , "null" , & null_termination ,
1182
+ OPT_BOOLEAN ('z' , "null" , & s . null_termination ,
1238
1183
"terminate entries with NUL" ),
1239
1184
{ OPTION_STRING , 'u' , "untracked-files" , & untracked_files_arg ,
1240
1185
"mode" ,
@@ -1259,7 +1204,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1259
1204
builtin_status_options ,
1260
1205
builtin_status_usage , 0 );
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