| 744 | } |
| 745 | |
| 746 | static int do_recursive_merge(struct repository *r, |
| 747 | struct commit *base, struct commit *next, |
| 748 | const char *base_label, const char *next_label, |
| 749 | struct object_id *head, struct strbuf *msgbuf, |
| 750 | struct replay_opts *opts) |
| 751 | { |
| 752 | struct merge_options o; |
| 753 | struct merge_result result; |
| 754 | struct tree *next_tree, *base_tree, *head_tree; |
| 755 | int clean, show_output; |
| 756 | int i; |
| 757 | struct lock_file index_lock = LOCK_INIT; |
| 758 | |
| 759 | if (repo_hold_locked_index(r, &index_lock, LOCK_REPORT_ON_ERROR) < 0) |
| 760 | return -1; |
| 761 | |
| 762 | repo_read_index(r); |
| 763 | |
| 764 | init_ui_merge_options(&o, r); |
| 765 | o.ancestor = base ? base_label : "(empty tree)"; |
| 766 | o.branch1 = "HEAD"; |
| 767 | o.branch2 = next ? next_label : "(empty tree)"; |
| 768 | if (is_rebase_i(opts)) |
| 769 | o.buffer_output = 2; |
| 770 | o.show_rename_progress = 1; |
| 771 | |
| 772 | head_tree = repo_parse_tree_indirect(the_repository, head); |
| 773 | if (!head_tree) |
| 774 | return error(_("unable to read tree (%s)"), oid_to_hex(head)); |
| 775 | next_tree = next ? repo_get_commit_tree(r, next) : empty_tree(r); |
| 776 | base_tree = base ? repo_get_commit_tree(r, base) : empty_tree(r); |
| 777 | |
| 778 | for (i = 0; i < opts->xopts.nr; i++) |
| 779 | parse_merge_opt(&o, opts->xopts.v[i]); |
| 780 | |
| 781 | memset(&result, 0, sizeof(result)); |
| 782 | merge_incore_nonrecursive(&o, base_tree, head_tree, next_tree, &result); |
| 783 | show_output = !is_rebase_i(opts) || !result.clean; |
| 784 | /* |
| 785 | * TODO: merge_switch_to_result will update index/working tree; |
| 786 | * we only really want to do that if !result.clean || this is |
| 787 | * the final patch to be picked. But determining this is the |
| 788 | * final patch would take some work, and "head_tree" would need |
| 789 | * to be replace with the tree the index matched before we |
| 790 | * started doing any picks. |
| 791 | */ |
| 792 | merge_switch_to_result(&o, head_tree, &result, 1, show_output); |
| 793 | clean = result.clean; |
| 794 | if (clean < 0) { |
| 795 | rollback_lock_file(&index_lock); |
| 796 | return clean; |
| 797 | } |
| 798 | |
| 799 | if (write_locked_index(r->index, &index_lock, |
| 800 | COMMIT_LOCK | SKIP_IF_UNCHANGED)) |
| 801 | /* |
| 802 | * TRANSLATORS: %s will be "revert", "cherry-pick" or |
| 803 | * "rebase". |
no test coverage detected