diff options
author | Junio C Hamano <gitster@pobox.com> | 2011-11-10 09:10:51 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-11-10 09:10:51 -0800 |
commit | c444c16589f95ac22d8e3ffe603cd7f0613512ce (patch) | |
tree | 31d2e0c2a77344201af6f3ee5427f47218dec9bb /editor.c | |
parent | 77f143bf3e218857ec8e5244d7e862e8e0c1a041 (diff) | |
parent | 81b50f3ce40bfdd66e5d967bf82be001039a9a98 (diff) | |
download | git-ly/mktree-using-strbuf.tar.gz |
Merge "Move 'builtin-*' into a 'builtin/' subdirectory"ly/mktree-using-strbuf
Diffstat (limited to 'editor.c')
-rw-r--r-- | editor.c | 53 |
1 files changed, 25 insertions, 28 deletions
@@ -2,46 +2,43 @@ #include "strbuf.h" #include "run-command.h" -int launch_editor(const char *path, struct strbuf *buffer, const char *const *env) +#ifndef DEFAULT_EDITOR +#define DEFAULT_EDITOR "vi" +#endif + +const char *git_editor(void) { - const char *editor, *terminal; + const char *editor = getenv("GIT_EDITOR"); + const char *terminal = getenv("TERM"); + int terminal_is_dumb = !terminal || !strcmp(terminal, "dumb"); - editor = getenv("GIT_EDITOR"); if (!editor && editor_program) editor = editor_program; - if (!editor) + if (!editor && !terminal_is_dumb) editor = getenv("VISUAL"); if (!editor) editor = getenv("EDITOR"); - terminal = getenv("TERM"); - if (!editor && (!terminal || !strcmp(terminal, "dumb"))) - return error("Terminal is dumb but no VISUAL nor EDITOR defined."); + if (!editor && terminal_is_dumb) + return NULL; if (!editor) - editor = "vi"; + editor = DEFAULT_EDITOR; + + return editor; +} + +int launch_editor(const char *path, struct strbuf *buffer, const char *const *env) +{ + const char *editor = git_editor(); + + if (!editor) + return error("Terminal is dumb, but EDITOR unset"); if (strcmp(editor, ":")) { - size_t len = strlen(editor); - int i = 0; - int failed; - const char *args[6]; - struct strbuf arg0 = STRBUF_INIT; - - if (strcspn(editor, "$ \t'") != len) { - /* there are specials */ - strbuf_addf(&arg0, "%s \"$@\"", editor); - args[i++] = "sh"; - args[i++] = "-c"; - args[i++] = arg0.buf; - } - args[i++] = editor; - args[i++] = path; - args[i] = NULL; - - failed = run_command_v_opt_cd_env(args, 0, NULL, env); - strbuf_release(&arg0); - if (failed) + const char *args[] = { editor, path, NULL }; + + if (run_command_v_opt_cd_env(args, RUN_USING_SHELL, NULL, env)) return error("There was a problem with the editor '%s'.", editor); } |