14
#include "diff.h"
15
#include "revision.h"
16
#include "rerere.h"
17
-#include "merge-recursive.h"
17
+#include "merge-ort.h"
18
+#include "merge-ort-wrappers.h"
19
#include "refs.h"
20
#include "strvec.h"
21
#include "quote.h"
205
return 0;
206
}
207
208
+ if (!opts->default_strategy && !strcmp(k, "pull.twohead")) {
209
+ int ret = git_config_string((const char**)&opts->default_strategy, k, v);
210
+ if (ret == 0) {
211
+ /*
212
+ * pull.twohead is allowed to be multi-valued; we only
213
+ * care about the first value.
214
+ */
215
+ char *tmp = strchr(opts->default_strategy, ' ');
216
+ if (tmp)
217
+ *tmp = '\0';
218
+ }
219
+ return ret;
220
+ }
221
+
222
status = git_gpg_config(k, v, NULL);
223
if (status)
224
return status;
332
free(opts->committer_name);
333
free(opts->committer_email);
334
free(opts->gpg_sign);
335
+ free(opts->default_strategy);
336
free(opts->strategy);
337
for (i = 0; i < opts->xopts_nr; i++)
338
free(opts->xopts[i]);
611
struct replay_opts *opts)
612
{
613
struct merge_options o;
614
+ struct merge_result result;
615
struct tree *next_tree, *base_tree, *head_tree;
599
- int clean;
616
+ int clean, show_output;
617
int i;
618
struct lock_file index_lock = LOCK_INIT;
619
637
for (i = 0; i < opts->xopts_nr; i++)
638
parse_merge_opt(&o, opts->xopts[i]);
639
623
- clean = merge_trees(&o,
624
- head_tree,
625
- next_tree, base_tree);
626
- if (is_rebase_i(opts) && clean <= 0)
627
- fputs(o.obuf.buf, stdout);
628
- strbuf_release(&o.obuf);
640
+ if (opts->strategy && !strcmp(opts->strategy, "ort")) {
641
+ memset(&result, 0, sizeof(result));
642
+ merge_incore_nonrecursive(&o, base_tree, head_tree, next_tree,
643
+ &result);
644
+ show_output = !is_rebase_i(opts) || !result.clean;
645
+ /*
646
+ * TODO: merge_switch_to_result will update index/working tree;
647
+ * we only really want to do that if !result.clean || this is
648
+ * the final patch to be picked. But determining this is the
649
+ * final patch would take some work, and "head_tree" would need
650
+ * to be replace with the tree the index matched before we
651
+ * started doing any picks.
652
+ */
653
+ merge_switch_to_result(&o, head_tree, &result, 1, show_output);
654
+ clean = result.clean;
655
+ } else {
656
+ clean = merge_trees(&o, head_tree, next_tree, base_tree);
657
+ if (is_rebase_i(opts) && clean <= 0)
658
+ fputs(o.obuf.buf, stdout);
659
+ strbuf_release(&o.obuf);
660
+ }
661
if (clean < 0) {
662
rollback_lock_file(&index_lock);
663
return clean;
2023
2024
if (is_rebase_i(opts) && write_author_script(msg.message) < 0)
2025
res = -1;
1994
- else if (!opts->strategy || !strcmp(opts->strategy, "recursive") || command == TODO_REVERT) {
2026
+ else if (!opts->strategy ||
2027
+ !strcmp(opts->strategy, "recursive") ||
2028
+ !strcmp(opts->strategy, "ort") ||
2029
+ command == TODO_REVERT) {
2030
res = do_recursive_merge(r, base, next, base_label, next_label,
2031
&head, &msgbuf, opts);
2032
if (res < 0)
3520
struct commit_list *bases, *j, *reversed = NULL;
3521
struct commit_list *to_merge = NULL, **tail = &to_merge;
3522
const char *strategy = !opts->xopts_nr &&
3488
- (!opts->strategy || !strcmp(opts->strategy, "recursive")) ?
3523
+ (!opts->strategy ||
3524
+ !strcmp(opts->strategy, "recursive") ||
3525
+ !strcmp(opts->strategy, "ort")) ?
3526
NULL : opts->strategy;
3527
struct merge_options o;
3528
int merge_arg_len, oneline_offset, can_fast_forward, ret, k;
3759
o.branch2 = ref_name.buf;
3760
o.buffer_output = 2;
3761
3725
- ret = merge_recursive(&o, head_commit, merge_commit, reversed, &i);
3762
+ if (opts->strategy && !strcmp(opts->strategy, "ort")) {
3763
+ /*
3764
+ * TODO: Should use merge_incore_recursive() and
3765
+ * merge_switch_to_result(), skipping the call to
3766
+ * merge_switch_to_result() when we don't actually need to
3767
+ * update the index and working copy immediately.
3768
+ */
3769
+ ret = merge_ort_recursive(&o,
3770
+ head_commit, merge_commit, reversed,
3771
+ &i);
3772
+ } else {
3773
+ ret = merge_recursive(&o, head_commit, merge_commit, reversed,
3774
+ &i);
3775
+ }
3776
if (ret <= 0)
3777
fputs(o.obuf.buf, stdout);
3778
strbuf_release(&o.obuf);