Skip to content

Commit f084c50

Browse files
committed
Merge branch 'ad/merge-with-diff-algorithm'
Many Porcelain commands that internally use the merge machinery were taught to consistently honor the diff.algorithm configuration. * ad/merge-with-diff-algorithm: merge-recursive: honor diff.algorithm
2 parents 6a52f30 + 9c93ba4 commit f084c50

15 files changed

+150
-15
lines changed

builtin/am.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
16301630
* changes.
16311631
*/
16321632

1633-
init_merge_options(&o, the_repository);
1633+
init_ui_merge_options(&o, the_repository);
16341634

16351635
o.branch1 = "HEAD";
16361636
their_tree_name = xstrfmt("%.*s", linelen(state->msg), state->msg);

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
884884

885885
add_files_to_cache(the_repository, NULL, NULL, NULL, 0,
886886
0);
887-
init_merge_options(&o, the_repository);
887+
init_ui_merge_options(&o, the_repository);
888888
o.verbosity = 0;
889889
work = write_in_core_index_as_tree(the_repository);
890890

builtin/merge-recursive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix UNUSED)
3131
char *better1, *better2;
3232
struct commit *result;
3333

34-
init_merge_options(&o, the_repository);
34+
init_basic_merge_options(&o, the_repository);
3535
if (argv[0] && ends_with(argv[0], "-subtree"))
3636
o.subtree_shift = "";
3737

builtin/merge-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix)
571571
};
572572

573573
/* Init merge options */
574-
init_merge_options(&o.merge_options, the_repository);
574+
init_ui_merge_options(&o.merge_options, the_repository);
575575

576576
/* Parse arguments */
577577
original_argc = argc - 1; /* ignoring argv[0] */

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
724724
return 2;
725725
}
726726

727-
init_merge_options(&o, the_repository);
727+
init_ui_merge_options(&o, the_repository);
728728
if (!strcmp(strategy, "subtree"))
729729
o.subtree_shift = "";
730730

builtin/replay.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix)
377377
goto cleanup;
378378
}
379379

380-
init_merge_options(&merge_opt, the_repository);
380+
init_basic_merge_options(&merge_opt, the_repository);
381381
memset(&result, 0, sizeof(result));
382382
merge_opt.show_rename_progress = 0;
383383
last_commit = onto;

builtin/stash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
574574
}
575575
}
576576

577-
init_merge_options(&o, the_repository);
577+
init_ui_merge_options(&o, the_repository);
578578

579579
o.branch1 = "Updated upstream";
580580
o.branch2 = "Stashed changes";

log-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ static int do_remerge_diff(struct rev_info *opt,
10251025
struct strbuf parent2_desc = STRBUF_INIT;
10261026

10271027
/* Setup merge options */
1028-
init_merge_options(&o, the_repository);
1028+
init_ui_merge_options(&o, the_repository);
10291029
o.show_rename_progress = 0;
10301030
o.record_conflict_msgs_as_headers = 1;
10311031
o.msg_header_prefix = "remerge";

merge-recursive.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3921,7 +3921,7 @@ int merge_recursive_generic(struct merge_options *opt,
39213921
return clean ? 0 : 1;
39223922
}
39233923

3924-
static void merge_recursive_config(struct merge_options *opt)
3924+
static void merge_recursive_config(struct merge_options *opt, int ui)
39253925
{
39263926
char *value = NULL;
39273927
int renormalize = 0;
@@ -3950,11 +3950,20 @@ static void merge_recursive_config(struct merge_options *opt)
39503950
} /* avoid erroring on values from future versions of git */
39513951
free(value);
39523952
}
3953+
if (ui) {
3954+
if (!git_config_get_string("diff.algorithm", &value)) {
3955+
long diff_algorithm = parse_algorithm_value(value);
3956+
if (diff_algorithm < 0)
3957+
die(_("unknown value for config '%s': %s"), "diff.algorithm", value);
3958+
opt->xdl_opts = (opt->xdl_opts & ~XDF_DIFF_ALGORITHM_MASK) | diff_algorithm;
3959+
free(value);
3960+
}
3961+
}
39533962
git_config(git_xmerge_config, NULL);
39543963
}
39553964

3956-
void init_merge_options(struct merge_options *opt,
3957-
struct repository *repo)
3965+
static void init_merge_options(struct merge_options *opt,
3966+
struct repository *repo, int ui)
39583967
{
39593968
const char *merge_verbosity;
39603969
memset(opt, 0, sizeof(struct merge_options));
@@ -3973,14 +3982,26 @@ void init_merge_options(struct merge_options *opt,
39733982

39743983
opt->conflict_style = -1;
39753984

3976-
merge_recursive_config(opt);
3985+
merge_recursive_config(opt, ui);
39773986
merge_verbosity = getenv("GIT_MERGE_VERBOSITY");
39783987
if (merge_verbosity)
39793988
opt->verbosity = strtol(merge_verbosity, NULL, 10);
39803989
if (opt->verbosity >= 5)
39813990
opt->buffer_output = 0;
39823991
}
39833992

3993+
void init_ui_merge_options(struct merge_options *opt,
3994+
struct repository *repo)
3995+
{
3996+
init_merge_options(opt, repo, 1);
3997+
}
3998+
3999+
void init_basic_merge_options(struct merge_options *opt,
4000+
struct repository *repo)
4001+
{
4002+
init_merge_options(opt, repo, 0);
4003+
}
4004+
39844005
/*
39854006
* For now, members of merge_options do not need deep copying, but
39864007
* it may change in the future, in which case we would need to update

merge-recursive.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ struct merge_options {
5454
struct merge_options_internal *priv;
5555
};
5656

57-
void init_merge_options(struct merge_options *opt, struct repository *repo);
57+
/* for use by porcelain commands */
58+
void init_ui_merge_options(struct merge_options *opt, struct repository *repo);
59+
/* for use by plumbing commands */
60+
void init_basic_merge_options(struct merge_options *opt, struct repository *repo);
5861

5962
void copy_merge_options(struct merge_options *dst, struct merge_options *src);
6063
void clear_merge_options(struct merge_options *opt);

0 commit comments

Comments
 (0)