If an invalid strategy is supplied, like -s foobar, then git-merge listed all git-merge-* commands. This is not perfect, since for example git-merge-index is not a valid strategy. These are now 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@xxxxxxxxxxxxxx> --- On Sat, Jul 26, 2008 at 07:01:16PM +0200, Johannes Schindelin <Johannes.Schindelin@xxxxxx> wrote: > > Hmm. So let's say ent->name is "ours.exe", ent->len is set to 4. > > > > Then !strncmp(ent->name, all_strategy[j].name, ent->len) will be > > true, > > and the command will not be added to the exclude list. > > What I meant is: if you change the strcmp to strncmp because one of > the > both strings is not supposed to be NUL terminated, you still want to > make > sure that one is not a strict prefix of the other. Aah, I forgot about all_strategy[j].name is NUL terminated. Updated patch below. builtin-merge.c | 15 ++++++++++++++- 1 files changed, 14 insertions(+), 1 deletions(-) diff --git a/builtin-merge.c b/builtin-merge.c index cdbc692..29826b1 100644 --- a/builtin-merge.c +++ b/builtin-merge.c @@ -88,8 +88,21 @@ static struct strategy *get_strategy(const char *name) return &all_strategy[i]; if (!is_git_command(name, "git-merge-")) { + struct cmdnames not_strategies; + + memset(¬_strategies, 0, sizeof(struct cmdnames)); + 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); + } fprintf(stderr, "Could not find merge strategy '%s'.\n\n", name); - list_commands("git-merge-", "strategies"); + list_commands("git-merge-", "strategies", ¬_strategies); exit(1); } -- 1.6.0.rc0.14.g95f8.dirty -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html