Re: [PATCH 3/8] Teach git var about GIT_EDITOR
- From
Johannes Sixt <j6t@kdbg.org>
- Date
- Oct 30, 2009, 20:51 UTC
- Message-ID
- <4AEB51C6.7060204@kdbg.org>
- In-Reply-To
- <20091030102658.GD1610@progeny.tock>
Jonathan Nieder schrieb:
Show 8 quoted lines
> From: Johannes Sixt <j.sixt@viscovery.net> > > Expose the command used by launch_editor() for scripts to use. > This should allow one to avoid searching for a proper editor > separately in each command. > > Signed-off-by: Johannes Sixt <j6t@kdbg.org> > Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Thanks for cleaning up behind me. I don't mind if you take authorship, but if you do keep my name, please make it:
From: Johannes Sixt <j6t@kdbg.org>
Show 19 quoted lines
> -int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)
> +const char *git_editor(void)
> {
> const char *editor, *terminal;
>
> ...
> terminal = getenv("TERM");
> - if (!editor && (!terminal || !strcmp(terminal, "dumb")))
> + if (!editor && (!terminal || !strcmp(terminal, "dumb"))) {
> /* Terminal is dumb but no VISUAL nor EDITOR defined. */
> - return error(
> + error(
> "No editor specified in GIT_EDITOR, core.editor, VISUAL,\n"
> "or EDITOR. Tried to fall back to vi but terminal is dumb.\n"
> "Please set one of these variables to an appropriate\n"
> "editor or run again with options that will not cause an\n"
> "editor to be invoked (e.g., -m or -F for git commit).");
> + return NULL;
> + }I somehow dislike that this huge error message is in git_editor(). The return value, NULL, should be indication enough for the callers to handle the situation suitable. In particular, launch_editor() wants to write this big warning, but 'git var -l' can avoid the error message and write only a short notice:
GIT_EDITOR=terminal is dumb, but VISUAL and EDITOR unset
Show 7 quoted lines
> +static const char *editor(int flag)
> +{
> + const char *pgm = git_editor();
> +
> + if (!pgm && (flag & IDENT_ERROR_ON_NO_NAME))
> + die("cannot find a suitable editor");
> + return pgm;This should be
return pgm ? pgm : "terminal is dumb, but VISUAL and EDITOR unset";
otherwise, 'git var -l' later trips over printf("%s", NULL).-- Hannes