Skip to content

Commit 203c853

Browse files
Denton-Lgitster
authored andcommitted
Use OPT_CALLBACK and OPT_CALLBACK_F
In the codebase, there are many options which use OPTION_CALLBACK in a plain ol' struct definition. However, we have the OPT_CALLBACK and OPT_CALLBACK_F macros which are meant to abstract these plain struct definitions away. These macros are useful as they semantically signal to developers that these are just normal callback option with nothing fancy happening. Replace plain struct definitions of OPTION_CALLBACK with OPT_CALLBACK or OPT_CALLBACK_F where applicable. The heavy lifting was done using the following (disgusting) shell script: #!/bin/sh do_replacement () { tr '\n' '\r' | sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\s*0,\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK(\1,\2,\3,\4,\5,\6)/g' | sed -e 's/{\s*OPTION_CALLBACK,\s*\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\(\s*[^[:space:]}]*\)\s*}/OPT_CALLBACK_F(\1,\2,\3,\4,\5,\6,\7)/g' | tr '\r' '\n' } for f in $(git ls-files \*.c) do do_replacement <"$f" >"$f.tmp" mv "$f.tmp" "$f" done The result was manually inspected and then reformatted to match the style of the surrounding code. Finally, using `git grep OPTION_CALLBACK \*.c`, leftover results which were not handled by the script were manually transformed. Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e870325 commit 203c853

31 files changed

+173
-181
lines changed

