From: Jonathan Nieder <jrnieder@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Ben Walton <bwalton@artsci.utoronto.ca>,
Johannes Sixt <j.sixt@viscovery.net>,
David Roundy <roundyd@physics.oregonstate.edu>,
GIT List <git@vger.kernel.org>
Subject: [PATCH 3/8] Teach git var about GIT_EDITOR
Date: Fri, 30 Oct 2009 05:26:58 -0500 [thread overview]
Message-ID: <20091030102658.GD1610@progeny.tock> (raw)
In-Reply-To: <20091030101634.GA1610@progeny.tock>
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>
---
Documentation/git-var.txt | 8 ++++++++
cache.h | 1 +
editor.c | 18 +++++++++++++++---
var.c | 10 ++++++++++
4 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-var.txt b/Documentation/git-var.txt
index e2f4c09..89e4b4f 100644
--- a/Documentation/git-var.txt
+++ b/Documentation/git-var.txt
@@ -36,6 +36,14 @@ GIT_AUTHOR_IDENT::
GIT_COMMITTER_IDENT::
The person who put a piece of code into git.
+GIT_EDITOR::
+ Text editor for use by git commands. The value is meant to be
+ interpreted by the shell when it is used. Examples: `~/bin/vi`,
+ `$SOME_ENVIRONMENT_VARIABLE`, `"C:\Program Files\Vim\gvim.exe"
+ --nofork`. The order of preference is the `$GIT_EDITOR`
+ environment variable, then `core.editor` configuration, then
+ `$VISUAL`, then `$EDITOR`, and then finally 'vi'.
+
Diagnostics
-----------
You don't exist. Go away!::
diff --git a/cache.h b/cache.h
index 96840c7..311cfe1 100644
--- a/cache.h
+++ b/cache.h
@@ -750,6 +750,7 @@ extern const char *git_author_info(int);
extern const char *git_committer_info(int);
extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int);
extern const char *fmt_name(const char *name, const char *email);
+extern const char *git_editor(void);
struct checkout {
const char *base_dir;
diff --git a/editor.c b/editor.c
index facd7f2..9dcf95c 100644
--- a/editor.c
+++ b/editor.c
@@ -2,7 +2,7 @@
#include "strbuf.h"
#include "run-command.h"
-int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)
+const char *git_editor(void)
{
const char *editor, *terminal;
@@ -15,18 +15,30 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
editor = getenv("EDITOR");
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;
+ }
if (!editor)
editor = "vi";
+ return editor;
+}
+
+int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)
+{
+ const char *editor = git_editor();
+
+ if (!editor)
+ return -1;
+
if (strcmp(editor, ":")) {
size_t len = strlen(editor);
int i = 0;
diff --git a/var.c b/var.c
index 125c0d1..342dc2c 100644
--- a/var.c
+++ b/var.c
@@ -8,6 +8,15 @@
static const char var_usage[] = "git var [-l | <variable>]";
+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;
+}
+
struct git_var {
const char *name;
const char *(*read)(int);
@@ -15,6 +24,7 @@ struct git_var {
static struct git_var git_vars[] = {
{ "GIT_COMMITTER_IDENT", git_committer_info },
{ "GIT_AUTHOR_IDENT", git_author_info },
+ { "GIT_EDITOR", editor },
{ "", NULL },
};
--
1.6.5.2
next prev parent reply other threads:[~2009-10-30 10:16 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-28 15:21 packaging vs default pager Ben Walton
2009-10-28 17:55 ` Junio C Hamano
2009-10-29 7:32 ` [PATCH 0/2] " Jonathan Nieder
2009-10-29 7:45 ` [PATCH 1/2] Provide a build time default-pager setting Jonathan Nieder
2009-10-29 7:50 ` [PATCH/RFC 2/2] Provide a build time default-editor setting Jonathan Nieder
2009-10-29 10:36 ` David Roundy
2009-10-29 11:50 ` Johannes Sixt
2009-10-29 20:40 ` Junio C Hamano
2009-10-29 20:57 ` Johannes Sixt
2009-10-29 22:12 ` Junio C Hamano
2009-10-30 2:21 ` David Roundy
2009-10-29 20:43 ` Junio C Hamano
2009-10-30 10:16 ` [PATCH v2 0/8] Default pager and editor Jonathan Nieder
2009-10-30 10:20 ` [PATCH 1/8] launch_editor: Longer error message when TERM=dumb Jonathan Nieder
2009-10-30 10:25 ` [PATCH 2/8] Handle more shell metacharacters in editor names Jonathan Nieder
2009-10-30 10:26 ` Jonathan Nieder [this message]
2009-10-30 20:51 ` [PATCH 3/8] Teach git var about GIT_EDITOR Johannes Sixt
2009-10-30 22:47 ` Jonathan Nieder
2009-10-30 22:43 ` Junio C Hamano
2009-10-31 0:01 ` Jonathan Nieder
2009-10-30 10:29 ` [PATCH 4/8] Teach git var about GIT_PAGER Jonathan Nieder
2009-10-30 10:32 ` [PATCH 5/8] add -i, send-email, svn, p4, etc: use "git var GIT_EDITOR" Jonathan Nieder
2009-10-30 10:33 ` [PATCH 6/8] am -i, git-svn: use "git var GIT_PAGER" Jonathan Nieder
2009-10-30 10:35 ` [PATCH 7/8] Provide a build time default-editor setting Jonathan Nieder
2009-10-30 13:17 ` Jonathan Nieder
2009-10-30 10:39 ` [PATCH 8/8] Provide a build time default-pager setting Jonathan Nieder
2009-10-30 22:59 ` Junio C Hamano
2009-10-30 10:49 ` [PATCH/RFC 9/8] Teach git var to run the editor Jonathan Nieder
2009-10-31 1:20 ` [PATCH v3 0/8] Default pager and editor Jonathan Nieder
2009-10-31 1:24 ` [PATCH 1/8] Handle more shell metacharacters in editor names Jonathan Nieder
2009-10-31 1:30 ` [PATCH 2/8] Do not use VISUAL editor on dumb terminals Jonathan Nieder
2009-10-31 7:46 ` [PATCH v2 " Jonathan Nieder
2009-10-31 1:39 ` [PATCH v2 3/8] Teach git var about GIT_EDITOR Jonathan Nieder
2009-10-31 2:01 ` Junio C Hamano
2009-10-31 2:23 ` Jonathan Nieder
2009-10-31 2:34 ` Junio C Hamano
2009-10-31 4:00 ` Jonathan Nieder
2009-10-31 4:04 ` [PATCH v3] " Jonathan Nieder
2009-10-31 4:53 ` Jonathan Nieder
2009-10-31 7:56 ` [PATCH v4] " Jonathan Nieder
2009-11-01 4:29 ` Junio C Hamano
2009-10-31 19:40 ` [PATCH v2 3/8] " Johannes Sixt
2009-10-31 1:41 ` [PATCH 4/8] Teach git var about GIT_PAGER Jonathan Nieder
2009-10-31 1:42 ` [PATCH 5/8] add -i, send-email, svn, p4, etc: use "git var GIT_EDITOR" Jonathan Nieder
2009-10-31 1:43 ` [PATCH 6/8] am -i, git-svn: use "git var GIT_PAGER" Jonathan Nieder
2009-10-31 1:44 ` [PATCH 7/8] Provide a build time default-editor setting Jonathan Nieder
2009-10-31 2:09 ` Junio C Hamano
2009-10-31 3:26 ` Jonathan Nieder
2009-10-31 19:51 ` Junio C Hamano
2009-10-31 21:21 ` Jonathan Nieder
2009-11-01 4:29 ` Junio C Hamano
2009-10-31 1:45 ` [PATCH 8/8] Provide a build time default-pager setting Jonathan Nieder
2009-11-11 23:51 ` [PATCH v4 0/9] Default pager and editor Jonathan Nieder
2009-11-11 23:52 ` [PATCH 1/9] Handle more shell metacharacters in editor names Jonathan Nieder
2009-11-11 23:56 ` [PATCH 2/9] Do not use VISUAL editor on dumb terminals Jonathan Nieder
2009-11-11 23:57 ` [PATCH 3/9] Suppress warnings from "git var -l" Jonathan Nieder
2009-11-12 0:01 ` [PATCH 4/9] Teach git var about GIT_EDITOR Jonathan Nieder
2009-11-12 0:02 ` [PATCH 5/9] Teach git var about GIT_PAGER Jonathan Nieder
2009-11-12 0:02 ` [PATCH 6/9] add -i, send-email, svn, p4, etc: use "git var GIT_EDITOR" Jonathan Nieder
2009-11-12 0:03 ` [PATCH 7/9] am -i, git-svn: use "git var GIT_PAGER" Jonathan Nieder
2009-11-12 0:03 ` [PATCH 8/9] Provide a build time default-editor setting Jonathan Nieder
2009-11-12 0:04 ` [PATCH 9/9] Provide a build time default-pager setting Jonathan Nieder
2009-11-15 9:04 ` [PATCH v4 0/9] Default pager and editor Junio C Hamano
2009-10-29 16:42 ` [PATCH 0/2] Default Pager and Editor at build-time Ben Walton
2009-10-29 16:42 ` [PATCH 1/2] Provide a build time default-pager setting Ben Walton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20091030102658.GD1610@progeny.tock \
--to=jrnieder@gmail.com \
--cc=bwalton@artsci.utoronto.ca \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j.sixt@viscovery.net \
--cc=roundyd@physics.oregonstate.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).