{"thread":{"id":"59732","subject":"[PATCH] Fix merge_recursive_config()","startedAt":"2023-05-12T00:00:57Z","lastAt":"2023-05-12T00:00:57Z","messageCount":1,"participants":["Felipe Contreras"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"477114","messageId":"20230511235951.2309462-1-felipe.contreras@gmail.com","threadId":"59732","inReplyTo":null,"subject":"[PATCH] Fix merge_recursive_config()","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-05-11T23:59:51Z","receivedAt":"2023-05-12T00:00:57Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"The configuration shouldn't be loaded whenever, it should be loaded\n*before* command options are parsed, so the code has the opportunity to\noverride the configuration.\n\nmerge_recursive_config() erroneously calls git_xmerge_config() directly,\noverriding any previous options, for example `--confligt=diff3`.\n\nTo do this properly git_xmerge_config is explicitly called at the top\nlevel of all the commands that call merge_recursive_config() directly or\nindirectly.\n\nSome commands already do this, for example `git checkout`, others\nprobably don't need it, like `git bisect` or `git diff-tree`. For the\nrest it's added.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin/am.c              | 3 ++-\n builtin/log.c             | 5 +++++\n builtin/merge-recursive.c | 3 +++\n builtin/merge-tree.c      | 4 ++++\n builtin/merge.c           | 4 ++++\n builtin/stash.c           | 5 +++++\n merge-recursive.c         | 1 -\n sequencer.c               | 4 ++++\n 8 files changed, 27 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 5c83f2e003..9d56b434d9 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -44,6 +44,7 @@\n #include \"repository.h\"\n #include \"pretty.h\"\n #include \"wrapper.h\"\n+#include \"xdiff-interface.h\"\n \n /**\n  * Returns the length of the first line of msg.\n@@ -2433,7 +2434,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)\n \tif (argc == 2 && !strcmp(argv[1], \"-h\"))\n \t\tusage_with_options(usage, options);\n \n-\tgit_config(git_default_config, NULL);\n+\tgit_config(git_xmerge_config, NULL);\n \n \tam_state_init(&state);\n \ndiff --git a/builtin/log.c b/builtin/log.c\nindex 676de107d6..50cb422494 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -46,6 +46,7 @@\n #include \"tmp-objdir.h\"\n #include \"tree.h\"\n #include \"write-or-die.h\"\n+#include \"xdiff-interface.h\"\n \n #define MAIL_DEFAULT_WRAP 72\n #define COVER_FROM_AUTO_MAX_SUBJECT_LEN 100\n@@ -567,6 +568,7 @@ static int cmd_log_walk(struct rev_info *rev)\n static int git_log_config(const char *var, const char *value, void *cb)\n {\n \tconst char *slot_name;\n+\tint status;\n \n \tif (!strcmp(var, \"format.pretty\"))\n \t\treturn git_config_string(&fmt_pretty, var, value);\n@@ -613,6 +615,9 @@ static int git_log_config(const char *var, const char *value, void *cb)\n \t\treturn 0;\n \t}\n \n+\tstatus = git_xmerge_config(var, value, NULL);\n+\tif (status)\n+\t\treturn status;\n \treturn git_diff_ui_config(var, value, cb);\n }\n \ndiff --git a/builtin/merge-recursive.c b/builtin/merge-recursive.c\nindex b9e980384a..2bcc354788 100644\n--- a/builtin/merge-recursive.c\n+++ b/builtin/merge-recursive.c\n@@ -9,6 +9,7 @@\n #include \"object-name.h\"\n #include \"repository.h\"\n #include \"xdiff-interface.h\"\n+#include \"config.h\"\n \n static const char builtin_merge_recursive_usage[] =\n \t\"git %s <base>... -- <head> <remote> ...\";\n@@ -35,6 +36,8 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix UNUSED)\n \tchar *better1, *better2;\n \tstruct commit *result;\n \n+\tgit_config(git_xmerge_config, NULL);\n+\n \tinit_merge_options(&o, the_repository);\n \tif (argv[0] && ends_with(argv[0], \"-subtree\"))\n \t\to.subtree_shift = \"\";\ndiff --git a/builtin/merge-tree.c b/builtin/merge-tree.c\nindex aa8040c2a6..59b0323640 100644\n--- a/builtin/merge-tree.c\n+++ b/builtin/merge-tree.c\n@@ -17,6 +17,8 @@\n #include \"merge-blobs.h\"\n #include \"quote.h\"\n #include \"tree.h\"\n+#include \"config.h\"\n+#include \"xdiff-interface.h\"\n \n static int line_termination = '\\n';\n \n@@ -548,6 +550,8 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix)\n \t\tOPT_END()\n \t};\n \n+\tgit_config(git_xmerge_config, NULL);\n+\n \t/* Parse arguments */\n \toriginal_argc = argc - 1; /* ignoring argv[0] */\n \targc = parse_options(argc, argv, prefix, mt_options,\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 8da3e46abb..0c41e89c60 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -53,6 +53,7 @@\n #include \"wt-status.h\"\n #include \"commit-graph.h\"\n #include \"wrapper.h\"\n+#include \"xdiff-interface.h\"\n \n #define DEFAULT_TWOHEAD (1<<0)\n #define DEFAULT_OCTOPUS (1<<1)\n@@ -669,6 +670,9 @@ static int git_merge_config(const char *k, const char *v, void *cb)\n \t}\n \n \tstatus = fmt_merge_msg_config(k, v, cb);\n+\tif (status)\n+\t\treturn status;\n+\tstatus = git_xmerge_config(k, v, NULL);\n \tif (status)\n \t\treturn status;\n \treturn git_diff_ui_config(k, v, cb);\ndiff --git a/builtin/stash.c b/builtin/stash.c\nindex a7e17ffe38..355ea1034c 100644\n--- a/builtin/stash.c\n+++ b/builtin/stash.c\n@@ -25,6 +25,7 @@\n #include \"exec-cmd.h\"\n #include \"reflog.h\"\n #include \"add-interactive.h\"\n+#include \"xdiff-interface.h\"\n \n #define INCLUDE_ALL_FILES 2\n \n@@ -839,6 +840,7 @@ static int show_include_untracked;\n \n static int git_stash_config(const char *var, const char *value, void *cb)\n {\n+\tint status;\n \tif (!strcmp(var, \"stash.showstat\")) {\n \t\tshow_stat = git_config_bool(var, value);\n \t\treturn 0;\n@@ -851,6 +853,9 @@ static int git_stash_config(const char *var, const char *value, void *cb)\n \t\tshow_include_untracked = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n+\tstatus = git_xmerge_config(var, value, NULL);\n+\tif (status)\n+\t\treturn status;\n \treturn git_diff_basic_config(var, value, cb);\n }\n \ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 8e87b6386d..226603f7f8 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -3881,7 +3881,6 @@ static void merge_recursive_config(struct merge_options *opt)\n \t\t} /* avoid erroring on values from future versions of git */\n \t\tfree(value);\n \t}\n-\tgit_config(git_xmerge_config, NULL);\n }\n \n void init_merge_options(struct merge_options *opt,\ndiff --git a/sequencer.c b/sequencer.c\nindex b553b49fbb..22c8530649 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -47,6 +47,7 @@\n #include \"reset.h\"\n #include \"branch.h\"\n #include \"wrapper.h\"\n+#include \"xdiff-interface.h\"\n \n #define GIT_REFLOG_ACTION \"GIT_REFLOG_ACTION\"\n \n@@ -274,6 +275,9 @@ static int git_sequencer_config(const char *k, const char *v, void *cb)\n \tif (opts->action == REPLAY_REVERT && !strcmp(k, \"revert.reference\"))\n \t\topts->commit_use_reference = git_config_bool(k, v);\n \n+\tstatus = git_xmerge_config(k, v, NULL);\n+\tif (status)\n+\t\treturn status;\n \treturn git_diff_basic_config(k, v, NULL);\n }\n \n-- \n2.40.0+fc1\n\n"}]}