apply.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4964,15 +4964,15 @@ int apply_parse_options(int argc, const char **argv,
49644964
const char * const *apply_usage)
49654965
{
49664966
struct option builtin_apply_options[] = {
4967-
{ OPTION_CALLBACK, 0, "exclude", state, N_("path"),
4967+
OPT_CALLBACK_F(0, "exclude", state, N_("path"),
49684968
N_("don't apply changes matching the given path"),
4969-
PARSE_OPT_NONEG, apply_option_parse_exclude },
4970-
{ OPTION_CALLBACK, 0, "include", state, N_("path"),
4969+
PARSE_OPT_NONEG, apply_option_parse_exclude),
4970+
OPT_CALLBACK_F(0, "include", state, N_("path"),
49714971
N_("apply changes matching the given path"),
4972-
PARSE_OPT_NONEG, apply_option_parse_include },
4973-
{ OPTION_CALLBACK, 'p', NULL, state, N_("num"),
4972+
PARSE_OPT_NONEG, apply_option_parse_include),
4973+
OPT_CALLBACK('p', NULL, state, N_("num"),
49744974
N_("remove <num> leading slashes from traditional diff paths"),
4975-
0, apply_option_parse_p },
4975+
apply_option_parse_p),
49764976
OPT_BOOL(0, "no-add", &state->no_add,
49774977
N_("ignore additions made by the patch")),
49784978
OPT_BOOL(0, "stat", &state->diffstat,
@@ -5005,15 +5005,15 @@ int apply_parse_options(int argc, const char **argv,
50055005
N_("paths are separated with NUL character"), '\0'),
50065006
OPT_INTEGER('C', NULL, &state->p_context,
50075007
N_("ensure at least <n> lines of context match")),
5008-
{ OPTION_CALLBACK, 0, "whitespace", state, N_("action"),
5008+
OPT_CALLBACK(0, "whitespace", state, N_("action"),
50095009
N_("detect new or modified lines that have whitespace errors"),
5010-
0, apply_option_parse_whitespace },
5011-
{ OPTION_CALLBACK, 0, "ignore-space-change", state, NULL,
5010+
apply_option_parse_whitespace),
5011+
OPT_CALLBACK_F(0, "ignore-space-change", state, NULL,
50125012
N_("ignore changes in whitespace when finding context"),
5013-
PARSE_OPT_NOARG, apply_option_parse_space_change },
5014-
{ OPTION_CALLBACK, 0, "ignore-whitespace", state, NULL,
5013+
PARSE_OPT_NOARG, apply_option_parse_space_change),
5014+
OPT_CALLBACK_F(0, "ignore-whitespace", state, NULL,
50155015
N_("ignore changes in whitespace when finding context"),
5016-
PARSE_OPT_NOARG, apply_option_parse_space_change },
5016+
PARSE_OPT_NOARG, apply_option_parse_space_change),
50175017
OPT_BOOL('R', "reverse", &state->apply_in_reverse,
50185018
N_("apply the patch in reverse")),
50195019
OPT_BOOL(0, "unidiff-zero", &state->unidiff_zero,
@@ -5029,9 +5029,9 @@ int apply_parse_options(int argc, const char **argv,
50295029
OPT_BIT(0, "recount", options,
50305030
N_("do not trust the line counts in the hunk headers"),
50315031
APPLY_OPT_RECOUNT),
5032-
{ OPTION_CALLBACK, 0, "directory", state, N_("root"),
5032+
OPT_CALLBACK(0, "directory", state, N_("root"),
50335033
N_("prepend <root> to all filenames"),
5034-
0, apply_option_parse_directory },
5034+
apply_option_parse_directory),
50355035
OPT_END()
50365036
};
50375037

builtin/add.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,10 @@ static struct option builtin_add_options[] = {
330330
OPT_BOOL(0, "renormalize", &add_renormalize, N_("renormalize EOL of tracked files (implies -u)")),
331331
OPT_BOOL('N', "intent-to-add", &intent_to_add, N_("record only the fact that the path will be added later")),
332332
OPT_BOOL('A', "all", &addremove_explicit, N_("add changes from all tracked and untracked files")),
333-
{ OPTION_CALLBACK, 0, "ignore-removal", &addremove_explicit,
333+
OPT_CALLBACK_F(0, "ignore-removal", &addremove_explicit,
334334
NULL /* takes no arguments */,
335335
N_("ignore paths removed in the working tree (same as --no-all)"),
336-
PARSE_OPT_NOARG, ignore_removal_cb },
336+
PARSE_OPT_NOARG, ignore_removal_cb),
337337
OPT_BOOL( 0 , "refresh", &refresh_only, N_("don't add, only refresh the index")),
338338
OPT_BOOL( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")),
339339
OPT_BOOL( 0 , "ignore-missing", &ignore_missing, N_("check if - even missing - files are ignored in dry run")),

builtin/blame.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,8 +864,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
864864
OPT_BIT(0, "minimal", &xdl_opts, N_("Spend extra cycles to find better match"), XDF_NEED_MINIMAL),
865865
OPT_STRING('S', NULL, &revs_file, N_("file"), N_("Use revisions from <file> instead of calling git-rev-list")),
866866
OPT_STRING(0, "contents", &contents_from, N_("file"), N_("Use <file>'s contents as the final image")),
867-
{ OPTION_CALLBACK, 'C', NULL, &opt, N_("score"), N_("Find line copies within and across files"), PARSE_OPT_OPTARG, blame_copy_callback },
868-
{ OPTION_CALLBACK, 'M', NULL, &opt, N_("score"), N_("Find line movements within and across files"), PARSE_OPT_OPTARG, blame_move_callback },
867+
OPT_CALLBACK_F('C', NULL, &opt, N_("score"), N_("Find line copies within and across files"), PARSE_OPT_OPTARG, blame_copy_callback),
868+
OPT_CALLBACK_F('M', NULL, &opt, N_("score"), N_("Find line movements within and across files"), PARSE_OPT_OPTARG, blame_move_callback),
869869
OPT_STRING_LIST('L', NULL, &range_list, N_("n,m"), N_("Process only line range n,m, counting from 1")),
870870
OPT__ABBREV(&abbrev),
871871
OPT_END()

builtin/branch.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -653,10 +653,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
653653
OPT_NO_MERGED(&filter, N_("print only branches that are not merged")),
654654
OPT_COLUMN(0, "column", &colopts, N_("list branches in columns")),
655655
OPT_REF_SORT(sorting_tail),
656-
{
657-
OPTION_CALLBACK, 0, "points-at", &filter.points_at, N_("object"),
658-
N_("print only branches of the object"), 0, parse_opt_object_name
659-
},
656+
OPT_CALLBACK(0, "points-at", &filter.points_at, N_("object"),
657+
N_("print only branches of the object"), parse_opt_object_name),
660658
OPT_BOOL('i', "ignore-case", &icase, N_("sorting and filtering are case insensitive")),
661659
OPT_STRING( 0 , "format", &format.format, N_("format"), N_("format to use for the output")),
662660
OPT_END(),

builtin/cat-file.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -650,14 +650,14 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
650650
OPT_BOOL(0, "allow-unknown-type", &unknown_type,
651651
N_("allow -s and -t to work with broken/corrupt objects")),
652652
OPT_BOOL(0, "buffer", &batch.buffer_output, N_("buffer --batch output")),
653-
{ OPTION_CALLBACK, 0, "batch", &batch, "format",
653+
OPT_CALLBACK_F(0, "batch", &batch, "format",
654654
N_("show info and content of objects fed from the standard input"),
655655
PARSE_OPT_OPTARG | PARSE_OPT_NONEG,
656-
batch_option_callback },
657-
{ OPTION_CALLBACK, 0, "batch-check", &batch, "format",
656+
batch_option_callback),
657+
OPT_CALLBACK_F(0, "batch-check", &batch, "format",
658658
N_("show info about objects fed from the standard input"),
659659
PARSE_OPT_OPTARG | PARSE_OPT_NONEG,
660-
batch_option_callback },
660+
batch_option_callback),
661661
OPT_BOOL(0, "follow-symlinks", &batch.follow_symlinks,
662662
N_("follow in-tree symlinks (used with --batch or --batch-check)")),
663663
OPT_BOOL(0, "batch-all-objects", &batch.all_objects,

builtin/checkout-index.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
177177
N_("write the content to temporary files")),
178178
OPT_STRING(0, "prefix", &state.base_dir, N_("string"),
179179
N_("when creating files, prepend <string>")),
180-
{ OPTION_CALLBACK, 0, "stage", NULL, "(1|2|3|all)",
180+
OPT_CALLBACK_F(0, "stage", NULL, "(1|2|3|all)",
181181
N_("copy out the files from named stage"),
182-
PARSE_OPT_NONEG, option_parse_stage },
182+
PARSE_OPT_NONEG, option_parse_stage),
183183
OPT_END()
184184
};
185185

builtin/checkout.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,9 +1486,9 @@ static struct option *add_common_options(struct checkout_opts *opts,
14861486
{
14871487
struct option options[] = {
14881488
OPT__QUIET(&opts->quiet, N_("suppress progress reporting")),
1489-
{ OPTION_CALLBACK, 0, "recurse-submodules", NULL,
1489+
OPT_CALLBACK_F(0, "recurse-submodules", NULL,
14901490
"checkout", "control recursive updating of submodules",
1491-
PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater },
1491+
PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater),
14921492
OPT_BOOL(0, "progress", &opts->show_progress, N_("force progress reporting")),
14931493
OPT_BOOL('m', "merge", &opts->merge, N_("perform a 3-way merge with the new branch")),
14941494
OPT_STRING(0, "conflict", &opts->conflict_style, N_("style"),

builtin/clean.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,8 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
906906
OPT_BOOL('i', "interactive", &interactive, N_("interactive cleaning")),
907907
OPT_BOOL('d', NULL, &remove_directories,
908908
N_("remove whole directories")),
909-
{ OPTION_CALLBACK, 'e', "exclude", &exclude_list, N_("pattern"),
910-
N_("add <pattern> to ignore rules"), PARSE_OPT_NONEG, exclude_cb },
909+
OPT_CALLBACK_F('e', "exclude", &exclude_list, N_("pattern"),
910+
N_("add <pattern> to ignore rules"), PARSE_OPT_NONEG, exclude_cb),
911911
OPT_BOOL('x', NULL, &ignored, N_("remove ignored files, too")),
912912
OPT_BOOL('X', NULL, &ignored_only,
913913
N_("remove only ignored files")),

builtin/commit-tree.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
108108
struct object_id commit_oid;
109109

110110
struct option options[] = {
111-
{ OPTION_CALLBACK, 'p', NULL, &parents, N_("parent"),
111+
OPT_CALLBACK_F('p', NULL, &parents, N_("parent"),
112112
N_("id of a parent commit object"), PARSE_OPT_NONEG,
113-
parse_parent_arg_callback },
114-
{ OPTION_CALLBACK, 'm', NULL, &buffer, N_("message"),
113+
parse_parent_arg_callback),
114+
OPT_CALLBACK_F('m', NULL, &buffer, N_("message"),
115115
N_("commit message"), PARSE_OPT_NONEG,
116-
parse_message_arg_callback },
117-
{ OPTION_CALLBACK, 'F', NULL, &buffer, N_("file"),
116+
parse_message_arg_callback),
117+
OPT_CALLBACK_F('F', NULL, &buffer, N_("file"),
118118
N_("read commit log message from file"), PARSE_OPT_NONEG,
119-
parse_file_arg_callback },
119+
parse_file_arg_callback),
120120
{ OPTION_STRING, 'S', "gpg-sign", &sign_commit, N_("key-id"),
121121
N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
122122
OPT_END()

builtin/commit.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,9 +1372,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13721372
N_("show stash information")),
13731373
OPT_BOOL(0, "ahead-behind", &s.ahead_behind_flags,
13741374
N_("compute full ahead/behind values")),
1375-
{ OPTION_CALLBACK, 0, "porcelain", &status_format,
1375+
OPT_CALLBACK_F(0, "porcelain", &status_format,
13761376
N_("version"), N_("machine-readable output"),
1377-
PARSE_OPT_OPTARG, opt_parse_porcelain },
1377+
PARSE_OPT_OPTARG, opt_parse_porcelain),
13781378
OPT_SET_INT(0, "long", &status_format,
13791379
N_("show status in long format (default)"),
13801380
STATUS_FORMAT_LONG),
@@ -1393,9 +1393,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13931393
PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
13941394
OPT_COLUMN(0, "column", &s.colopts, N_("list untracked files in columns")),
13951395
OPT_BOOL(0, "no-renames", &no_renames, N_("do not detect renames")),
1396-
{ OPTION_CALLBACK, 'M', "find-renames", &rename_score_arg,
1396+
OPT_CALLBACK_F('M', "find-renames", &rename_score_arg,
13971397
N_("n"), N_("detect renames, optionally set similarity index"),
1398-
PARSE_OPT_OPTARG | PARSE_OPT_NONEG, opt_parse_rename_score },
1398+
PARSE_OPT_OPTARG | PARSE_OPT_NONEG, opt_parse_rename_score),
13991399
OPT_END(),
14001400
};
14011401

0 commit comments

Comments
 (0)