aboutsummaryrefslogtreecommitdiff
path: root/builtin-merge.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-08-27 17:28:31 -0700
committerJunio C Hamano <gitster@pobox.com>2008-08-27 17:28:31 -0700
commita1184d85e8752658f02746982822f43f32316803 (patch)
treef4508ca7d63ca7e71c3e99cac4e54945f777b1aa /builtin-merge.c
parent8d13caf795902812d44809e2f222fb2334030603 (diff)
parente596cdddf349b244dca854bf5a7aa9428b48fc50 (diff)
downloadgit-a1184d85e8752658f02746982822f43f32316803.tar.gz
git-a1184d85e8752658f02746982822f43f32316803.tar.xz
Merge branch 'mv/merge-custom'
* mv/merge-custom: t7606: fix custom merge test Fix "git-merge -s bogo" help text Update .gitignore to ignore git-help Builtin git-help. builtin-help: always load_command_list() in cmd_help() Add a second testcase for handling invalid strategies in git-merge Add a new test for using a custom merge strategy builtin-merge: allow using a custom strategy builtin-help: make some internal functions available to other builtins Conflicts: help.c
Diffstat (limited to 'builtin-merge.c')
-rw-r--r--builtin-merge.c50
1 files changed, 43 insertions, 7 deletions
diff --git a/builtin-merge.c b/builtin-merge.c
index 0bff26e83..d6bcbec70 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -22,6 +22,7 @@
#include "log-tree.h"
#include "color.h"
#include "rerere.h"
+#include "help.h"
#define DEFAULT_TWOHEAD (1<<0)
#define DEFAULT_OCTOPUS (1<<1)
@@ -77,7 +78,9 @@ static int option_parse_message(const struct option *opt,
static struct strategy *get_strategy(const char *name)
{
int i;
- struct strbuf err;
+ struct strategy *ret;
+ static struct cmdnames main_cmds, other_cmds;
+ static int longest;
if (!name)
return NULL;
@@ -86,12 +89,45 @@ static struct strategy *get_strategy(const char *name)
if (!strcmp(name, all_strategy[i].name))
return &all_strategy[i];
- strbuf_init(&err, 0);
- for (i = 0; i < ARRAY_SIZE(all_strategy); i++)
- strbuf_addf(&err, " %s", all_strategy[i].name);
- fprintf(stderr, "Could not find merge strategy '%s'.\n", name);
- fprintf(stderr, "Available strategies are:%s.\n", err.buf);
- exit(1);
+ if (!longest) {
+ struct cmdnames not_strategies;
+
+ memset(&main_cmds, 0, sizeof(struct cmdnames));
+ memset(&other_cmds, 0, sizeof(struct cmdnames));
+ memset(&not_strategies, 0, sizeof(struct cmdnames));
+ longest = 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(&not_strategies, ent->name, ent->len);
+ exclude_cmds(&main_cmds, &not_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 = xmalloc(sizeof(struct strategy));
+ memset(ret, 0, sizeof(struct strategy));
+ ret->name = xstrdup(name);
+ return ret;
}
static void append_strategy(struct strategy *s)