@@ -129,59 +129,6 @@ static int opt_parse_m(const struct option *opt, const char *arg, int unset)
129
129
return 0 ;
130
130
}
131
131
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
132
static void determine_whence (struct wt_status * s )
186
133
{
187
134
if (file_exists (git_path ("MERGE_HEAD" )))
@@ -1046,15 +993,15 @@ static const char *read_commit_message(const char *name)
1046
993
}
1047
994
1048
995
static int parse_and_validate_options (int argc , const char * argv [],
996
+ const struct option * options ,
1049
997
const char * const usage [],
1050
998
const char * prefix ,
1051
999
struct commit * current_head ,
1052
1000
struct wt_status * s )
1053
1001
{
1054
1002
int f = 0 ;
1055
1003
1056
- argc = parse_options (argc , argv , prefix , builtin_commit_options , usage ,
1057
- 0 );
1004
+ argc = parse_options (argc , argv , prefix , options , usage , 0 );
1058
1005
1059
1006
if (force_author && !strchr (force_author , '>' ))
1060
1007
force_author = find_author_by_nickname (force_author );
@@ -1222,7 +1169,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
1222
1169
1223
1170
int cmd_status (int argc , const char * * argv , const char * prefix )
1224
1171
{
1225
- struct wt_status s ;
1172
+ static struct wt_status s ;
1226
1173
int fd ;
1227
1174
unsigned char sha1 [20 ];
1228
1175
static struct option builtin_status_options [] = {
@@ -1422,6 +1369,60 @@ static int run_rewrite_hook(const unsigned char *oldsha1,
1422
1369
1423
1370
int cmd_commit (int argc , const char * * argv , const char * prefix )
1424
1371
{
1372
+ static struct wt_status s ;
1373
+ static struct option builtin_commit_options [] = {
1374
+ OPT__QUIET (& quiet , "suppress summary after successful commit" ),
1375
+ OPT__VERBOSE (& verbose , "show diff in commit message template" ),
1376
+
1377
+ OPT_GROUP ("Commit message options" ),
1378
+ OPT_FILENAME ('F' , "file" , & logfile , "read message from file" ),
1379
+ OPT_STRING (0 , "author" , & force_author , "author" , "override author for commit" ),
1380
+ OPT_STRING (0 , "date" , & force_date , "date" , "override date for commit" ),
1381
+ OPT_CALLBACK ('m' , "message" , & message , "message" , "commit message" , opt_parse_m ),
1382
+ OPT_STRING ('c' , "reedit-message" , & edit_message , "commit" , "reuse and edit message from specified commit" ),
1383
+ OPT_STRING ('C' , "reuse-message" , & use_message , "commit" , "reuse message from specified commit" ),
1384
+ OPT_STRING (0 , "fixup" , & fixup_message , "commit" , "use autosquash formatted message to fixup specified commit" ),
1385
+ OPT_STRING (0 , "squash" , & squash_message , "commit" , "use autosquash formatted message to squash specified commit" ),
1386
+ OPT_BOOLEAN (0 , "reset-author" , & renew_authorship , "the commit is authored by me now (used with -C/-c/--amend)" ),
1387
+ OPT_BOOLEAN ('s' , "signoff" , & signoff , "add Signed-off-by:" ),
1388
+ OPT_FILENAME ('t' , "template" , & template_file , "use specified template file" ),
1389
+ OPT_BOOL ('e' , "edit" , & edit_flag , "force edit of commit" ),
1390
+ OPT_STRING (0 , "cleanup" , & cleanup_arg , "default" , "how to strip spaces and #comments from message" ),
1391
+ OPT_BOOLEAN (0 , "status" , & include_status , "include status in commit message template" ),
1392
+ { OPTION_STRING , 'S' , "gpg-sign" , & sign_commit , "key id" ,
1393
+ "GPG sign commit" , PARSE_OPT_OPTARG , NULL , (intptr_t ) "" },
1394
+ /* end commit message options */
1395
+
1396
+ OPT_GROUP ("Commit contents options" ),
1397
+ OPT_BOOLEAN ('a' , "all" , & all , "commit all changed files" ),
1398
+ OPT_BOOLEAN ('i' , "include" , & also , "add specified files to index for commit" ),
1399
+ OPT_BOOLEAN (0 , "interactive" , & interactive , "interactively add files" ),
1400
+ OPT_BOOLEAN ('p' , "patch" , & patch_interactive , "interactively add changes" ),
1401
+ OPT_BOOLEAN ('o' , "only" , & only , "commit only specified files" ),
1402
+ OPT_BOOLEAN ('n' , "no-verify" , & no_verify , "bypass pre-commit hook" ),
1403
+ OPT_BOOLEAN (0 , "dry-run" , & dry_run , "show what would be committed" ),
1404
+ OPT_SET_INT (0 , "short" , & status_format , "show status concisely" ,
1405
+ STATUS_FORMAT_SHORT ),
1406
+ OPT_BOOLEAN (0 , "branch" , & status_show_branch , "show branch information" ),
1407
+ OPT_SET_INT (0 , "porcelain" , & status_format ,
1408
+ "machine-readable output" , STATUS_FORMAT_PORCELAIN ),
1409
+ OPT_BOOLEAN ('z' , "null" , & null_termination ,
1410
+ "terminate entries with NUL" ),
1411
+ OPT_BOOLEAN (0 , "amend" , & amend , "amend previous commit" ),
1412
+ OPT_BOOLEAN (0 , "no-post-rewrite" , & no_post_rewrite , "bypass post-rewrite hook" ),
1413
+ { 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" },
1414
+ /* end commit contents options */
1415
+
1416
+ { OPTION_BOOLEAN , 0 , "allow-empty" , & allow_empty , NULL ,
1417
+ "ok to record an empty change" ,
1418
+ PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
1419
+ { OPTION_BOOLEAN , 0 , "allow-empty-message" , & allow_empty_message , NULL ,
1420
+ "ok to record a change with an empty message" ,
1421
+ PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
1422
+
1423
+ OPT_END ()
1424
+ };
1425
+
1425
1426
struct strbuf sb = STRBUF_INIT ;
1426
1427
struct strbuf author_ident = STRBUF_INIT ;
1427
1428
const char * index_file , * reflog_msg ;
@@ -1431,7 +1432,6 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1431
1432
struct commit_list * parents = NULL , * * pptr = & parents ;
1432
1433
struct stat statbuf ;
1433
1434
int allow_fast_forward = 1 ;
1434
- struct wt_status s ;
1435
1435
struct commit * current_head = NULL ;
1436
1436
struct commit_extra_header * extra = NULL ;
1437
1437
@@ -1449,7 +1449,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1449
1449
if (!current_head || parse_commit (current_head ))
1450
1450
die (_ ("could not parse HEAD commit" ));
1451
1451
}
1452
- argc = parse_and_validate_options (argc , argv , builtin_commit_usage ,
1452
+ argc = parse_and_validate_options (argc , argv , builtin_commit_options ,
1453
+ builtin_commit_usage ,
1453
1454
prefix , current_head , & s );
1454
1455
if (dry_run )
1455
1456
return dry_run_commit (argc , argv , prefix , current_head , & s );
0 commit comments