summaryrefslogtreecommitdiff
path: root/apply.c
diff options
context:
space:
mode:
authorDenton Liu <liu.denton@gmail.com>2020-04-28 04:36:28 -0400
committerJunio C Hamano <gitster@pobox.com>2020-04-28 10:47:10 -0700
commit203c85339fb51bb8b83aae8f0adde44d6e55e018 (patch)
tree177514cadc9a148394749b130ed168ccff57c7d8 /apply.c
parente870325ee8575d5c3d7afe0ba2c9be072c692b65 (diff)
downloadgit-203c85339fb51bb8b83aae8f0adde44d6e55e018.tar.gz
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 <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'apply.c')
-rw-r--r--apply.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/apply.c b/apply.c
index 144c19aaca..8bff604dbe 100644
--- a/apply.c
+++ b/apply.c
@@ -4964,15 +4964,15 @@ int apply_parse_options(int argc, const char **argv,
const char * const *apply_usage)
{
struct option builtin_apply_options[] = {
- { OPTION_CALLBACK, 0, "exclude", state, N_("path"),
+ OPT_CALLBACK_F(0, "exclude", state, N_("path"),
N_("don't apply changes matching the given path"),
- PARSE_OPT_NONEG, apply_option_parse_exclude },
- { OPTION_CALLBACK, 0, "include", state, N_("path"),
+ PARSE_OPT_NONEG, apply_option_parse_exclude),
+ OPT_CALLBACK_F(0, "include", state, N_("path"),
N_("apply changes matching the given path"),
- PARSE_OPT_NONEG, apply_option_parse_include },
- { OPTION_CALLBACK, 'p', NULL, state, N_("num"),
+ PARSE_OPT_NONEG, apply_option_parse_include),
+ OPT_CALLBACK('p', NULL, state, N_("num"),
N_("remove <num> leading slashes from traditional diff paths"),
- 0, apply_option_parse_p },
+ apply_option_parse_p),
OPT_BOOL(0, "no-add", &state->no_add,
N_("ignore additions made by the patch")),
OPT_BOOL(0, "stat", &state->diffstat,
@@ -5005,15 +5005,15 @@ int apply_parse_options(int argc, const char **argv,
N_("paths are separated with NUL character"), '\0'),
OPT_INTEGER('C', NULL, &state->p_context,
N_("ensure at least <n> lines of context match")),
- { OPTION_CALLBACK, 0, "whitespace", state, N_("action"),
+ OPT_CALLBACK(0, "whitespace", state, N_("action"),
N_("detect new or modified lines that have whitespace errors"),
- 0, apply_option_parse_whitespace },
- { OPTION_CALLBACK, 0, "ignore-space-change", state, NULL,
+ apply_option_parse_whitespace),
+ OPT_CALLBACK_F(0, "ignore-space-change", state, NULL,
N_("ignore changes in whitespace when finding context"),
- PARSE_OPT_NOARG, apply_option_parse_space_change },
- { OPTION_CALLBACK, 0, "ignore-whitespace", state, NULL,
+ PARSE_OPT_NOARG, apply_option_parse_space_change),
+ OPT_CALLBACK_F(0, "ignore-whitespace", state, NULL,
N_("ignore changes in whitespace when finding context"),
- PARSE_OPT_NOARG, apply_option_parse_space_change },
+ PARSE_OPT_NOARG, apply_option_parse_space_change),
OPT_BOOL('R', "reverse", &state->apply_in_reverse,
N_("apply the patch in reverse")),
OPT_BOOL(0, "unidiff-zero", &state->unidiff_zero,
@@ -5029,9 +5029,9 @@ int apply_parse_options(int argc, const char **argv,
OPT_BIT(0, "recount", options,
N_("do not trust the line counts in the hunk headers"),
APPLY_OPT_RECOUNT),
- { OPTION_CALLBACK, 0, "directory", state, N_("root"),
+ OPT_CALLBACK(0, "directory", state, N_("root"),
N_("prepend <root> to all filenames"),
- 0, apply_option_parse_directory },
+ apply_option_parse_directory),
OPT_END()
};