22
#include "log-tree.h"
23
#include "color.h"
24
#include "rerere.h"
25
+#include "help.h"
26
27
#define DEFAULT_TWOHEAD (1<<0)
28
#define DEFAULT_OCTOPUS (1<<1)
78
static struct strategy *get_strategy(const char *name)
79
{
80
int i;
80
- struct strbuf err;
81
+ struct strategy *ret;
82
+ static struct cmdnames main_cmds, other_cmds;
83
+ static int longest;
84
85
if (!name)
86
return NULL;
89
if (!strcmp(name, all_strategy[i].name))
90
return &all_strategy[i];
91
89
- strbuf_init(&err, 0);
90
- for (i = 0; i < ARRAY_SIZE(all_strategy); i++)
91
- strbuf_addf(&err, " %s", all_strategy[i].name);
92
- fprintf(stderr, "Could not find merge strategy '%s'.\n", name);
93
- fprintf(stderr, "Available strategies are:%s.\n", err.buf);
94
- exit(1);
92
+ if (!longest) {
93
+ struct cmdnames not_strategies;
94
+
95
+ memset(&main_cmds, 0, sizeof(struct cmdnames));
96
+ memset(&other_cmds, 0, sizeof(struct cmdnames));
97
+ memset(¬_strategies, 0, sizeof(struct cmdnames));
98
+ longest = load_command_list("git-merge-", &main_cmds,
99
+ &other_cmds);
100
+ for (i = 0; i < main_cmds.cnt; i++) {
101
+ int j, found = 0;
102
+ struct cmdname *ent = main_cmds.names[i];
103
+ for (j = 0; j < ARRAY_SIZE(all_strategy); j++)
104
+ if (!strncmp(ent->name, all_strategy[j].name, ent->len)
105
+ && !all_strategy[j].name[ent->len])
106
+ found = 1;
107
+ if (!found)
108
+ add_cmdname(¬_strategies, ent->name, ent->len);
109
+ exclude_cmds(&main_cmds, ¬_strategies);
110
+ }
111
+ }
112
+ if (!is_in_cmdlist(&main_cmds, name) && !is_in_cmdlist(&other_cmds, name)) {
113
+
114
+ fprintf(stderr, "Could not find merge strategy '%s'.\n\n", name);
115
+ list_commands("strategies", longest, &main_cmds, &other_cmds);
116
+ exit(1);
117
+ }
118
+
119
+ ret = xmalloc(sizeof(struct strategy));
120
+ memset(ret, 0, sizeof(struct strategy));
121
+ ret->name = xstrdup(name);
122
+ return ret;
123
}
124
125
static void append_strategy(struct strategy *s)