add -i, send-email, svn, p4, etc: use "git var GIT_EDITOR"
Use the new "git var GIT_EDITOR" feature to decide what editor to use, instead of duplicating its logic elsewhere. This should make the behavior of commands in edge cases (e.g., editor names with spaces) a little more consistent. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Oct 30, 2009 at 20:42 UTC
b4479f074760a788dd4e353b8c86a7d735afc53e
8 files changed
+16
-29
Documentation/config.txt
+1
-3
@@ -387,9 +387,7 @@ core.editor::
387
Commands such as `commit` and `tag` that lets you edit
388
messages by launching an editor uses the value of this
389
variable when it is set, and the environment variable
390
- `GIT_EDITOR` is not set. The order of preference is
391
- `GIT_EDITOR` environment, `core.editor`, `VISUAL` and
392
- `EDITOR` environment variables and then finally `vi`.
390
+ `GIT_EDITOR` is not set. See linkgit:git-var[1].
391
392
core.pager::
393
The command that git will use to paginate output. Can
Documentation/git-commit.txt
+1
-1
@@ -323,7 +323,7 @@ ENVIRONMENT AND CONFIGURATION VARIABLES
323
The editor used to edit the commit log message will be chosen from the
324
GIT_EDITOR environment variable, the core.editor configuration variable, the
325
VISUAL environment variable, or the EDITOR environment variable (in that
326
-order).
326
+order). See linkgit:git-var[1] for details.
327
328
HOOKS
329
-----
Documentation/git-send-email.txt
+2
-2
@@ -60,8 +60,8 @@ The --bcc option must be repeated for each user you want on the bcc list.
60
The --cc option must be repeated for each user you want on the cc list.
61
62
--compose::
63
- Use $GIT_EDITOR, core.editor, $VISUAL, or $EDITOR to edit an
64
- introductory message for the patch series.
63
+ Invoke a text editor (see GIT_EDITOR in linkgit:git-var[1])
64
+ to edit an introductory message for the patch series.
65
+
66
When '--compose' is used, git send-email will use the From, Subject, and
67
In-Reply-To headers specified in the message. If the body of the message
contrib/fast-import/git-p4
+1
-4
@@ -729,13 +729,10 @@ class P4Submit(Command):
729
tmpFile.write(submitTemplate + separatorLine + diff + newdiff)
730
tmpFile.close()
731
mtime = os.stat(fileName).st_mtime
732
- defaultEditor = "vi"
733
- if platform.system() == "Windows":
734
- defaultEditor = "notepad"
732
if os.environ.has_key("P4EDITOR"):
733
editor = os.environ.get("P4EDITOR")
734
else:
738
- editor = os.environ.get("EDITOR", defaultEditor);
735
+ editor = read_pipe("git var GIT_EDITOR")
736
system(editor + " " + fileName)
737
738
response = "y"
git-add--interactive.perl
+1
-2
@@ -987,8 +987,7 @@ sub edit_hunk_manually {
987
EOF
988
close $fh;
989
990
- my $editor = $ENV{GIT_EDITOR} || $repo->config("core.editor")
991
- || $ENV{VISUAL} || $ENV{EDITOR} || "vi";
990
+ chomp(my $editor = run_cmd_pipe(qw(git var GIT_EDITOR)));
991
system('sh', '-c', $editor.' "$@"', $editor, $hunkfile);
992
993
if ($? != 0) {
git-send-email.perl
+2
-1
@@ -162,7 +162,8 @@ my $compose_filename;
162
163
# Handle interactive edition of files.
164
my $multiedit;
165
-my $editor = $ENV{GIT_EDITOR} || Git::config(@repo, "core.editor") || $ENV{VISUAL} || $ENV{EDITOR} || "vi";
165
+my $editor = Git::command_oneline('var', 'GIT_EDITOR');
166
+
167
sub do_edit {
168
if (defined($multiedit) && !$multiedit) {
169
map {
git-sh-setup.sh
+6
-13
@@ -99,19 +99,12 @@ set_reflog_action() {
99
}
100
101
git_editor() {
102
- : "${GIT_EDITOR:=$(git config core.editor)}"
103
- : "${GIT_EDITOR:=${VISUAL:-${EDITOR}}}"
104
- case "$GIT_EDITOR,$TERM" in
105
- ,dumb)
106
- echo >&2 "No editor specified in GIT_EDITOR, core.editor, VISUAL,"
107
- echo >&2 "or EDITOR. Tried to fall back to vi but terminal is dumb."
108
- echo >&2 "Please set one of these variables to an appropriate"
109
- echo >&2 "editor or run $0 with options that will not cause an"
110
- echo >&2 "editor to be invoked (e.g., -m or -F for git-commit)."
111
- exit 1
112
- ;;
113
- esac
114
- eval "${GIT_EDITOR:=vi}" '"$@"'
102
+ if test -z "${GIT_EDITOR:+set}"
103
+ then
104
+ GIT_EDITOR="$(git var GIT_EDITOR)" || return $?
105
+ fi
106
+
107
+ eval "$GIT_EDITOR" '"$@"'
108
}
109
110
is_bare_repository () {
git-svn.perl
+2
-3
@@ -1321,9 +1321,8 @@ sub get_commit_entry {
1321
close $log_fh or croak $!;
1322
1323
if ($_edit || ($type eq 'tree')) {
1324
- my $editor = $ENV{VISUAL} || $ENV{EDITOR} || 'vi';
1325
- # TODO: strip out spaces, comments, like git-commit.sh
1326
- system($editor, $commit_editmsg);
1324
+ chomp(my $editor = command_oneline(qw(var GIT_EDITOR)));
1325
+ system('sh', '-c', $editor.' "$@"', $editor, $commit_editmsg);
1326
}
1327
rename $commit_editmsg, $commit_msg or croak $!;
1328
{