Re: [PATCH v8 40/41] builtin/am: use apply api in run_apply()
From: Junio C Hamano <hidden>
Date: 2016-07-26 19:50:24
Christian Couder [off-list ref] writes:
static int run_apply(const struct am_state *state, const char *index_file)
{
- struct child_process cp = CHILD_PROCESS_INIT;
+ struct argv_array apply_paths = ARGV_ARRAY_INIT;
+ struct argv_array apply_opts = ARGV_ARRAY_INIT;
+ struct apply_state apply_state;
+ int res, opts_left;
+ char *save_index_file;
+ static struct lock_file lock_file;
+
+ struct option am_apply_options[] = {
+ { OPTION_CALLBACK, 0, "whitespace", &apply_state, N_("action"),
+ N_("detect new or modified lines that have whitespace errors"),
+ 0, apply_option_parse_whitespace },
+ { OPTION_CALLBACK, 0, "ignore-space-change", &apply_state, NULL,
+ N_("ignore changes in whitespace when finding context"),
+ PARSE_OPT_NOARG, apply_option_parse_space_change },
+ { OPTION_CALLBACK, 0, "ignore-whitespace", &apply_state, NULL,
+ N_("ignore changes in whitespace when finding context"),
+ PARSE_OPT_NOARG, apply_option_parse_space_change },
+ { OPTION_CALLBACK, 0, "directory", &apply_state, N_("root"),
+ N_("prepend <root> to all filenames"),
+ 0, apply_option_parse_directory },
+ { OPTION_CALLBACK, 0, "exclude", &apply_state, N_("path"),
+ N_("don't apply changes matching the given path"),
+ 0, apply_option_parse_exclude },
+ { OPTION_CALLBACK, 0, "include", &apply_state, N_("path"),
+ N_("apply changes matching the given path"),
+ 0, apply_option_parse_include },
+ OPT_INTEGER('C', NULL, &apply_state.p_context,
+ N_("ensure at least <n> lines of context match")),
+ { OPTION_CALLBACK, 'p', NULL, &apply_state, N_("num"),
+ N_("remove <num> leading slashes from traditional diff paths"),
+ 0, apply_option_parse_p },
+ OPT_BOOL(0, "reject", &apply_state.apply_with_reject,
+ N_("leave the rejected hunks in corresponding *.rej files")),
+ OPT_END()
+ };Is this an indication that this step came too prematurely? Can we avoid having to maintain semi-duplicated options array if cmd_apply() is properly refactored before this step? The resulting code is unmaintainable as long as we have this duplication.