summaryrefslogtreecommitdiff
path: root/builtin/merge.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/merge.c')
-rw-r--r--builtin/merge.c133
1 files changed, 98 insertions, 35 deletions
diff --git a/builtin/merge.c b/builtin/merge.c
index 5f67007bba..ce880e6ccb 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -39,7 +39,6 @@
#include "rerere.h"
#include "help.h"
#include "merge.h"
-#include "merge-recursive.h"
#include "merge-ort-wrappers.h"
#include "resolve-undo.h"
#include "remote.h"
@@ -70,7 +69,10 @@ static const char * const builtin_merge_usage[] = {
NULL
};
-static int show_diffstat = 1, shortlog_len = -1, squash;
+#define MERGE_SHOW_DIFFSTAT 1
+#define MERGE_SHOW_COMPACTSUMMARY 2
+
+static int show_diffstat = MERGE_SHOW_DIFFSTAT, shortlog_len = -1, squash;
static int option_commit = -1;
static int option_edit = -1;
static int allow_trivial = 1, have_message, verify_signatures;
@@ -171,7 +173,7 @@ static struct strategy *get_strategy(const char *name)
struct strategy *ret;
static struct cmdnames main_cmds = {0}, other_cmds = {0};
static int loaded;
- char *default_strategy = getenv("GIT_TEST_MERGE_ALGORITHM");
+ char *default_strategy = NULL;
if (!name)
return NULL;
@@ -244,15 +246,38 @@ static int option_parse_strategy(const struct option *opt UNUSED,
return 0;
}
+static int option_parse_compact_summary(const struct option *opt,
+ const char *name UNUSED, int unset)
+{
+ int *setting = opt->value;
+
+ if (unset)
+ *setting = 0;
+ else
+ *setting = MERGE_SHOW_COMPACTSUMMARY;
+ return 0;
+}
+
static struct option builtin_merge_options[] = {
OPT_SET_INT('n', NULL, &show_diffstat,
N_("do not show a diffstat at the end of the merge"), 0),
OPT_BOOL(0, "stat", &show_diffstat,
N_("show a diffstat at the end of the merge")),
OPT_BOOL(0, "summary", &show_diffstat, N_("(synonym to --stat)")),
- { OPTION_INTEGER, 0, "log", &shortlog_len, N_("n"),
- N_("add (at most <n>) entries from shortlog to merge commit message"),
- PARSE_OPT_OPTARG, NULL, DEFAULT_MERGE_LOG_LEN },
+ OPT_CALLBACK_F(0, "compact-summary", &show_diffstat, NULL,
+ N_("show a compact-summary at the end of the merge"),
+ PARSE_OPT_NOARG,
+ option_parse_compact_summary),
+ {
+ .type = OPTION_INTEGER,
+ .long_name = "log",
+ .value = &shortlog_len,
+ .precision = sizeof(shortlog_len),
+ .argh = N_("n"),
+ .help = N_("add (at most <n>) entries from shortlog to merge commit message"),
+ .flags = PARSE_OPT_OPTARG,
+ .defval = DEFAULT_MERGE_LOG_LEN,
+ },
OPT_BOOL(0, "squash", &squash,
N_("create a single commit instead of doing a merge")),
OPT_BOOL(0, "commit", &option_commit,
@@ -274,9 +299,16 @@ static struct option builtin_merge_options[] = {
OPT_CALLBACK('m', "message", &merge_msg, N_("message"),
N_("merge commit message (for a non-fast-forward merge)"),
option_parse_message),
- { OPTION_LOWLEVEL_CALLBACK, 'F', "file", &merge_msg, N_("path"),
- N_("read message from file"), PARSE_OPT_NONEG,
- NULL, 0, option_read_message },
+ {
+ .type = OPTION_LOWLEVEL_CALLBACK,
+ .short_name = 'F',
+ .long_name = "file",
+ .value = &merge_msg,
+ .argh = N_("path"),
+ .help = N_("read message from file"),
+ .flags = PARSE_OPT_NONEG,
+ .ll_callback = option_read_message,
+ },
OPT_STRING(0, "into-name", &into_name, N_("name"),
N_("use <name> instead of the real target")),
OPT__VERBOSITY(&verbosity),
@@ -289,8 +321,16 @@ static struct option builtin_merge_options[] = {
OPT_BOOL(0, "allow-unrelated-histories", &allow_unrelated_histories,
N_("allow merging unrelated histories")),
OPT_SET_INT(0, "progress", &show_progress, N_("force progress reporting"), 1),
- { OPTION_STRING, 'S', "gpg-sign", &sign_commit, N_("key-id"),
- N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
+ {
+ .type = OPTION_STRING,
+ .short_name = 'S',
+ .long_name = "gpg-sign",
+ .value = &sign_commit,
+ .argh = N_("key-id"),
+ .help = N_("GPG sign commit"),
+ .flags = PARSE_OPT_OPTARG,
+ .defval = (intptr_t) "",
+ },
OPT_AUTOSTASH(&autostash),
OPT_BOOL(0, "overwrite-ignore", &overwrite_ignore, N_("update ignored files (default)")),
OPT_BOOL(0, "signoff", &signoff, N_("add a Signed-off-by trailer")),
@@ -473,8 +513,19 @@ static void finish(struct commit *head_commit,
struct diff_options opts;
repo_diff_setup(the_repository, &opts);
init_diffstat_widths(&opts);
- opts.output_format |=
- DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
+
+ switch (show_diffstat) {
+ case MERGE_SHOW_DIFFSTAT: /* 1 */
+ opts.output_format |=
+ DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
+ break;
+ case MERGE_SHOW_COMPACTSUMMARY: /* 2 */
+ opts.output_format |= DIFF_FORMAT_DIFFSTAT;
+ opts.flags.stat_with_summary = 1;
+ break;
+ default:
+ break;
+ }
opts.detect_rename = DIFF_DETECT_RENAME;
diff_setup_done(&opts);
diff_tree_oid(head, new_head, "", &opts);
@@ -622,7 +673,35 @@ static int git_merge_config(const char *k, const char *v,
}
if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat")) {
- show_diffstat = git_config_bool(k, v);
+ int val = git_parse_maybe_bool_text(v);
+ switch (val) {
+ case 0:
+ show_diffstat = 0;
+ break;
+ case 1:
+ show_diffstat = MERGE_SHOW_DIFFSTAT;
+ break;
+ default:
+ if (!strcmp(v, "compact"))
+ show_diffstat = MERGE_SHOW_COMPACTSUMMARY;
+ /*
+ * We do not need to have an explicit
+ *
+ * else if (!strcmp(v, "diffstat"))
+ * show_diffstat = MERGE_SHOW_DIFFSTAT;
+ *
+ * here, because the catch-all uses the
+ * diffstat style anyway.
+ */
+ else
+ /*
+ * A setting from a future? It is not an
+ * error grave enough to fail the command.
+ * proceed using the default one.
+ */
+ show_diffstat = MERGE_SHOW_DIFFSTAT;
+ break;
+ }
} else if (!strcmp(k, "merge.verifysignatures")) {
verify_signatures = git_config_bool(k, v);
} else if (!strcmp(k, "pull.twohead")) {
@@ -750,12 +829,8 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
repo_hold_locked_index(the_repository, &lock,
LOCK_DIE_ON_ERROR);
- if (!strcmp(strategy, "ort"))
- clean = merge_ort_recursive(&o, head, remoteheads->item,
- reversed, &result);
- else
- clean = merge_recursive(&o, head, remoteheads->item,
- reversed, &result);
+ clean = merge_ort_recursive(&o, head, remoteheads->item,
+ reversed, &result);
free_commit_list(reversed);
strbuf_release(&o.obuf);
@@ -1300,8 +1375,8 @@ int cmd_merge(int argc,
void *branch_to_free;
int orig_argc = argc;
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage_with_options(builtin_merge_usage, builtin_merge_options);
+ show_usage_with_options_if_asked(argc, argv,
+ builtin_merge_usage, builtin_merge_options);
prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0;
@@ -1316,14 +1391,8 @@ int cmd_merge(int argc,
if (branch)
skip_prefix(branch, "refs/heads/", &branch);
- if (!pull_twohead) {
- char *default_strategy = getenv("GIT_TEST_MERGE_ALGORITHM");
- if (default_strategy && !strcmp(default_strategy, "ort"))
- pull_twohead = xstrdup("ort");
- }
-
init_diff_ui_defaults();
- git_config(git_merge_config, NULL);
+ repo_config(the_repository, git_merge_config, NULL);
if (!branch || is_null_oid(&head_oid))
head_commit = NULL;
@@ -1522,12 +1591,6 @@ int cmd_merge(int argc,
fast_forward = FF_NO;
}
- if (!use_strategies && !pull_twohead &&
- remoteheads && !remoteheads->next) {
- char *default_strategy = getenv("GIT_TEST_MERGE_ALGORITHM");
- if (default_strategy)
- append_strategy(get_strategy(default_strategy));
- }
if (!use_strategies) {
if (!remoteheads)
; /* already up-to-date */