|
28 | 28 | #include "rerere.h"
|
29 | 29 | #include "prompt.h"
|
30 | 30 | #include "mailinfo.h"
|
| 31 | +#include "apply.h" |
31 | 32 |
|
32 | 33 | /**
|
33 | 34 | * Returns 1 if the file is empty or does not exist, 0 otherwise.
|
@@ -1522,39 +1523,59 @@ static int parse_mail_rebase(struct am_state *state, const char *mail)
|
1522 | 1523 | */
|
1523 | 1524 | static int run_apply(const struct am_state *state, const char *index_file)
|
1524 | 1525 | {
|
1525 |
| - struct child_process cp = CHILD_PROCESS_INIT; |
1526 |
| - |
1527 |
| - cp.git_cmd = 1; |
1528 |
| - |
1529 |
| - if (index_file) |
1530 |
| - argv_array_pushf(&cp.env_array, "GIT_INDEX_FILE=%s", index_file); |
| 1526 | + struct argv_array apply_paths = ARGV_ARRAY_INIT; |
| 1527 | + struct argv_array apply_opts = ARGV_ARRAY_INIT; |
| 1528 | + struct apply_state apply_state; |
| 1529 | + int res, opts_left; |
| 1530 | + static struct lock_file lock_file; |
| 1531 | + int force_apply = 0; |
| 1532 | + int options = 0; |
| 1533 | + |
| 1534 | + if (init_apply_state(&apply_state, NULL, &lock_file)) |
| 1535 | + die("BUG: init_apply_state() failed"); |
| 1536 | + |
| 1537 | + argv_array_push(&apply_opts, "apply"); |
| 1538 | + argv_array_pushv(&apply_opts, state->git_apply_opts.argv); |
| 1539 | + |
| 1540 | + opts_left = apply_parse_options(apply_opts.argc, apply_opts.argv, |
| 1541 | + &apply_state, &force_apply, &options, |
| 1542 | + NULL); |
| 1543 | + |
| 1544 | + if (opts_left != 0) |
| 1545 | + die("unknown option passed through to git apply"); |
| 1546 | + |
| 1547 | + if (index_file) { |
| 1548 | + apply_state.index_file = index_file; |
| 1549 | + apply_state.cached = 1; |
| 1550 | + } else |
| 1551 | + apply_state.check_index = 1; |
1531 | 1552 |
|
1532 | 1553 | /*
|
1533 | 1554 | * If we are allowed to fall back on 3-way merge, don't give false
|
1534 | 1555 | * errors during the initial attempt.
|
1535 | 1556 | */
|
1536 |
| - if (state->threeway && !index_file) { |
1537 |
| - cp.no_stdout = 1; |
1538 |
| - cp.no_stderr = 1; |
1539 |
| - } |
| 1557 | + if (state->threeway && !index_file) |
| 1558 | + apply_state.apply_verbosity = verbosity_silent; |
1540 | 1559 |
|
1541 |
| - argv_array_push(&cp.args, "apply"); |
| 1560 | + if (check_apply_state(&apply_state, force_apply)) |
| 1561 | + die("BUG: check_apply_state() failed"); |
1542 | 1562 |
|
1543 |
| - argv_array_pushv(&cp.args, state->git_apply_opts.argv); |
| 1563 | + argv_array_push(&apply_paths, am_path(state, "patch")); |
1544 | 1564 |
|
1545 |
| - if (index_file) |
1546 |
| - argv_array_push(&cp.args, "--cached"); |
1547 |
| - else |
1548 |
| - argv_array_push(&cp.args, "--index"); |
| 1565 | + res = apply_all_patches(&apply_state, apply_paths.argc, apply_paths.argv, options); |
1549 | 1566 |
|
1550 |
| - argv_array_push(&cp.args, am_path(state, "patch")); |
| 1567 | + argv_array_clear(&apply_paths); |
| 1568 | + argv_array_clear(&apply_opts); |
| 1569 | + clear_apply_state(&apply_state); |
1551 | 1570 |
|
1552 |
| - if (run_command(&cp)) |
1553 |
| - return -1; |
| 1571 | + if (res) |
| 1572 | + return res; |
1554 | 1573 |
|
1555 |
| - /* Reload index as git-apply will have modified it. */ |
1556 |
| - discard_cache(); |
1557 |
| - read_cache_from(index_file ? index_file : get_index_file()); |
| 1574 | + if (index_file) { |
| 1575 | + /* Reload index as apply_all_patches() will have modified it. */ |
| 1576 | + discard_cache(); |
| 1577 | + read_cache_from(index_file); |
| 1578 | + } |
1558 | 1579 |
|
1559 | 1580 | return 0;
|
1560 | 1581 | }
|
|
0 commit comments