2005-05-23 17:52:17 +00:00
|
|
|
#include "cache.h"
|
2006-05-23 12:15:34 +00:00
|
|
|
#include "builtin.h"
|
2008-12-27 23:03:57 +00:00
|
|
|
#include "parse-options.h"
|
2016-04-22 18:55:46 +00:00
|
|
|
#include "lockfile.h"
|
2016-08-08 21:02:59 +00:00
|
|
|
#include "apply.h"
|
2016-05-11 13:16:19 +00:00
|
|
|
|
2008-12-27 23:03:57 +00:00
|
|
|
static const char * const apply_usage[] = {
|
2015-01-13 07:44:47 +00:00
|
|
|
N_("git apply [<options>] [<patch>...]"),
|
2008-12-27 23:03:57 +00:00
|
|
|
NULL
|
|
|
|
};
|
2005-05-23 17:52:17 +00:00
|
|
|
|
2006-06-06 19:51:49 +00:00
|
|
|
static struct lock_file lock_file;
|
2005-06-05 21:05:43 +00:00
|
|
|
|
2016-05-24 08:11:24 +00:00
|
|
|
int cmd_apply(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
2008-12-27 23:03:57 +00:00
|
|
|
int force_apply = 0;
|
2016-05-11 13:16:17 +00:00
|
|
|
int options = 0;
|
2016-05-24 08:11:24 +00:00
|
|
|
int ret;
|
2016-05-11 13:16:19 +00:00
|
|
|
struct apply_state state;
|
2005-05-23 17:52:17 +00:00
|
|
|
|
2008-12-27 23:03:57 +00:00
|
|
|
struct option builtin_apply_options[] = {
|
2016-05-24 08:11:07 +00:00
|
|
|
{ OPTION_CALLBACK, 0, "exclude", &state, N_("path"),
|
2012-05-06 14:23:52 +00:00
|
|
|
N_("don't apply changes matching the given path"),
|
2016-09-04 20:18:20 +00:00
|
|
|
0, apply_option_parse_exclude },
|
2016-05-24 08:11:07 +00:00
|
|
|
{ OPTION_CALLBACK, 0, "include", &state, N_("path"),
|
2012-05-06 14:23:52 +00:00
|
|
|
N_("apply changes matching the given path"),
|
2016-09-04 20:18:20 +00:00
|
|
|
0, apply_option_parse_include },
|
2016-05-24 08:11:09 +00:00
|
|
|
{ OPTION_CALLBACK, 'p', NULL, &state, N_("num"),
|
2012-05-06 14:23:52 +00:00
|
|
|
N_("remove <num> leading slashes from traditional diff paths"),
|
2016-09-04 20:18:20 +00:00
|
|
|
0, apply_option_parse_p },
|
2016-05-24 08:11:00 +00:00
|
|
|
OPT_BOOL(0, "no-add", &state.no_add,
|
2012-05-06 14:23:52 +00:00
|
|
|
N_("ignore additions made by the patch")),
|
2016-05-24 08:10:56 +00:00
|
|
|
OPT_BOOL(0, "stat", &state.diffstat,
|
2012-05-06 14:23:52 +00:00
|
|
|
N_("instead of applying the patch, output diffstat for the input")),
|
2011-09-28 17:47:54 +00:00
|
|
|
OPT_NOOP_NOARG(0, "allow-binary-replacement"),
|
|
|
|
OPT_NOOP_NOARG(0, "binary"),
|
2016-05-24 08:10:57 +00:00
|
|
|
OPT_BOOL(0, "numstat", &state.numstat,
|
2012-08-20 12:32:55 +00:00
|
|
|
N_("show number of added and deleted lines in decimal notation")),
|
2016-05-24 08:10:58 +00:00
|
|
|
OPT_BOOL(0, "summary", &state.summary,
|
2012-05-06 14:23:52 +00:00
|
|
|
N_("instead of applying the patch, output a summary for the input")),
|
2016-05-24 08:10:48 +00:00
|
|
|
OPT_BOOL(0, "check", &state.check,
|
2012-05-06 14:23:52 +00:00
|
|
|
N_("instead of applying the patch, see if the patch is applicable")),
|
2016-05-24 08:10:49 +00:00
|
|
|
OPT_BOOL(0, "index", &state.check_index,
|
2012-05-06 14:23:52 +00:00
|
|
|
N_("make sure the patch is applicable to the current index")),
|
2016-05-24 08:10:55 +00:00
|
|
|
OPT_BOOL(0, "cached", &state.cached,
|
2012-05-06 14:23:52 +00:00
|
|
|
N_("apply a patch without touching the working tree")),
|
2016-05-24 08:11:01 +00:00
|
|
|
OPT_BOOL(0, "unsafe-paths", &state.unsafe_paths,
|
2015-01-29 23:35:24 +00:00
|
|
|
N_("accept a patch that touches outside the working area")),
|
2013-08-03 11:51:19 +00:00
|
|
|
OPT_BOOL(0, "apply", &force_apply,
|
2012-05-06 14:23:52 +00:00
|
|
|
N_("also apply the patch (use with --stat/--summary/--check)")),
|
2016-05-24 08:10:59 +00:00
|
|
|
OPT_BOOL('3', "3way", &state.threeway,
|
2012-07-16 04:38:51 +00:00
|
|
|
N_( "attempt three-way merge if a patch does not apply")),
|
2016-05-24 08:11:03 +00:00
|
|
|
OPT_FILENAME(0, "build-fake-ancestor", &state.fake_ancestor,
|
2012-05-06 14:23:52 +00:00
|
|
|
N_("build a temporary index based on embedded index information")),
|
2016-01-31 11:35:46 +00:00
|
|
|
/* Think twice before adding "--nul" synonym to this */
|
2016-05-24 08:11:02 +00:00
|
|
|
OPT_SET_INT('z', NULL, &state.line_termination,
|
2016-01-31 11:35:46 +00:00
|
|
|
N_("paths are separated with NUL character"), '\0'),
|
2016-05-24 08:11:04 +00:00
|
|
|
OPT_INTEGER('C', NULL, &state.p_context,
|
2012-05-06 14:23:52 +00:00
|
|
|
N_("ensure at least <n> lines of context match")),
|
2016-05-24 08:11:13 +00:00
|
|
|
{ OPTION_CALLBACK, 0, "whitespace", &state, N_("action"),
|
2012-05-06 14:23:52 +00:00
|
|
|
N_("detect new or modified lines that have whitespace errors"),
|
2016-09-04 20:18:20 +00:00
|
|
|
0, apply_option_parse_whitespace },
|
2016-05-24 08:11:18 +00:00
|
|
|
{ OPTION_CALLBACK, 0, "ignore-space-change", &state, NULL,
|
2012-05-06 14:23:52 +00:00
|
|
|
N_("ignore changes in whitespace when finding context"),
|
2016-09-04 20:18:20 +00:00
|
|
|
PARSE_OPT_NOARG, apply_option_parse_space_change },
|
2016-05-24 08:11:18 +00:00
|
|
|
{ OPTION_CALLBACK, 0, "ignore-whitespace", &state, NULL,
|
2012-05-06 14:23:52 +00:00
|
|
|
N_("ignore changes in whitespace when finding context"),
|
2016-09-04 20:18:20 +00:00
|
|
|
PARSE_OPT_NOARG, apply_option_parse_space_change },
|
2016-05-24 08:10:50 +00:00
|
|
|
OPT_BOOL('R', "reverse", &state.apply_in_reverse,
|
2012-05-06 14:23:52 +00:00
|
|
|
N_("apply the patch in reverse")),
|
2016-05-24 08:10:47 +00:00
|
|
|
OPT_BOOL(0, "unidiff-zero", &state.unidiff_zero,
|
2012-05-06 14:23:52 +00:00
|
|
|
N_("don't expect at least one line of context")),
|
2016-05-24 08:10:51 +00:00
|
|
|
OPT_BOOL(0, "reject", &state.apply_with_reject,
|
2012-05-06 14:23:52 +00:00
|
|
|
N_("leave the rejected hunks in corresponding *.rej files")),
|
2016-05-24 08:10:54 +00:00
|
|
|
OPT_BOOL(0, "allow-overlap", &state.allow_overlap,
|
2012-05-06 14:23:52 +00:00
|
|
|
N_("allow overlapping hunks")),
|
2016-09-04 20:18:25 +00:00
|
|
|
OPT__VERBOSE(&state.apply_verbosity, N_("be verbose")),
|
2008-12-27 23:03:57 +00:00
|
|
|
OPT_BIT(0, "inaccurate-eof", &options,
|
2012-05-06 14:23:52 +00:00
|
|
|
N_("tolerate incorrectly detected missing new-line at the end of file"),
|
2016-09-04 20:18:21 +00:00
|
|
|
APPLY_OPT_INACCURATE_EOF),
|
2008-12-27 23:03:57 +00:00
|
|
|
OPT_BIT(0, "recount", &options,
|
2012-05-06 14:23:52 +00:00
|
|
|
N_("do not trust the line counts in the hunk headers"),
|
2016-09-04 20:18:21 +00:00
|
|
|
APPLY_OPT_RECOUNT),
|
2016-05-24 08:11:11 +00:00
|
|
|
{ OPTION_CALLBACK, 0, "directory", &state, N_("root"),
|
2012-05-06 14:23:52 +00:00
|
|
|
N_("prepend <root> to all filenames"),
|
2016-09-04 20:18:20 +00:00
|
|
|
0, apply_option_parse_directory },
|
2008-12-27 23:03:57 +00:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
2016-08-08 21:03:08 +00:00
|
|
|
if (init_apply_state(&state, prefix, &lock_file))
|
|
|
|
exit(128);
|
2007-02-17 20:37:25 +00:00
|
|
|
|
2016-05-11 13:16:19 +00:00
|
|
|
argc = parse_options(argc, argv, state.prefix, builtin_apply_options,
|
2008-12-27 23:03:57 +00:00
|
|
|
apply_usage, 0);
|
2009-05-23 18:53:11 +00:00
|
|
|
|
2016-08-08 21:03:09 +00:00
|
|
|
if (check_apply_state(&state, force_apply))
|
|
|
|
exit(128);
|
2015-01-29 23:35:24 +00:00
|
|
|
|
2016-05-24 08:11:24 +00:00
|
|
|
ret = apply_all_patches(&state, argc, argv, options);
|
2005-05-23 17:52:17 +00:00
|
|
|
|
2016-05-24 08:10:46 +00:00
|
|
|
clear_apply_state(&state);
|
2005-11-26 07:14:15 +00:00
|
|
|
|
2016-05-24 08:11:24 +00:00
|
|
|
return ret;
|
2005-05-23 17:52:17 +00:00
|
|
|
}
|