/*
* Builtin "git merge"
*
* Copyright (c) 2008 Miklos Vajna <vmiklos@frugalware.org>
*
* Based on git-merge.sh by Junio C Hamano.
*/
#include "cache.h"
#include "parse-options.h"
#include "builtin.h"
#include "run-command.h"
#include "diff.h"
#include "refs.h"
#include "commit.h"
#include "diffcore.h"
#include "revision.h"
#include "unpack-trees.h"
#include "cache-tree.h"
#include "dir.h"
#include "utf8.h"
#include "log-tree.h"
#include "color.h"
#include "rerere.h"
#include "help.h"
#include "merge-recursive.h"
#define DEFAULT_TWOHEAD (1<<0)
#define DEFAULT_OCTOPUS (1<<1)
#define NO_FAST_FORWARD (1<<2)
#define NO_TRIVIAL (1<<3)
struct strategy {
const char *name;
unsigned attr;
};
static const char * const builtin_merge_usage[] = {
"git merge [options] <remote>...",
"git merge [options] <msg> HEAD <remote>",
NULL
};
static int show_diffstat = 1, option_log, squash;
static int option_commit = 1, allow_fast_forward = 1;
static int allow_trivial = 1, have_message;
static struct strbuf merge_msg;
static struct commit_list *remoteheads;
static unsigned char head[20], stash[20];
static struct strategy **use_strategies;
static size_t use_strategies_nr, use_strategies_alloc;
static const char *branch;
static int verbosity;
static struct strategy all_strategy[] = {
{ "recursive", DEFAULT_TWOHEAD | NO_TRIVIAL },
{ "octopus", DEFAULT_OCTOPUS },
{ "resolve", 0 },
{ "ours", NO_FAST_FORWARD | NO_TRIVIAL },
{ "subtree", NO_FAST_FORWARD | NO_TRIVIAL },
};
static const char *pull_twohead, *pull_octopus;
static int option_parse_message(const struct option *opt,
const char *arg, int unset)
{
struct strbuf *buf = opt->value;
if (unset)
strbuf_setlen(buf, 0);
else if (arg) {
strbuf_addf(buf, "%s\n\n", arg);
have_message = 1;
} else
return error("switch `m' requires a value");
return 0;
}
static struct strategy *get_strategy(const char *name)
{
int i;
struct strategy *ret;
static struct cmdnames main_cmds, other_cmds;
static int loaded;
if (!name)
return NULL;
for (i = 0; i < ARRAY_SIZE(all_strategy); i++)
if (!strcmp(name, all_strategy[i].name))
return &all_strategy[i];
if (!loaded) {
struct cmdnames not_strategies;
loaded = 1;
memset(¬_strategies, 0, sizeof(struct cmdnames));
load_command_list("git-merge-", &main_cmds, &other_cmds);
for (i = 0; i < main_cmds.cnt; i++) {
int j, found = 0;
struct cmdname *ent = main_cmds.names[i];
for (j = 0; j < ARRAY_SIZE(all_strategy); j++)
if (!strncmp(ent->name, all_strategy[j].name, ent->len)
&& !all_strategy[j].name[ent->len])
found = 1;
if (!found)
add_cmdname(¬_strategies, ent->name, ent->len);
exclude_cmds(&main_cmds, ¬_strategies);
}
}
if (!is_in_cmdlist(&main_cmds, name) && !is_in_cmdlist(&other_cmds, name)) {
fprintf(stderr, "Could not find merge strategy '%s'.\n", name);
fprintf(stderr, "Available strategies are:");
for (i = 0; i < main_cmds.cnt; i++)
fprintf(stderr, " %s", main_cmds.names[i]->name);
fprintf(stderr, ".\n");
if (other_cmds.cnt) {
fprintf(stderr, "Available custom strategies are:");
for (i = 0; i < other_cmds.cnt; i++)
fprintf(stderr, " %s", other_cmds.names[i]->name);
fprintf(stderr, ".\n");
}
exit(1);
}
ret = xcalloc(1,
|