@@ -4730,35 +4730,35 @@ static int apply_patch(struct apply_state *state,
47304730 return res ;
47314731}
47324732
4733- int apply_option_parse_exclude (const struct option * opt ,
4734- const char * arg , int unset )
4733+ static int apply_option_parse_exclude (const struct option * opt ,
4734+ const char * arg , int unset )
47354735{
47364736 struct apply_state * state = opt -> value ;
47374737 add_name_limit (state , arg , 1 );
47384738 return 0 ;
47394739}
47404740
4741- int apply_option_parse_include (const struct option * opt ,
4742- const char * arg , int unset )
4741+ static int apply_option_parse_include (const struct option * opt ,
4742+ const char * arg , int unset )
47434743{
47444744 struct apply_state * state = opt -> value ;
47454745 add_name_limit (state , arg , 0 );
47464746 state -> has_include = 1 ;
47474747 return 0 ;
47484748}
47494749
4750- int apply_option_parse_p (const struct option * opt ,
4751- const char * arg ,
4752- int unset )
4750+ static int apply_option_parse_p (const struct option * opt ,
4751+ const char * arg ,
4752+ int unset )
47534753{
47544754 struct apply_state * state = opt -> value ;
47554755 state -> p_value = atoi (arg );
47564756 state -> p_value_known = 1 ;
47574757 return 0 ;
47584758}
47594759
4760- int apply_option_parse_space_change (const struct option * opt ,
4761- const char * arg , int unset )
4760+ static int apply_option_parse_space_change (const struct option * opt ,
4761+ const char * arg , int unset )
47624762{
47634763 struct apply_state * state = opt -> value ;
47644764 if (unset )
@@ -4768,8 +4768,8 @@ int apply_option_parse_space_change(const struct option *opt,
47684768 return 0 ;
47694769}
47704770
4771- int apply_option_parse_whitespace (const struct option * opt ,
4772- const char * arg , int unset )
4771+ static int apply_option_parse_whitespace (const struct option * opt ,
4772+ const char * arg , int unset )
47734773{
47744774 struct apply_state * state = opt -> value ;
47754775 state -> whitespace_option = arg ;
@@ -4778,8 +4778,8 @@ int apply_option_parse_whitespace(const struct option *opt,
47784778 return 0 ;
47794779}
47804780
4781- int apply_option_parse_directory (const struct option * opt ,
4782- const char * arg , int unset )
4781+ static int apply_option_parse_directory (const struct option * opt ,
4782+ const char * arg , int unset )
47834783{
47844784 struct apply_state * state = opt -> value ;
47854785 strbuf_reset (& state -> root );
@@ -4893,3 +4893,80 @@ int apply_all_patches(struct apply_state *state,
48934893 return res ;
48944894 return (res == -1 ? 1 : 128 );
48954895}
4896+
4897+ int apply_parse_options (int argc , const char * * argv ,
4898+ struct apply_state * state ,
4899+ int * force_apply , int * options ,
4900+ const char * const * apply_usage )
4901+ {
4902+ struct option builtin_apply_options [] = {
4903+ { OPTION_CALLBACK , 0 , "exclude" , state , N_ ("path" ),
4904+ N_ ("don't apply changes matching the given path" ),
4905+ 0 , apply_option_parse_exclude },
4906+ { OPTION_CALLBACK , 0 , "include" , state , N_ ("path" ),
4907+ N_ ("apply changes matching the given path" ),
4908+ 0 , apply_option_parse_include },
4909+ { OPTION_CALLBACK , 'p' , NULL , state , N_ ("num" ),
4910+ N_ ("remove <num> leading slashes from traditional diff paths" ),
4911+ 0 , apply_option_parse_p },
4912+ OPT_BOOL (0 , "no-add" , & state -> no_add ,
4913+ N_ ("ignore additions made by the patch" )),
4914+ OPT_BOOL (0 , "stat" , & state -> diffstat ,
4915+ N_ ("instead of applying the patch, output diffstat for the input" )),
4916+ OPT_NOOP_NOARG (0 , "allow-binary-replacement" ),
4917+ OPT_NOOP_NOARG (0 , "binary" ),
4918+ OPT_BOOL (0 , "numstat" , & state -> numstat ,
4919+ N_ ("show number of added and deleted lines in decimal notation" )),
4920+ OPT_BOOL (0 , "summary" , & state -> summary ,
4921+ N_ ("instead of applying the patch, output a summary for the input" )),
4922+ OPT_BOOL (0 , "check" , & state -> check ,
4923+ N_ ("instead of applying the patch, see if the patch is applicable" )),
4924+ OPT_BOOL (0 , "index" , & state -> check_index ,
4925+ N_ ("make sure the patch is applicable to the current index" )),
4926+ OPT_BOOL (0 , "cached" , & state -> cached ,
4927+ N_ ("apply a patch without touching the working tree" )),
4928+ OPT_BOOL (0 , "unsafe-paths" , & state -> unsafe_paths ,
4929+ N_ ("accept a patch that touches outside the working area" )),
4930+ OPT_BOOL (0 , "apply" , force_apply ,
4931+ N_ ("also apply the patch (use with --stat/--summary/--check)" )),
4932+ OPT_BOOL ('3' , "3way" , & state -> threeway ,
4933+ N_ ( "attempt three-way merge if a patch does not apply" )),
4934+ OPT_FILENAME (0 , "build-fake-ancestor" , & state -> fake_ancestor ,
4935+ N_ ("build a temporary index based on embedded index information" )),
4936+ /* Think twice before adding "--nul" synonym to this */
4937+ OPT_SET_INT ('z' , NULL , & state -> line_termination ,
4938+ N_ ("paths are separated with NUL character" ), '\0' ),
4939+ OPT_INTEGER ('C' , NULL , & state -> p_context ,
4940+ N_ ("ensure at least <n> lines of context match" )),
4941+ { OPTION_CALLBACK , 0 , "whitespace" , state , N_ ("action" ),
4942+ N_ ("detect new or modified lines that have whitespace errors" ),
4943+ 0 , apply_option_parse_whitespace },
4944+ { OPTION_CALLBACK , 0 , "ignore-space-change" , state , NULL ,
4945+ N_ ("ignore changes in whitespace when finding context" ),
4946+ PARSE_OPT_NOARG , apply_option_parse_space_change },
4947+ { OPTION_CALLBACK , 0 , "ignore-whitespace" , state , NULL ,
4948+ N_ ("ignore changes in whitespace when finding context" ),
4949+ PARSE_OPT_NOARG , apply_option_parse_space_change },
4950+ OPT_BOOL ('R' , "reverse" , & state -> apply_in_reverse ,
4951+ N_ ("apply the patch in reverse" )),
4952+ OPT_BOOL (0 , "unidiff-zero" , & state -> unidiff_zero ,
4953+ N_ ("don't expect at least one line of context" )),
4954+ OPT_BOOL (0 , "reject" , & state -> apply_with_reject ,
4955+ N_ ("leave the rejected hunks in corresponding *.rej files" )),
4956+ OPT_BOOL (0 , "allow-overlap" , & state -> allow_overlap ,
4957+ N_ ("allow overlapping hunks" )),
4958+ OPT__VERBOSE (& state -> apply_verbosity , N_ ("be verbose" )),
4959+ OPT_BIT (0 , "inaccurate-eof" , options ,
4960+ N_ ("tolerate incorrectly detected missing new-line at the end of file" ),
4961+ APPLY_OPT_INACCURATE_EOF ),
4962+ OPT_BIT (0 , "recount" , options ,
4963+ N_ ("do not trust the line counts in the hunk headers" ),
4964+ APPLY_OPT_RECOUNT ),
4965+ { OPTION_CALLBACK , 0 , "directory" , state , N_ ("root" ),
4966+ N_ ("prepend <root> to all filenames" ),
4967+ 0 , apply_option_parse_directory },
4968+ OPT_END ()
4969+ };
4970+
4971+ return parse_options (argc , argv , state -> prefix , builtin_apply_options , apply_usage , 0 );
4972+ }
0 commit comments