builtin-merge: allow using a custom strategy
Allow using a custom strategy, as long as it's named git-merge-foo. The error handling is now done using is_git_command(). The list of available strategies is now shown by list_commands(). If an invalid strategy is supplied, like -s foobar, then git-merge would list all git-merge-* commands. This is not perfect, since for example git-merge-index is not a valid strategy. These are removed from the output by scanning the list of main commands; if the git-merge-foo command is listed in the all_strategy list, then it's shown, otherwise excluded. This does not exclude commands somewhere else in the PATH, where custom strategies are expected. Signed-off-by: Miklos Vajna <vmiklos@frugalware.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
940208a771
commit
87091b495e
@ -22,6 +22,7 @@
|
|||||||
#include "log-tree.h"
|
#include "log-tree.h"
|
||||||
#include "color.h"
|
#include "color.h"
|
||||||
#include "rerere.h"
|
#include "rerere.h"
|
||||||
|
#include "help.h"
|
||||||
|
|
||||||
#define DEFAULT_TWOHEAD (1<<0)
|
#define DEFAULT_TWOHEAD (1<<0)
|
||||||
#define DEFAULT_OCTOPUS (1<<1)
|
#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)
|
static struct strategy *get_strategy(const char *name)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct strbuf err;
|
struct strategy *ret;
|
||||||
|
static struct cmdnames main_cmds, other_cmds;
|
||||||
|
static int longest;
|
||||||
|
|
||||||
if (!name)
|
if (!name)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -86,14 +89,39 @@ static struct strategy *get_strategy(const char *name)
|
|||||||
if (!strcmp(name, all_strategy[i].name))
|
if (!strcmp(name, all_strategy[i].name))
|
||||||
return &all_strategy[i];
|
return &all_strategy[i];
|
||||||
|
|
||||||
strbuf_init(&err, 0);
|
if (!longest) {
|
||||||
for (i = 0; i < ARRAY_SIZE(all_strategy); i++)
|
struct cmdnames not_strategies;
|
||||||
strbuf_addf(&err, " %s", all_strategy[i].name);
|
|
||||||
fprintf(stderr, "Could not find merge strategy '%s'.\n", name);
|
memset(&main_cmds, 0, sizeof(struct cmdnames));
|
||||||
fprintf(stderr, "Available strategies are:%s.\n", err.buf);
|
memset(&other_cmds, 0, sizeof(struct cmdnames));
|
||||||
|
memset(¬_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(¬_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\n", name);
|
||||||
|
list_commands("strategies", longest, &main_cmds, &other_cmds);
|
||||||
exit(1);
|
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)
|
static void append_strategy(struct strategy *s)
|
||||||
{
|
{
|
||||||
ALLOC_GROW(use_strategies, use_strategies_nr + 1, use_strategies_alloc);
|
ALLOC_GROW(use_strategies, use_strategies_nr + 1, use_strategies_alloc);
|
||||||
|
Loading…
Reference in New Issue
Block a user