Merge branch 'cc/apply-am'
"git am" has been taught to make an internal call to "git apply"'s innards without spawning the latter as a separate process. * cc/apply-am: (41 commits) builtin/am: use apply API in run_apply() apply: learn to use a different index file apply: pass apply state to build_fake_ancestor() apply: refactor `git apply` option parsing apply: change error_routine when silent usage: add get_error_routine() and get_warn_routine() usage: add set_warn_routine() apply: don't print on stdout in verbosity_silent mode apply: make it possible to silently apply apply: use error_errno() where possible apply: make some parsing functions static again apply: move libified code from builtin/apply.c to apply.{c,h} apply: rename and move opt constants to apply.h builtin/apply: rename option parsing functions builtin/apply: make create_one_file() return -1 on error builtin/apply: make try_create_file() return -1 on error builtin/apply: make write_out_results() return -1 on error builtin/apply: make write_out_one_result() return -1 on error builtin/apply: make create_file() return -1 on error builtin/apply: make add_index_file() return -1 on error ...
This commit is contained in:
71
builtin/am.c
71
builtin/am.c
@ -28,6 +28,7 @@
|
||||
#include "rerere.h"
|
||||
#include "prompt.h"
|
||||
#include "mailinfo.h"
|
||||
#include "apply.h"
|
||||
#include "string-list.h"
|
||||
|
||||
/**
|
||||
@ -1509,40 +1510,60 @@ static int parse_mail_rebase(struct am_state *state, const char *mail)
|
||||
*/
|
||||
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;
|
||||
static struct lock_file lock_file;
|
||||
int force_apply = 0;
|
||||
int options = 0;
|
||||
|
||||
cp.git_cmd = 1;
|
||||
if (init_apply_state(&apply_state, NULL, &lock_file))
|
||||
die("BUG: init_apply_state() failed");
|
||||
|
||||
if (index_file)
|
||||
argv_array_pushf(&cp.env_array, "GIT_INDEX_FILE=%s", index_file);
|
||||
argv_array_push(&apply_opts, "apply");
|
||||
argv_array_pushv(&apply_opts, state->git_apply_opts.argv);
|
||||
|
||||
opts_left = apply_parse_options(apply_opts.argc, apply_opts.argv,
|
||||
&apply_state, &force_apply, &options,
|
||||
NULL);
|
||||
|
||||
if (opts_left != 0)
|
||||
die("unknown option passed through to git apply");
|
||||
|
||||
if (index_file) {
|
||||
apply_state.index_file = index_file;
|
||||
apply_state.cached = 1;
|
||||
} else
|
||||
apply_state.check_index = 1;
|
||||
|
||||
/*
|
||||
* If we are allowed to fall back on 3-way merge, don't give false
|
||||
* errors during the initial attempt.
|
||||
*/
|
||||
if (state->threeway && !index_file) {
|
||||
cp.no_stdout = 1;
|
||||
cp.no_stderr = 1;
|
||||
if (state->threeway && !index_file)
|
||||
apply_state.apply_verbosity = verbosity_silent;
|
||||
|
||||
if (check_apply_state(&apply_state, force_apply))
|
||||
die("BUG: check_apply_state() failed");
|
||||
|
||||
argv_array_push(&apply_paths, am_path(state, "patch"));
|
||||
|
||||
res = apply_all_patches(&apply_state, apply_paths.argc, apply_paths.argv, options);
|
||||
|
||||
argv_array_clear(&apply_paths);
|
||||
argv_array_clear(&apply_opts);
|
||||
clear_apply_state(&apply_state);
|
||||
|
||||
if (res)
|
||||
return res;
|
||||
|
||||
if (index_file) {
|
||||
/* Reload index as apply_all_patches() will have modified it. */
|
||||
discard_cache();
|
||||
read_cache_from(index_file);
|
||||
}
|
||||
|
||||
argv_array_push(&cp.args, "apply");
|
||||
|
||||
argv_array_pushv(&cp.args, state->git_apply_opts.argv);
|
||||
|
||||
if (index_file)
|
||||
argv_array_push(&cp.args, "--cached");
|
||||
else
|
||||
argv_array_push(&cp.args, "--index");
|
||||
|
||||
argv_array_push(&cp.args, am_path(state, "patch"));
|
||||
|
||||
if (run_command(&cp))
|
||||
return -1;
|
||||
|
||||
/* Reload index as git-apply will have modified it. */
|
||||
discard_cache();
|
||||
read_cache_from(index_file ? index_file : get_index_file());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user