{"thread":{"id":"21405","subject":"packaging vs default pager","startedAt":"2009-10-28T15:21:03Z","lastAt":"2009-11-15T09:04:51Z","messageCount":65,"participants":["Ben Walton","Junio C Hamano","Jonathan Nieder","David Roundy","Johannes Sixt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"126150","messageId":"1256742357-sup-3798@ntdws12.chass.utoronto.ca","threadId":"21405","inReplyTo":null,"subject":"packaging vs default pager","fromName":"Ben Walton","fromEmail":"bwalton@artsci.utoronto.ca","sentAt":"2009-10-28T15:21:03Z","receivedAt":"2009-10-28T15:21:03Z","isPatch":false,"sender":{"key":"bdwalton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/396061?v=4"},"body":"\nHi All,\n\nI'd like to see what people think about providing a configure/Makefile\nknob for overriding the default pager at build time.  Currently,\nthings use 'less' as the fallback and rely on the path to find\nit.\n\nOn (old) solaris systems, /usr/bin/less (typically the first less\nfound) doesn't understand the default arguments (FXRS), which forces\nusers to alter their environment (PATH, GIT_PAGER, LESS, etc) or have\na local or global gitconfig before paging works as expected.\n\nWould it be completely out of line to provide a knob so that the\nfallback $pager could be set to something more specific/appropriate\nduring the build?  [I'll do the work but not if it's an undesirable\naddition.]\n\nAlternately, are packagers recommended to simply ship a global\ngitconfig that sets core.pager?\n\nThanks\n-Ben\n-- \nBen Walton\nSystems Programmer - CHASS\nUniversity of Toronto\nC:416.407.5610 | W:416.978.4302\n\nGPG Key Id: 8E89F6D2; Key Server: pgp.mit.edu\nContact me to arrange for a CAcert assurance meeting.\n"},{"id":"126162","messageId":"7vskd3o11t.fsf@alter.siamese.dyndns.org","threadId":"21405","inReplyTo":"1256742357-sup-3798@ntdws12.chass.utoronto.ca","subject":"Re: packaging vs default pager","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-28T17:55:58Z","receivedAt":"2009-10-28T17:55:58Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ben Walton <bwalton@artsci.utoronto.ca> writes:\n\n> On (old) solaris systems, /usr/bin/less (typically the first less\n> found) doesn't understand the default arguments (FXRS), which forces\n> users to alter their environment (PATH, GIT_PAGER, LESS, etc) or have\n> a local or global gitconfig before paging works as expected.\n>\n> Would it be completely out of line to provide a knob so that the\n> fallback $pager could be set to something more specific/appropriate\n> during the build?\n\nI think that is a sensible thing to do.  Something like this?\n\n Makefile |    6 ++++++\n pager.c  |    6 +++++-\n 2 files changed, 11 insertions(+), 1 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 268aede..342d49a 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -200,6 +200,9 @@ all::\n # memory allocators with the nedmalloc allocator written by Niall Douglas.\n #\n # Define NO_REGEX if you have no or inferior regex support in your C library.\n+#\n+# Define DEFAULT_PAGER to the path of a sensible pager (defaults to \"less\") if\n+# you want to use something different.\n \n GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE\n \t@$(SHELL_PATH) ./GIT-VERSION-GEN\n@@ -1294,6 +1297,9 @@ ifdef NO_REGEX\n \tCOMPAT_CFLAGS += -Icompat/regex\n \tCOMPAT_OBJS += compat/regex/regex.o\n endif\n+ifdef DEFAULT_PAGER\n+\tBASIC_CFLAGS += -DDEFAULT_PAGER='\"$(DEFAULT_PAGER)\"'\n+endif\n \n ifdef USE_NED_ALLOCATOR\n        COMPAT_CFLAGS += -DUSE_NED_ALLOCATOR -DOVERRIDE_STRDUP -DNDEBUG -DREPLACE_SYSTEM_ALLOCATOR -Icompat/nedmalloc\ndiff --git a/pager.c b/pager.c\nindex 86facec..f4c992d 100644\n--- a/pager.c\n+++ b/pager.c\n@@ -2,6 +2,10 @@\n #include \"run-command.h\"\n #include \"sigchain.h\"\n \n+#ifndef DEFAULT_PAGER\n+#define DEFAULT_PAGER \"less\"\n+#endif\n+\n /*\n  * This is split up from the rest of git so that we can do\n  * something different on Windows.\n@@ -58,7 +62,7 @@ void setup_pager(void)\n \tif (!pager)\n \t\tpager = getenv(\"PAGER\");\n \tif (!pager)\n-\t\tpager = \"less\";\n+\t\tpager = DEFAULT_PAGER;\n \telse if (!*pager || !strcmp(pager, \"cat\"))\n \t\treturn;\n \n"},{"id":"126245","messageId":"20091029073224.GA15403@progeny.tock","threadId":"21405","inReplyTo":"7vskd3o11t.fsf@alter.siamese.dyndns.org","subject":"[PATCH 0/2] Re: packaging vs default pager","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-29T07:32:24Z","receivedAt":"2009-10-29T07:32:24Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Junio C Hamano wrote:\n> Ben Walton <bwalton@artsci.utoronto.ca> writes:\n\n>> Would it be completely out of line to provide a knob so that the\n>> fallback $pager could be set to something more specific/appropriate\n>> during the build?\n> \n> I think that is a sensible thing to do.  Something like this?\n> \n>  Makefile |    6 ++++++\n>  pager.c  |    6 +++++-\n>  2 files changed, 11 insertions(+), 1 deletions(-)\n\nThat looks good to me, but it’s missing a corresponding change to\ngit-svn.  I think something like this could be useful for Debian to\navoid patching to comply with the distro policy of falling back to\ngeneric \"pager\" and \"editor\" symlinks.  How about the following two\npatches?\n\nJonathan Nieder (1):\n  Provide a build time default-editor setting\n\nJunio C Hamano (1):\n  Provide a build time default-pager setting\n\n Makefile                  |   18 ++++++++++++++++++\n editor.c                  |    2 +-\n git-add--interactive.perl |    3 ++-\n git-sh-setup.sh           |    6 ++++--\n git-svn.perl              |    8 +++++---\n pager.c                   |    2 +-\n t/Makefile                |    2 ++\n t/t7005-editor.sh         |   29 ++++++++++++++++++++++-------\n 8 files changed, 55 insertions(+), 15 deletions(-)\n"},{"id":"126248","messageId":"20091029074532.GB15403@progeny.tock","threadId":"21405","inReplyTo":"20091029073224.GA15403@progeny.tock","subject":"[PATCH 1/2] Provide a build time default-pager setting","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-29T07:45:33Z","receivedAt":"2009-10-29T07:45:33Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"From: Junio C Hamano <gitster@pobox.com>\n\nOn (old) solaris systems, /usr/bin/less (typically the first less\nfound) doesn't understand the default arguments (FXRS), which\nforces users to alter their environment (PATH, GIT_PAGER, LESS,\netc) or have a local or global gitconfig before paging works as\nexpected.\n\nOn Debian systems, by policy packages must fall back to the\n'pager' command, so that changing the target of the\n/usr/bin/pager symlink changes the default pager for all packages\nat once.\n\nProvide a DEFAULT_PAGER knob so packagers can set the fallback\npager to something appropriate during the build.\n\nThis puts the \"less\" default in the Makefile instead of pager.c,\nsince it is needed for git-svn, too.  This means that the\nDEFAULT_PAGER preprocessor token _has_ to be defined on the\ncommand line for git to build.  I was worried about this for a\nmoment, but GIT_VERSION already works this way without trouble.\n\nProbably the DEFAULT_PAGER setting should be added to something\nlike TRACK_CFLAGS as well.  Actually, some other settings that\ncan change without forcing files to be rebuilt (e.g. SHELL_PATH),\ntoo.  This should be probably be addressed separately.\n\nReported-by: Ben Walton <bwalton@artsci.utoronto.ca>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n Makefile     |    8 ++++++++\n git-svn.perl |    5 +++--\n pager.c      |    2 +-\n 3 files changed, 12 insertions(+), 3 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 268aede..fc1a461 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -200,6 +200,9 @@ all::\n # memory allocators with the nedmalloc allocator written by Niall Douglas.\n #\n # Define NO_REGEX if you have no or inferior regex support in your C library.\n+#\n+# Define DEFAULT_PAGER to the path of a sensible pager (defaults to \"less\") if\n+# you want to use something different.\n \n GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE\n \t@$(SHELL_PATH) ./GIT-VERSION-GEN\n@@ -1294,6 +1297,10 @@ ifdef NO_REGEX\n \tCOMPAT_CFLAGS += -Icompat/regex\n \tCOMPAT_OBJS += compat/regex/regex.o\n endif\n+ifndef DEFAULT_PAGER\n+\tDEFAULT_PAGER = less\n+endif\n+BASIC_CFLAGS += -DDEFAULT_PAGER='\"$(DEFAULT_PAGER)\"'\n \n ifdef USE_NED_ALLOCATOR\n        COMPAT_CFLAGS += -DUSE_NED_ALLOCATOR -DOVERRIDE_STRDUP -DNDEBUG -DREPLACE_SYSTEM_ALLOCATOR -Icompat/nedmalloc\n@@ -1451,6 +1458,7 @@ $(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl\n \t    -e '}' \\\n \t    -e 's|@@INSTLIBDIR@@|'\"$$INSTLIBDIR\"'|g' \\\n \t    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n+\t    -e 's/@@DEFAULT_PAGER@@/$(DEFAULT_PAGER)/g' \\\n \t    $@.perl >$@+ && \\\n \tchmod +x $@+ && \\\n \tmv $@+ $@\ndiff --git a/git-svn.perl b/git-svn.perl\nindex 6a3b501..c270b23 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -3,11 +3,12 @@\n # License: GPL v2 or later\n use warnings;\n use strict;\n-use vars qw/\t$AUTHOR $VERSION\n+use vars qw/\t$AUTHOR $VERSION $DEFAULT_PAGER\n \t\t$sha1 $sha1_short $_revision $_repository\n \t\t$_q $_authors $_authors_prog %users/;\n $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';\n $VERSION = '@@GIT_VERSION@@';\n+$DEFAULT_PAGER = '@@DEFAULT_PAGER@@';\n \n # From which subdir have we been invoked?\n my $cmd_dir_prefix = eval {\n@@ -5174,7 +5175,7 @@ sub git_svn_log_cmd {\n sub config_pager {\n \t$pager ||= $ENV{GIT_PAGER} || $ENV{PAGER};\n \tif (!defined $pager) {\n-\t\t$pager = 'less';\n+\t\t$pager = $DEFAULT_PAGER;\n \t} elsif (length $pager == 0 || $pager eq 'cat') {\n \t\t$pager = undef;\n \t}\ndiff --git a/pager.c b/pager.c\nindex 86facec..416a796 100644\n--- a/pager.c\n+++ b/pager.c\n@@ -58,7 +58,7 @@ void setup_pager(void)\n \tif (!pager)\n \t\tpager = getenv(\"PAGER\");\n \tif (!pager)\n-\t\tpager = \"less\";\n+\t\tpager = DEFAULT_PAGER;\n \telse if (!*pager || !strcmp(pager, \"cat\"))\n \t\treturn;\n \n-- \n1.6.5.2\n"},{"id":"126250","messageId":"20091029075021.GC15403@progeny.tock","threadId":"21405","inReplyTo":"20091029073224.GA15403@progeny.tock","subject":"[PATCH/RFC 2/2] Provide a build time default-editor setting","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-29T07:50:22Z","receivedAt":"2009-10-29T07:50:22Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Provide a DEFAULT_EDITOR knob to allow the fallback editor (to\nuse instead of vi if VISUAL, EDITOR, and GIT_EDITOR are unset) to\nbe set at build time according to a system’s policy.  For\nexample, on Debian systems, the default editor should be the\n'editor' command.\n\nThe contrib/fast-import/git-p4 script still uses vi, since it is\nnot modified by the Makefile currently, and making it require\nbuild-time modification would create too much trouble for people\ndeploying that script.\n\nThis change makes t7005-editor into a mess.  Any ideas for fixing\nthis?\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n Makefile                  |   10 ++++++++++\n editor.c                  |    2 +-\n git-add--interactive.perl |    3 ++-\n git-sh-setup.sh           |    6 ++++--\n git-svn.perl              |    5 +++--\n t/Makefile                |    2 ++\n t/t7005-editor.sh         |   29 ++++++++++++++++++++++-------\n 7 files changed, 44 insertions(+), 13 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex fc1a461..fae8647 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -203,6 +203,9 @@ all::\n #\n # Define DEFAULT_PAGER to the path of a sensible pager (defaults to \"less\") if\n # you want to use something different.\n+#\n+# Define DEFAULT_EDITOR to a sensible editor command (defaults to \"vi\") if you\n+# want to use something different.\n \n GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE\n \t@$(SHELL_PATH) ./GIT-VERSION-GEN\n@@ -1301,6 +1304,11 @@ ifndef DEFAULT_PAGER\n \tDEFAULT_PAGER = less\n endif\n BASIC_CFLAGS += -DDEFAULT_PAGER='\"$(DEFAULT_PAGER)\"'\n+ifndef DEFAULT_EDITOR\n+\tDEFAULT_EDITOR = vi\n+endif\n+export DEFAULT_EDITOR\n+BASIC_CFLAGS += -DDEFAULT_EDITOR='\"$(DEFAULT_EDITOR)\"'\n \n ifdef USE_NED_ALLOCATOR\n        COMPAT_CFLAGS += -DUSE_NED_ALLOCATOR -DOVERRIDE_STRDUP -DNDEBUG -DREPLACE_SYSTEM_ALLOCATOR -Icompat/nedmalloc\n@@ -1435,6 +1443,7 @@ $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh\n \t    -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \\\n \t    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n \t    -e 's/@@NO_CURL@@/$(NO_CURL)/g' \\\n+\t    -e 's|DEFAULT_EDITOR:=vi|DEFAULT_EDITOR:=$(DEFAULT_EDITOR)|' \\\n \t    -e $(BROKEN_PATH_FIX) \\\n \t    $@.sh >$@+ && \\\n \tchmod +x $@+ && \\\n@@ -1459,6 +1468,7 @@ $(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl\n \t    -e 's|@@INSTLIBDIR@@|'\"$$INSTLIBDIR\"'|g' \\\n \t    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n \t    -e 's/@@DEFAULT_PAGER@@/$(DEFAULT_PAGER)/g' \\\n+\t    -e 's/@@DEFAULT_EDITOR@@/$(DEFAULT_EDITOR)/g' \\\n \t    $@.perl >$@+ && \\\n \tchmod +x $@+ && \\\n \tmv $@+ $@\ndiff --git a/editor.c b/editor.c\nindex 4d469d0..93b8cbb 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -19,7 +19,7 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en\n \t\treturn error(\"Terminal is dumb but no VISUAL nor EDITOR defined.\");\n \n \tif (!editor)\n-\t\teditor = \"vi\";\n+\t\teditor = DEFAULT_EDITOR;\n \n \tif (strcmp(editor, \":\")) {\n \t\tsize_t len = strlen(editor);\ndiff --git a/git-add--interactive.perl b/git-add--interactive.perl\nindex 69aeaf0..c3d932c 100755\n--- a/git-add--interactive.perl\n+++ b/git-add--interactive.perl\n@@ -1,6 +1,7 @@\n #!/usr/bin/perl -w\n \n use strict;\n+use constant DEFAULT_EDITOR => '@@DEFAULT_EDITOR@@';\n use Git;\n \n binmode(STDOUT, \":raw\");\n@@ -988,7 +989,7 @@ EOF\n \tclose $fh;\n \n \tmy $editor = $ENV{GIT_EDITOR} || $repo->config(\"core.editor\")\n-\t\t|| $ENV{VISUAL} || $ENV{EDITOR} || \"vi\";\n+\t\t|| $ENV{VISUAL} || $ENV{EDITOR} || DEFAULT_EDITOR;\n \tsystem('sh', '-c', $editor.' \"$@\"', $editor, $hunkfile);\n \n \tif ($? != 0) {\ndiff --git a/git-sh-setup.sh b/git-sh-setup.sh\nindex c41c2f7..d053d56 100755\n--- a/git-sh-setup.sh\n+++ b/git-sh-setup.sh\n@@ -99,19 +99,21 @@ set_reflog_action() {\n }\n \n git_editor() {\n+\t: \"${DEFAULT_EDITOR:=vi}\"\n \t: \"${GIT_EDITOR:=$(git config core.editor)}\"\n \t: \"${GIT_EDITOR:=${VISUAL:-${EDITOR}}}\"\n \tcase \"$GIT_EDITOR,$TERM\" in\n \t,dumb)\n \t\techo >&2 \"No editor specified in GIT_EDITOR, core.editor, VISUAL,\"\n-\t\techo >&2 \"or EDITOR. Tried to fall back to vi but terminal is dumb.\"\n+\t\techo >&2 \"or EDITOR. Tried to fall back to $DEFAULT_EDITOR\" \\\n+\t\t\t\"but terminal is dumb.\"\n \t\techo >&2 \"Please set one of these variables to an appropriate\"\n \t\techo >&2 \"editor or run $0 with options that will not cause an\"\n \t\techo >&2 \"editor to be invoked (e.g., -m or -F for git-commit).\"\n \t\texit 1\n \t\t;;\n \tesac\n-\teval \"${GIT_EDITOR:=vi}\" '\"$@\"'\n+\teval \"${GIT_EDITOR:=$DEFAULT_EDITOR}\" '\"$@\"'\n }\n \n is_bare_repository () {\ndiff --git a/git-svn.perl b/git-svn.perl\nindex c270b23..b98d378 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -3,12 +3,13 @@\n # License: GPL v2 or later\n use warnings;\n use strict;\n-use vars qw/\t$AUTHOR $VERSION $DEFAULT_PAGER\n+use vars qw/\t$AUTHOR $VERSION $DEFAULT_PAGER $DEFAULT_EDITOR\n \t\t$sha1 $sha1_short $_revision $_repository\n \t\t$_q $_authors $_authors_prog %users/;\n $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';\n $VERSION = '@@GIT_VERSION@@';\n $DEFAULT_PAGER = '@@DEFAULT_PAGER@@';\n+$DEFAULT_EDITOR = '@@DEFAULT_EDITOR@@';\n \n # From which subdir have we been invoked?\n my $cmd_dir_prefix = eval {\n@@ -1322,7 +1323,7 @@ sub get_commit_entry {\n \tclose $log_fh or croak $!;\n \n \tif ($_edit || ($type eq 'tree')) {\n-\t\tmy $editor = $ENV{VISUAL} || $ENV{EDITOR} || 'vi';\n+\t\tmy $editor = $ENV{VISUAL} || $ENV{EDITOR} || $DEFAULT_EDITOR;\n \t\t# TODO: strip out spaces, comments, like git-commit.sh\n \t\tsystem($editor, $commit_editmsg);\n \t}\ndiff --git a/t/Makefile b/t/Makefile\nindex bd09390..9174bbb 100644\n--- a/t/Makefile\n+++ b/t/Makefile\n@@ -9,6 +9,8 @@\n SHELL_PATH ?= $(SHELL)\n TAR ?= $(TAR)\n RM ?= rm -f\n+DEFAULT_EDITOR ?= vi\n+export DEFAULT_EDITOR\n \n # Shell quote;\n SHELL_PATH_SQ = $(subst ','\\'',$(SHELL_PATH))\ndiff --git a/t/t7005-editor.sh b/t/t7005-editor.sh\nindex b647957..2b76f72 100755\n--- a/t/t7005-editor.sh\n+++ b/t/t7005-editor.sh\n@@ -4,7 +4,18 @@ test_description='GIT_EDITOR, core.editor, and stuff'\n \n . ./test-lib.sh\n \n-for i in GIT_EDITOR core_editor EDITOR VISUAL vi\n+: ${DEFAULT_EDITOR=vi}\n+\n+unset EDITOR VISUAL GIT_EDITOR\n+\n+case \"$DEFAULT_EDITOR\" in\n+*/* | [A-Z]*)\n+\tDEFAULT_EDITOR=\n+\t;;\n+esac\n+\n+for i in GIT_EDITOR core_editor EDITOR VISUAL \\\n+\t${DEFAULT_EDITOR:+\"$DEFAULT_EDITOR\"}\n do\n \tcat >e-$i.sh <<-EOF\n \t#!$SHELL_PATH\n@@ -12,15 +23,17 @@ do\n \tEOF\n \tchmod +x e-$i.sh\n done\n-unset vi\n-mv e-vi.sh vi\n-unset EDITOR VISUAL GIT_EDITOR\n+\n+if test -n \"$DEFAULT_EDITOR\"\n+then\n+\tmv \"e-$DEFAULT_EDITOR.sh\" \"$DEFAULT_EDITOR\"\n+fi\n \n test_expect_success setup '\n \n \tmsg=\"Hand edited\" &&\n \techo \"$msg\" >expect &&\n-\tgit add vi &&\n+\tgit add \"e-VISUAL.sh\" &&\n \ttest_tick &&\n \tgit commit -m \"$msg\" &&\n \tgit show -s --pretty=oneline |\n@@ -44,7 +57,8 @@ test_expect_success 'dumb should error out when falling back on vi' '\n \n TERM=vt100\n export TERM\n-for i in vi EDITOR VISUAL core_editor GIT_EDITOR\n+for i in ${DEFAULT_EDITOR:+\"$DEFAULT_EDITOR\"} \\\n+\tEDITOR VISUAL core_editor GIT_EDITOR\n do\n \techo \"Edited by $i\" >expect\n \tunset EDITOR VISUAL GIT_EDITOR\n@@ -68,7 +82,8 @@ done\n \n unset EDITOR VISUAL GIT_EDITOR\n git config --unset-all core.editor\n-for i in vi EDITOR VISUAL core_editor GIT_EDITOR\n+for i in ${DEFAULT_EDITOR:+\"$DEFAULT_EDITOR\"} \\\n+\tEDITOR VISUAL core_editor GIT_EDITOR\n do\n \techo \"Edited by $i\" >expect\n \tcase \"$i\" in\n-- \n1.6.5.2\n"},{"id":"126258","messageId":"117f2cc80910290336k1e7b5877uc472ad511bb6f5ae@mail.gmail.com","threadId":"21405","inReplyTo":"20091029075021.GC15403@progeny.tock","subject":"Re: [PATCH/RFC 2/2] Provide a build time default-editor setting","fromName":"David Roundy","fromEmail":"roundyd@physics.oregonstate.edu","sentAt":"2009-10-29T10:36:59Z","receivedAt":"2009-10-29T10:36:59Z","isPatch":true,"sender":{"key":"roundyd@physics.oregonstate.edu","avatar":"https://gravatar.com/avatar/20c6928b273bb8a1c23deb12399d0e74782ce911504ad5ee604294fc6a61940a?d=mp&s=160"},"body":"Any chance this will be exported as plumbing? I know it's pretty\nhigh-level, but it'd be handy to have be able to write `git editor\n$FILENAME` and just have it do the right thing.  This would also mean\nthat the perl scripts below could be simplified.\n\nSame goes for pager, of course...\n\nDavid\n\nOn Thu, Oct 29, 2009 at 3:50 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Provide a DEFAULT_EDITOR knob to allow the fallback editor (to\n> use instead of vi if VISUAL, EDITOR, and GIT_EDITOR are unset) to\n> be set at build time according to a system’s policy.  For\n> example, on Debian systems, the default editor should be the\n> 'editor' command.\n>\n> The contrib/fast-import/git-p4 script still uses vi, since it is\n> not modified by the Makefile currently, and making it require\n> build-time modification would create too much trouble for people\n> deploying that script.\n>\n> This change makes t7005-editor into a mess.  Any ideas for fixing\n> this?\n>\n> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\n> ---\n>  Makefile                  |   10 ++++++++++\n>  editor.c                  |    2 +-\n>  git-add--interactive.perl |    3 ++-\n>  git-sh-setup.sh           |    6 ++++--\n>  git-svn.perl              |    5 +++--\n>  t/Makefile                |    2 ++\n>  t/t7005-editor.sh         |   29 ++++++++++++++++++++++-------\n>  7 files changed, 44 insertions(+), 13 deletions(-)\n>\n> diff --git a/Makefile b/Makefile\n> index fc1a461..fae8647 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -203,6 +203,9 @@ all::\n>  #\n>  # Define DEFAULT_PAGER to the path of a sensible pager (defaults to \"less\") if\n>  # you want to use something different.\n> +#\n> +# Define DEFAULT_EDITOR to a sensible editor command (defaults to \"vi\") if you\n> +# want to use something different.\n>\n>  GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE\n>        @$(SHELL_PATH) ./GIT-VERSION-GEN\n> @@ -1301,6 +1304,11 @@ ifndef DEFAULT_PAGER\n>        DEFAULT_PAGER = less\n>  endif\n>  BASIC_CFLAGS += -DDEFAULT_PAGER='\"$(DEFAULT_PAGER)\"'\n> +ifndef DEFAULT_EDITOR\n> +       DEFAULT_EDITOR = vi\n> +endif\n> +export DEFAULT_EDITOR\n> +BASIC_CFLAGS += -DDEFAULT_EDITOR='\"$(DEFAULT_EDITOR)\"'\n>\n>  ifdef USE_NED_ALLOCATOR\n>        COMPAT_CFLAGS += -DUSE_NED_ALLOCATOR -DOVERRIDE_STRDUP -DNDEBUG -DREPLACE_SYSTEM_ALLOCATOR -Icompat/nedmalloc\n> @@ -1435,6 +1443,7 @@ $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh\n>            -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \\\n>            -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n>            -e 's/@@NO_CURL@@/$(NO_CURL)/g' \\\n> +           -e 's|DEFAULT_EDITOR:=vi|DEFAULT_EDITOR:=$(DEFAULT_EDITOR)|' \\\n>            -e $(BROKEN_PATH_FIX) \\\n>            $@.sh >$@+ && \\\n>        chmod +x $@+ && \\\n> @@ -1459,6 +1468,7 @@ $(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl\n>            -e 's|@@INSTLIBDIR@@|'\"$$INSTLIBDIR\"'|g' \\\n>            -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n>            -e 's/@@DEFAULT_PAGER@@/$(DEFAULT_PAGER)/g' \\\n> +           -e 's/@@DEFAULT_EDITOR@@/$(DEFAULT_EDITOR)/g' \\\n>            $@.perl >$@+ && \\\n>        chmod +x $@+ && \\\n>        mv $@+ $@\n> diff --git a/editor.c b/editor.c\n> index 4d469d0..93b8cbb 100644\n> --- a/editor.c\n> +++ b/editor.c\n> @@ -19,7 +19,7 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en\n>                return error(\"Terminal is dumb but no VISUAL nor EDITOR defined.\");\n>\n>        if (!editor)\n> -               editor = \"vi\";\n> +               editor = DEFAULT_EDITOR;\n>\n>        if (strcmp(editor, \":\")) {\n>                size_t len = strlen(editor);\n> diff --git a/git-add--interactive.perl b/git-add--interactive.perl\n> index 69aeaf0..c3d932c 100755\n> --- a/git-add--interactive.perl\n> +++ b/git-add--interactive.perl\n> @@ -1,6 +1,7 @@\n>  #!/usr/bin/perl -w\n>\n>  use strict;\n> +use constant DEFAULT_EDITOR => '@@DEFAULT_EDITOR@@';\n>  use Git;\n>\n>  binmode(STDOUT, \":raw\");\n> @@ -988,7 +989,7 @@ EOF\n>        close $fh;\n>\n>        my $editor = $ENV{GIT_EDITOR} || $repo->config(\"core.editor\")\n> -               || $ENV{VISUAL} || $ENV{EDITOR} || \"vi\";\n> +               || $ENV{VISUAL} || $ENV{EDITOR} || DEFAULT_EDITOR;\n>        system('sh', '-c', $editor.' \"$@\"', $editor, $hunkfile);\n>\n>        if ($? != 0) {\n> diff --git a/git-sh-setup.sh b/git-sh-setup.sh\n> index c41c2f7..d053d56 100755\n> --- a/git-sh-setup.sh\n> +++ b/git-sh-setup.sh\n> @@ -99,19 +99,21 @@ set_reflog_action() {\n>  }\n>\n>  git_editor() {\n> +       : \"${DEFAULT_EDITOR:=vi}\"\n>        : \"${GIT_EDITOR:=$(git config core.editor)}\"\n>        : \"${GIT_EDITOR:=${VISUAL:-${EDITOR}}}\"\n>        case \"$GIT_EDITOR,$TERM\" in\n>        ,dumb)\n>                echo >&2 \"No editor specified in GIT_EDITOR, core.editor, VISUAL,\"\n> -               echo >&2 \"or EDITOR. Tried to fall back to vi but terminal is dumb.\"\n> +               echo >&2 \"or EDITOR. Tried to fall back to $DEFAULT_EDITOR\" \\\n> +                       \"but terminal is dumb.\"\n>                echo >&2 \"Please set one of these variables to an appropriate\"\n>                echo >&2 \"editor or run $0 with options that will not cause an\"\n>                echo >&2 \"editor to be invoked (e.g., -m or -F for git-commit).\"\n>                exit 1\n>                ;;\n>        esac\n> -       eval \"${GIT_EDITOR:=vi}\" '\"$@\"'\n> +       eval \"${GIT_EDITOR:=$DEFAULT_EDITOR}\" '\"$@\"'\n>  }\n>\n>  is_bare_repository () {\n> diff --git a/git-svn.perl b/git-svn.perl\n> index c270b23..b98d378 100755\n> --- a/git-svn.perl\n> +++ b/git-svn.perl\n> @@ -3,12 +3,13 @@\n>  # License: GPL v2 or later\n>  use warnings;\n>  use strict;\n> -use vars qw/   $AUTHOR $VERSION $DEFAULT_PAGER\n> +use vars qw/   $AUTHOR $VERSION $DEFAULT_PAGER $DEFAULT_EDITOR\n>                $sha1 $sha1_short $_revision $_repository\n>                $_q $_authors $_authors_prog %users/;\n>  $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';\n>  $VERSION = '@@GIT_VERSION@@';\n>  $DEFAULT_PAGER = '@@DEFAULT_PAGER@@';\n> +$DEFAULT_EDITOR = '@@DEFAULT_EDITOR@@';\n>\n>  # From which subdir have we been invoked?\n>  my $cmd_dir_prefix = eval {\n> @@ -1322,7 +1323,7 @@ sub get_commit_entry {\n>        close $log_fh or croak $!;\n>\n>        if ($_edit || ($type eq 'tree')) {\n> -               my $editor = $ENV{VISUAL} || $ENV{EDITOR} || 'vi';\n> +               my $editor = $ENV{VISUAL} || $ENV{EDITOR} || $DEFAULT_EDITOR;\n>                # TODO: strip out spaces, comments, like git-commit.sh\n>                system($editor, $commit_editmsg);\n>        }\n> diff --git a/t/Makefile b/t/Makefile\n> index bd09390..9174bbb 100644\n> --- a/t/Makefile\n> +++ b/t/Makefile\n> @@ -9,6 +9,8 @@\n>  SHELL_PATH ?= $(SHELL)\n>  TAR ?= $(TAR)\n>  RM ?= rm -f\n> +DEFAULT_EDITOR ?= vi\n> +export DEFAULT_EDITOR\n>\n>  # Shell quote;\n>  SHELL_PATH_SQ = $(subst ','\\'',$(SHELL_PATH))\n> diff --git a/t/t7005-editor.sh b/t/t7005-editor.sh\n> index b647957..2b76f72 100755\n> --- a/t/t7005-editor.sh\n> +++ b/t/t7005-editor.sh\n> @@ -4,7 +4,18 @@ test_description='GIT_EDITOR, core.editor, and stuff'\n>\n>  . ./test-lib.sh\n>\n> -for i in GIT_EDITOR core_editor EDITOR VISUAL vi\n> +: ${DEFAULT_EDITOR=vi}\n> +\n> +unset EDITOR VISUAL GIT_EDITOR\n> +\n> +case \"$DEFAULT_EDITOR\" in\n> +*/* | [A-Z]*)\n> +       DEFAULT_EDITOR=\n> +       ;;\n> +esac\n> +\n> +for i in GIT_EDITOR core_editor EDITOR VISUAL \\\n> +       ${DEFAULT_EDITOR:+\"$DEFAULT_EDITOR\"}\n>  do\n>        cat >e-$i.sh <<-EOF\n>        #!$SHELL_PATH\n> @@ -12,15 +23,17 @@ do\n>        EOF\n>        chmod +x e-$i.sh\n>  done\n> -unset vi\n> -mv e-vi.sh vi\n> -unset EDITOR VISUAL GIT_EDITOR\n> +\n> +if test -n \"$DEFAULT_EDITOR\"\n> +then\n> +       mv \"e-$DEFAULT_EDITOR.sh\" \"$DEFAULT_EDITOR\"\n> +fi\n>\n>  test_expect_success setup '\n>\n>        msg=\"Hand edited\" &&\n>        echo \"$msg\" >expect &&\n> -       git add vi &&\n> +       git add \"e-VISUAL.sh\" &&\n>        test_tick &&\n>        git commit -m \"$msg\" &&\n>        git show -s --pretty=oneline |\n> @@ -44,7 +57,8 @@ test_expect_success 'dumb should error out when falling back on vi' '\n>\n>  TERM=vt100\n>  export TERM\n> -for i in vi EDITOR VISUAL core_editor GIT_EDITOR\n> +for i in ${DEFAULT_EDITOR:+\"$DEFAULT_EDITOR\"} \\\n> +       EDITOR VISUAL core_editor GIT_EDITOR\n>  do\n>        echo \"Edited by $i\" >expect\n>        unset EDITOR VISUAL GIT_EDITOR\n> @@ -68,7 +82,8 @@ done\n>\n>  unset EDITOR VISUAL GIT_EDITOR\n>  git config --unset-all core.editor\n> -for i in vi EDITOR VISUAL core_editor GIT_EDITOR\n> +for i in ${DEFAULT_EDITOR:+\"$DEFAULT_EDITOR\"} \\\n> +       EDITOR VISUAL core_editor GIT_EDITOR\n>  do\n>        echo \"Edited by $i\" >expect\n>        case \"$i\" in\n> --\n> 1.6.5.2\n>\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n>\n\n\n\n-- \nDavid Roundy\n"},{"id":"126263","messageId":"4AE98175.504@viscovery.net","threadId":"21405","inReplyTo":"117f2cc80910290336k1e7b5877uc472ad511bb6f5ae@mail.gmail.com","subject":"Re: [PATCH/RFC 2/2] Provide a build time default-editor setting","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2009-10-29T11:50:13Z","receivedAt":"2009-10-29T11:50:13Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"David Roundy schrieb:\n> Any chance this will be exported as plumbing? I know it's pretty\n> high-level, but it'd be handy to have be able to write `git editor\n> $FILENAME` and just have it do the right thing.  This would also mean\n> that the perl scripts below could be simplified.\n\nSomething like below? Possible usage in shell scripts:\n\n\teditor=$(git var GIT_EDITOR)\n\t\"$editor\" \"$filename\"\n\n-- Hannes\n\nPS: warning: linewrapped.\n\nSubject: [PATCH] Teach git var about GIT_EDITOR\n\nSigned-off-by: Johannes Sixt <j6t@kdbg.org>\n---\n cache.h  |    1 +\n editor.c |   13 +++++++++++--\n var.c    |    6 ++++++\n 3 files changed, 18 insertions(+), 2 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex a5eeead..3103dda 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -750,6 +750,7 @@ extern const char *git_author_info(int);\n extern const char *git_committer_info(int);\n extern const char *fmt_ident(const char *name, const char *email, const\nchar *date_str, int);\n extern const char *fmt_name(const char *name, const char *email);\n+extern const char *git_editor();\n\n struct checkout {\n \tconst char *base_dir;\ndiff --git a/editor.c b/editor.c\nindex 4d469d0..bd8c828 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -2,7 +2,7 @@\n #include \"strbuf.h\"\n #include \"run-command.h\"\n\n-int launch_editor(const char *path, struct strbuf *buffer, const char\n*const *env)\n+const char *git_editor()\n {\n \tconst char *editor, *terminal;\n\n@@ -16,11 +16,20 @@ int launch_editor(const char *path, struct strbuf\n \tterminal = getenv(\"TERM\");\n \tif (!editor && (!terminal || !strcmp(terminal, \"dumb\")))\n-\t\treturn error(\"Terminal is dumb but no VISUAL nor EDITOR defined.\");\n+\t\treturn \"/dev/null\";\n\n \tif (!editor)\n \t\teditor = \"vi\";\n\n+\treturn editor;\n+}\n+\n+int launch_editor(const char *path, struct strbuf *buffer, const char\n*const *env)\n+{\n+\tconst char *editor = git_editor();\n+\n+\tif (!strcmp(editor, \"/dev/null\"))\n+\t\treturn error(\"Terminal is dumb but no VISUAL nor EDITOR defined.\");\n \tif (strcmp(editor, \":\")) {\n \t\tsize_t len = strlen(editor);\n \t\tint i = 0;\ndiff --git a/var.c b/var.c\nindex 125c0d1..48d8b9a 100644\n--- a/var.c\n+++ b/var.c\n@@ -8,6 +8,11 @@\n\n static const char var_usage[] = \"git var [-l | <variable>]\";\n\n+static const char *editor(int unused)\n+{\n+\treturn git_editor();\n+}\n+\n struct git_var {\n \tconst char *name;\n \tconst char *(*read)(int);\n@@ -15,6 +20,7 @@ struct git_var {\n static struct git_var git_vars[] = {\n \t{ \"GIT_COMMITTER_IDENT\", git_committer_info },\n \t{ \"GIT_AUTHOR_IDENT\",   git_author_info },\n+\t{ \"GIT_EDITOR\", editor },\n \t{ \"\", NULL },\n };\n\n-- \n1.6.5.rc2.47.g49402\n"},{"id":"126292","messageId":"1256834565-19443-1-git-send-email-bwalton@artsci.utoronto.ca","threadId":"21405","inReplyTo":"20091029073224.GA15403@progeny.tock","subject":"[PATCH 0/2] Default Pager and Editor at build-time","fromName":"Ben Walton","fromEmail":"bwalton@artsci.utoronto.ca","sentAt":"2009-10-29T16:42:43Z","receivedAt":"2009-10-29T16:42:43Z","isPatch":true,"sender":{"key":"bdwalton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/396061?v=4"},"body":"The two patches look ok to me (not withstanding the comments already\nmade about the test and possible future changes required).\n\nI did make a few small tweaks to use | instead of / as the sed\nsubstitution separator (since we're presumably working with full\npaths).  The substitution was also extended into the .sh scripts\n(git-am, explicitly).\n\nJonathan Nieder (1):\n  Provide a build time default-editor setting\n\nJunio C Hamano (1):\n  Provide a build time default-pager setting\n\n Makefile                  |   19 +++++++++++++++++++\n editor.c                  |    2 +-\n git-add--interactive.perl |    3 ++-\n git-am.sh                 |    2 +-\n git-sh-setup.sh           |    6 ++++--\n git-svn.perl              |    8 +++++---\n pager.c                   |    2 +-\n t/Makefile                |    2 ++\n t/t7005-editor.sh         |   29 ++++++++++++++++++++++-------\n 9 files changed, 57 insertions(+), 16 deletions(-)\n"},{"id":"126291","messageId":"1256834565-19443-2-git-send-email-bwalton@artsci.utoronto.ca","threadId":"21405","inReplyTo":"1256834565-19443-1-git-send-email-bwalton@artsci.utoronto.ca","subject":"[PATCH 1/2] Provide a build time default-pager setting","fromName":"Ben Walton","fromEmail":"bwalton@artsci.utoronto.ca","sentAt":"2009-10-29T16:42:44Z","receivedAt":"2009-10-29T16:42:44Z","isPatch":true,"sender":{"key":"bdwalton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/396061?v=4"},"body":"From: Junio C Hamano <gitster@pobox.com>\n\nOn (old) solaris systems, /usr/bin/less (typically the first less\nfound) doesn't understand the default arguments (FXRS), which\nforces users to alter their environment (PATH, GIT_PAGER, LESS,\netc) or have a local or global gitconfig before paging works as\nexpected.\n\nOn Debian systems, by policy packages must fall back to the\n'pager' command, so that changing the target of the\n/usr/bin/pager symlink changes the default pager for all packages\nat once.\n\nProvide a DEFAULT_PAGER knob so packagers can set the fallback\npager to something appropriate during the build.\n\nThis puts the \"less\" default in the Makefile instead of pager.c, since\nit is needed for git-svn and git-am, too.  This means that the\nDEFAULT_PAGER preprocessor token _has_ to be defined on the command\nline for git to build.  I was worried about this for a moment, but\nGIT_VERSION already works this way without trouble.\n\nProbably the DEFAULT_PAGER setting should be added to something\nlike TRACK_CFLAGS as well.  Actually, some other settings that\ncan change without forcing files to be rebuilt (e.g. SHELL_PATH),\ntoo.  This should be probably be addressed separately.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Ben Walton <bwalton@artsci.utoronto.ca>\n---\n Makefile     |    9 +++++++++\n git-am.sh    |    2 +-\n git-svn.perl |    5 +++--\n pager.c      |    2 +-\n 4 files changed, 14 insertions(+), 4 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 42b7d60..1d26800 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -200,6 +200,9 @@ all::\n # memory allocators with the nedmalloc allocator written by Niall Douglas.\n #\n # Define NO_REGEX if you have no or inferior regex support in your C library.\n+#\n+# Define DEFAULT_PAGER to the path of a sensible pager (defaults to \"less\") if\n+# you want to use something different.\n \n GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE\n \t@$(SHELL_PATH) ./GIT-VERSION-GEN\n@@ -1294,6 +1297,10 @@ ifdef NO_REGEX\n \tCOMPAT_CFLAGS += -Icompat/regex\n \tCOMPAT_OBJS += compat/regex/regex.o\n endif\n+ifndef DEFAULT_PAGER\n+\tDEFAULT_PAGER = less\n+endif\n+BASIC_CFLAGS += -DDEFAULT_PAGER='\"$(DEFAULT_PAGER)\"'\n \n ifdef USE_NED_ALLOCATOR\n        COMPAT_CFLAGS += -DUSE_NED_ALLOCATOR -DOVERRIDE_STRDUP -DNDEBUG -DREPLACE_SYSTEM_ALLOCATOR -Icompat/nedmalloc\n@@ -1428,6 +1435,7 @@ $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh\n \t    -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \\\n \t    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n \t    -e 's/@@NO_CURL@@/$(NO_CURL)/g' \\\n+\t    -e 's|@@DEFAULT_PAGER@@|$(DEFAULT_PAGER)|g' \\\n \t    -e $(BROKEN_PATH_FIX) \\\n \t    $@.sh >$@+ && \\\n \tchmod +x $@+ && \\\n@@ -1451,6 +1459,7 @@ $(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl\n \t    -e '}' \\\n \t    -e 's|@@INSTLIBDIR@@|'\"$$INSTLIBDIR\"'|g' \\\n \t    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n+\t    -e 's|@@DEFAULT_PAGER@@|$(DEFAULT_PAGER)|g' \\\n \t    $@.perl >$@+ && \\\n \tchmod +x $@+ && \\\n \tmv $@+ $@\ndiff --git a/git-am.sh b/git-am.sh\nindex c132f50..a194a4e 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -649,7 +649,7 @@ do\n \t\t[eE]*) git_editor \"$dotest/final-commit\"\n \t\t       action=again ;;\n \t\t[vV]*) action=again\n-\t\t       LESS=-S ${PAGER:-less} \"$dotest/patch\" ;;\n+\t\t       LESS=-S ${PAGER:-@@DEFAULT_PAGER@@} \"$dotest/patch\" ;;\n \t\t*)     action=again ;;\n \t\tesac\n \t    done\ndiff --git a/git-svn.perl b/git-svn.perl\nindex eb4b75a..a61ec55 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -3,11 +3,12 @@\n # License: GPL v2 or later\n use warnings;\n use strict;\n-use vars qw/\t$AUTHOR $VERSION\n+use vars qw/\t$AUTHOR $VERSION $DEFAULT_PAGER\n \t\t$sha1 $sha1_short $_revision $_repository\n \t\t$_q $_authors $_authors_prog %users/;\n $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';\n $VERSION = '@@GIT_VERSION@@';\n+$DEFAULT_PAGER = '@@DEFAULT_PAGER@@';\n \n # From which subdir have we been invoked?\n my $cmd_dir_prefix = eval {\n@@ -5031,7 +5032,7 @@ sub git_svn_log_cmd {\n sub config_pager {\n \t$pager ||= $ENV{GIT_PAGER} || $ENV{PAGER};\n \tif (!defined $pager) {\n-\t\t$pager = 'less';\n+\t\t$pager = $DEFAULT_PAGER;\n \t} elsif (length $pager == 0 || $pager eq 'cat') {\n \t\t$pager = undef;\n \t}\ndiff --git a/pager.c b/pager.c\nindex 86facec..416a796 100644\n--- a/pager.c\n+++ b/pager.c\n@@ -58,7 +58,7 @@ void setup_pager(void)\n \tif (!pager)\n \t\tpager = getenv(\"PAGER\");\n \tif (!pager)\n-\t\tpager = \"less\";\n+\t\tpager = DEFAULT_PAGER;\n \telse if (!*pager || !strcmp(pager, \"cat\"))\n \t\treturn;\n \n-- \n1.6.5\n"},{"id":"126328","messageId":"7viqdy6ii1.fsf@alter.siamese.dyndns.org","threadId":"21405","inReplyTo":"4AE98175.504@viscovery.net","subject":"Re: [PATCH/RFC 2/2] Provide a build time default-editor setting","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-29T20:40:54Z","receivedAt":"2009-10-29T20:40:54Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <j.sixt@viscovery.net> writes:\n\n> David Roundy schrieb:\n>> Any chance this will be exported as plumbing? I know it's pretty\n>> high-level, but it'd be handy to have be able to write `git editor\n>> $FILENAME` and just have it do the right thing.  This would also mean\n>> that the perl scripts below could be simplified.\n>\n> Something like below? Possible usage in shell scripts:\n>\n> \teditor=$(git var GIT_EDITOR)\n> \t\"$editor\" \"$filename\"\n\nI think we support GIT_EDITOR that is command path plus its initial\ncommand line arguments, so you do not want dq around $editor, right?\n"},{"id":"126329","messageId":"7v8weu6idl.fsf@alter.siamese.dyndns.org","threadId":"21405","inReplyTo":"20091029075021.GC15403@progeny.tock","subject":"Re: [PATCH/RFC 2/2] Provide a build time default-editor setting","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-29T20:43:34Z","receivedAt":"2009-10-29T20:43:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonathan Nieder <jrnieder@gmail.com> writes:\n\n> Provide a DEFAULT_EDITOR knob to allow the fallback editor (to\n> use instead of vi if VISUAL, EDITOR, and GIT_EDITOR are unset) to\n> be set at build time according to a system’s policy.  For\n> example, on Debian systems, the default editor should be the\n> 'editor' command.\n\nI think we allow things like\n\n    GIT_EDITOR='\"/c/my program/vi\" --i-like-color --config=$HOME/.myvicfg'\n\nand the eval construct in git-sh-setup.sh is about supporting that kind of\ninsanity^Wflexibility.\n\nMy \"how about\" patch on DEFAULT_PAGER might be minimally safe with\n\n    make DEFAULT_PAGER=\"/c/my program/less\"\n\nbut if you are going to do this for real, you would need to use proper\nquoting in the Makefile (look for _SQ for hints).\n\nAlso I do not think it allows this at all:\n\n    make DEFAULT_PAGER='\"/c/my program/less\" --i-like-color'\n\nIt probably is Ok to force the \"default\" one to be just the path to the\ncommand (i.e. not part of command line), but I thought this would be worth\npointing out.\n\n> This change makes t7005-editor into a mess.  Any ideas for fixing\n> this?\n\nI think the introduction of DEFAULT_EDITOR makes it unfixable; your\nDEFAULT_EDITOR may be set to '/usr/bin/vi' not 'vi'.\n\nJust detect DEFAULT_EDITOR being not the default 'vi' and abort/skip the\nentire test, perhaps?\n"},{"id":"126332","messageId":"200910292157.37474.j.sixt@viscovery.net","threadId":"21405","inReplyTo":"7viqdy6ii1.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH/RFC 2/2] Provide a build time default-editor setting","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2009-10-29T20:57:36Z","receivedAt":"2009-10-29T20:57:36Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"On Donnerstag, 29. Oktober 2009, Junio C Hamano wrote:\n> Johannes Sixt <j.sixt@viscovery.net> writes:\n> > Something like below? Possible usage in shell scripts:\n> >\n> > \teditor=$(git var GIT_EDITOR)\n> > \t\"$editor\" \"$filename\"\n>\n> I think we support GIT_EDITOR that is command path plus its initial\n> command line arguments, so you do not want dq around $editor, right?\n\nYeah, whatever, I didn't take the time to think it through. But this may be an \nopportunity to give some life back to the zombie that git-var currently is, \nthat is, to make it the plumbing that does value discovery for variables like \nGIT_AUTHOR_INDENT, GIT_COMMITTER_IDENT, GIT_EDITOR, and perhaps also \nGIT_PAGER.\n\n-- Hannes\n"},{"id":"126340","messageId":"7vfx916ea6.fsf@alter.siamese.dyndns.org","threadId":"21405","inReplyTo":"200910292157.37474.j.sixt@viscovery.net","subject":"Re: [PATCH/RFC 2/2] Provide a build time default-editor setting","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-29T22:12:01Z","receivedAt":"2009-10-29T22:12:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <j.sixt@viscovery.net> writes:\n\n> Yeah, whatever, I didn't take the time to think it through. But this may be an \n> opportunity to give some life back to the zombie that git-var currently is, \n> that is, to make it the plumbing that does value discovery for variables like \n> GIT_AUTHOR_INDENT, GIT_COMMITTER_IDENT, GIT_EDITOR, and perhaps also \n> GIT_PAGER.\n\nHmm, wouldn't it make even more sense to \"run\" them for the calling\nPorcelain script?\n\nA shell script Porcelain can already \". git-sh-setup\" and say\n\n\tgit_editor this-file\n\nwhen it needs to spawn the editor of choice.  Your new plumbing support\ncould make the definition of git_editor in git-sh-setup.sh into something\nlike:\n\n    git_editor() {\n    \tgit var --run GIT_EDITOR \"$@\"\n    }\n    git_pager() {\n    \tgit var --run GIT_PAGER \"$@\"\n    }\n"},{"id":"126349","messageId":"117f2cc80910291921u6fc5e6e6j12c8433a67852ec0@mail.gmail.com","threadId":"21405","inReplyTo":"7vfx916ea6.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH/RFC 2/2] Provide a build time default-editor setting","fromName":"David Roundy","fromEmail":"roundyd@physics.oregonstate.edu","sentAt":"2009-10-30T02:21:44Z","receivedAt":"2009-10-30T02:21:44Z","isPatch":true,"sender":{"key":"roundyd@physics.oregonstate.edu","avatar":"https://gravatar.com/avatar/20c6928b273bb8a1c23deb12399d0e74782ce911504ad5ee604294fc6a61940a?d=mp&s=160"},"body":"On Thu, Oct 29, 2009 at 6:12 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Johannes Sixt <j.sixt@viscovery.net> writes:\n>\n>> Yeah, whatever, I didn't take the time to think it through. But this may be an\n>> opportunity to give some life back to the zombie that git-var currently is,\n>> that is, to make it the plumbing that does value discovery for variables like\n>> GIT_AUTHOR_INDENT, GIT_COMMITTER_IDENT, GIT_EDITOR, and perhaps also\n>> GIT_PAGER.\n>\n> Hmm, wouldn't it make even more sense to \"run\" them for the calling\n> Porcelain script?\n\nThat was what I had been thinking.  That way the caller doesn't need\nto know whether it may be a space-containing absolute path or an\nexecutable with flags, as long as git knows what to do.\n\nDavid\n"},{"id":"126363","messageId":"20091030101634.GA1610@progeny.tock","threadId":"21405","inReplyTo":"7v8weu6idl.fsf@alter.siamese.dyndns.org","subject":"[PATCH v2 0/8] Default pager and editor","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-30T10:16:34Z","receivedAt":"2009-10-30T10:16:34Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Junio C Hamano wrote:\n\n> My \"how about\" patch on DEFAULT_PAGER might be minimally safe with\n> \n>     make DEFAULT_PAGER=\"/c/my program/less\"\n\nIt isn’t, actually, since in pager.c the pager already gets run through\nsh if it contains certain shell metacharacters.\n\n> but if you are going to do this for real, you would need to use proper\n> quoting in the Makefile (look for _SQ for hints).\n\nGood catch --- thanks.\n \n> > This change makes t7005-editor into a mess.  Any ideas for fixing\n> > this?\n> \n> I think the introduction of DEFAULT_EDITOR makes it unfixable; your\n> DEFAULT_EDITOR may be set to '/usr/bin/vi' not 'vi'.\n> \n> Just detect DEFAULT_EDITOR being not the default 'vi' and abort/skip the\n> entire test, perhaps?\n\nYep, unfortunately that looks like the best thing to do.  I tried to\nsalvage some of the test for distros (like Debian) that might override\nthe default without using an absolute path.\n\nHere’s an updated series.  It doesn’t provide git var --run yet since\nthe Windows exit status magic means that would require either futzing\nwith the run_pager() implementation or reimplementing cat in var.c.\n\nThoughts?\n\nJohannes Sixt (1):\n  Teach git var about GIT_EDITOR\n\nJonathan Nieder (6):\n  launch_editor: Longer error message when TERM=dumb\n  Handle more shell metacharacters in editor name\n  Teach git var about GIT_PAGER\n  add -i, send-email, svn, p4, etc: Use \"git var GIT_EDITOR\"\n  am -i, git-svn: use $(git var GIT_PAGER) instead of 'less'\n  Provide a build time default-editor setting\n\nJunio C Hamano (1):\n  Provide a build time default-pager setting\n\n Documentation/config.txt         |    4 +---\n Documentation/git-commit.txt     |    2 +-\n Documentation/git-send-email.txt |    4 ++--\n Documentation/git-var.txt        |   14 ++++++++++++++\n Makefile                         |   28 ++++++++++++++++++++++++++++\n cache.h                          |    2 ++\n contrib/fast-import/git-p4       |    5 +----\n editor.c                         |   33 ++++++++++++++++++++++++++++-----\n git-add--interactive.perl        |    3 +--\n git-am.sh                        |    5 ++++-\n git-send-email.perl              |    3 ++-\n git-sh-setup.sh                  |   19 ++++++-------------\n git-svn.perl                     |   11 ++++-------\n pager.c                          |   24 ++++++++++++++++++++----\n t/t7005-editor.sh                |   31 ++++++++++++++++++++++++-------\n var.c                            |   20 ++++++++++++++++++++\n 16 files changed, 158 insertions(+), 50 deletions(-)\n"},{"id":"126364","messageId":"20091030102048.GB1610@progeny.tock","threadId":"21405","inReplyTo":"20091030101634.GA1610@progeny.tock","subject":"[PATCH 1/8] launch_editor: Longer error message when TERM=dumb","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-30T10:20:48Z","receivedAt":"2009-10-30T10:20:48Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Before falling back to vi, git checks if the terminal can support\nsuch an editor by checking if $TERM is dumb.  git-sh-setup and\neditor.c have similar but distinct error messages for this case.\nTo avoid changes in behavior when switching from one\nimplementation to the other, standardize on one error message.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\nProbably this check should apply to $VISUAL, too, but that is a\nseparate topic.\n\nI am not sure which is the better error message.  It looks like some\neffort went into the longer message so I thought I should give it a\ntry, but I kind of prefer the shorter one.\n\n editor.c |    8 +++++++-\n 1 files changed, 7 insertions(+), 1 deletions(-)\n\ndiff --git a/editor.c b/editor.c\nindex 4d469d0..316d139 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -16,7 +16,13 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en\n \n \tterminal = getenv(\"TERM\");\n \tif (!editor && (!terminal || !strcmp(terminal, \"dumb\")))\n-\t\treturn error(\"Terminal is dumb but no VISUAL nor EDITOR defined.\");\n+\t\t/* Terminal is dumb but no VISUAL nor EDITOR defined. */\n+\t\treturn error(\n+\t\t  \"No editor specified in GIT_EDITOR, core.editor, VISUAL,\\n\"\n+\t\t  \"or EDITOR. Tried to fall back to vi but terminal is dumb.\\n\"\n+\t\t  \"Please set one of these variables to an appropriate\\n\"\n+\t\t  \"editor or run again with options that will not cause an\\n\"\n+\t\t  \"editor to be invoked (e.g., -m or -F for git commit).\");\n \n \tif (!editor)\n \t\teditor = \"vi\";\n-- \n1.6.5.2\n"},{"id":"126365","messageId":"20091030102548.GC1610@progeny.tock","threadId":"21405","inReplyTo":"20091030101634.GA1610@progeny.tock","subject":"[PATCH 2/8] Handle more shell metacharacters in editor names","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-30T10:25:48Z","receivedAt":"2009-10-30T10:25:48Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Pass the editor name to the shell if it contains any susv3 shell\nspecial character (globs, redirections, variable substitutions,\nescapes, etc).  This way, the meaning of some characters will not\nmeaninglessly change when others are added, and git commands\nimplemented in C and in shell scripts will interpret editor names\nin the same way.\n\nThis does not make the GIT_EDITOR setting any more expressive,\nsince one could always use single quotes to force the editor to\nbe passed to the shell.\n\nSigned-off-by: Jonathan Nieder<jrnieder@gmail.com>\n---\n editor.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/editor.c b/editor.c\nindex 316d139..facd7f2 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -34,7 +34,7 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en\n \t\tconst char *args[6];\n \t\tstruct strbuf arg0 = STRBUF_INIT;\n \n-\t\tif (strcspn(editor, \"$ \\t'\") != len) {\n+\t\tif (strcspn(editor, \"|&;<>()$`\\\\\\\"' \\t\\n*?[#~=%\") != len) {\n \t\t\t/* there are specials */\n \t\t\tstrbuf_addf(&arg0, \"%s \\\"$@\\\"\", editor);\n \t\t\targs[i++] = \"sh\";\n-- \n1.6.5.2\n"},{"id":"126366","messageId":"20091030102658.GD1610@progeny.tock","threadId":"21405","inReplyTo":"20091030101634.GA1610@progeny.tock","subject":"[PATCH 3/8] Teach git var about GIT_EDITOR","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-30T10:26:58Z","receivedAt":"2009-10-30T10:26:58Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"From: Johannes Sixt <j.sixt@viscovery.net>\n\nExpose the command used by launch_editor() for scripts to use.\nThis should allow one to avoid searching for a proper editor\nseparately in each command.\n\nSigned-off-by: Johannes Sixt <j6t@kdbg.org>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n Documentation/git-var.txt |    8 ++++++++\n cache.h                   |    1 +\n editor.c                  |   18 +++++++++++++++---\n var.c                     |   10 ++++++++++\n 4 files changed, 34 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-var.txt b/Documentation/git-var.txt\nindex e2f4c09..89e4b4f 100644\n--- a/Documentation/git-var.txt\n+++ b/Documentation/git-var.txt\n@@ -36,6 +36,14 @@ GIT_AUTHOR_IDENT::\n GIT_COMMITTER_IDENT::\n     The person who put a piece of code into git.\n \n+GIT_EDITOR::\n+    Text editor for use by git commands.  The value is meant to be\n+    interpreted by the shell when it is used.  Examples: `~/bin/vi`,\n+    `$SOME_ENVIRONMENT_VARIABLE`, `\"C:\\Program Files\\Vim\\gvim.exe\"\n+    --nofork`.  The order of preference is the `$GIT_EDITOR`\n+    environment variable, then `core.editor` configuration, then\n+    `$VISUAL`, then `$EDITOR`, and then finally 'vi'.\n+\n Diagnostics\n -----------\n You don't exist. Go away!::\ndiff --git a/cache.h b/cache.h\nindex 96840c7..311cfe1 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -750,6 +750,7 @@ extern const char *git_author_info(int);\n extern const char *git_committer_info(int);\n extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int);\n extern const char *fmt_name(const char *name, const char *email);\n+extern const char *git_editor(void);\n \n struct checkout {\n \tconst char *base_dir;\ndiff --git a/editor.c b/editor.c\nindex facd7f2..9dcf95c 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -2,7 +2,7 @@\n #include \"strbuf.h\"\n #include \"run-command.h\"\n \n-int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)\n+const char *git_editor(void)\n {\n \tconst char *editor, *terminal;\n \n@@ -15,18 +15,30 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en\n \t\teditor = getenv(\"EDITOR\");\n \n \tterminal = getenv(\"TERM\");\n-\tif (!editor && (!terminal || !strcmp(terminal, \"dumb\")))\n+\tif (!editor && (!terminal || !strcmp(terminal, \"dumb\"))) {\n \t\t/* Terminal is dumb but no VISUAL nor EDITOR defined. */\n-\t\treturn error(\n+\t\terror(\n \t\t  \"No editor specified in GIT_EDITOR, core.editor, VISUAL,\\n\"\n \t\t  \"or EDITOR. Tried to fall back to vi but terminal is dumb.\\n\"\n \t\t  \"Please set one of these variables to an appropriate\\n\"\n \t\t  \"editor or run again with options that will not cause an\\n\"\n \t\t  \"editor to be invoked (e.g., -m or -F for git commit).\");\n+\t\treturn NULL;\n+\t}\n \n \tif (!editor)\n \t\teditor = \"vi\";\n \n+\treturn editor;\n+}\n+\n+int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)\n+{\n+\tconst char *editor = git_editor();\n+\n+\tif (!editor)\n+\t\treturn -1;\n+\n \tif (strcmp(editor, \":\")) {\n \t\tsize_t len = strlen(editor);\n \t\tint i = 0;\ndiff --git a/var.c b/var.c\nindex 125c0d1..342dc2c 100644\n--- a/var.c\n+++ b/var.c\n@@ -8,6 +8,15 @@\n \n static const char var_usage[] = \"git var [-l | <variable>]\";\n \n+static const char *editor(int flag)\n+{\n+\tconst char *pgm = git_editor();\n+\n+\tif (!pgm && (flag & IDENT_ERROR_ON_NO_NAME))\n+\t\tdie(\"cannot find a suitable editor\");\n+\treturn pgm;\n+}\n+\n struct git_var {\n \tconst char *name;\n \tconst char *(*read)(int);\n@@ -15,6 +24,7 @@ struct git_var {\n static struct git_var git_vars[] = {\n \t{ \"GIT_COMMITTER_IDENT\", git_committer_info },\n \t{ \"GIT_AUTHOR_IDENT\",   git_author_info },\n+\t{ \"GIT_EDITOR\", editor },\n \t{ \"\", NULL },\n };\n \n-- \n1.6.5.2\n"},{"id":"126367","messageId":"20091030102921.GE1610@progeny.tock","threadId":"21405","inReplyTo":"20091030101634.GA1610@progeny.tock","subject":"[PATCH 4/8] Teach git var about GIT_PAGER","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-30T10:29:22Z","receivedAt":"2009-10-30T10:29:22Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Expose the command found by setup_pager() for scripts to use.\nScripts can use this to avoid repeating the logic to look for a\nproper pager in each command.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n Documentation/git-var.txt |    6 ++++++\n cache.h                   |    1 +\n pager.c                   |   18 +++++++++++++++---\n var.c                     |   10 ++++++++++\n 4 files changed, 32 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-var.txt b/Documentation/git-var.txt\nindex 89e4b4f..ef6aa81 100644\n--- a/Documentation/git-var.txt\n+++ b/Documentation/git-var.txt\n@@ -44,6 +44,12 @@ GIT_EDITOR::\n     environment variable, then `core.editor` configuration, then\n     `$VISUAL`, then `$EDITOR`, and then finally 'vi'.\n \n+GIT_PAGER::\n+    Text viewer for use by git commands (e.g., 'less').  The value\n+    is meant to be interpreted by the shell.  The order of preference\n+    is the `$GIT_PAGER` environment variable, then `core.pager`\n+    configuration, then `$PAGER`, and then finally 'less'.\n+\n Diagnostics\n -----------\n You don't exist. Go away!::\ndiff --git a/cache.h b/cache.h\nindex 311cfe1..5aaa4ba 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -751,6 +751,7 @@ extern const char *git_committer_info(int);\n extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int);\n extern const char *fmt_name(const char *name, const char *email);\n extern const char *git_editor(void);\n+extern const char *git_pager(void);\n \n struct checkout {\n \tconst char *base_dir;\ndiff --git a/pager.c b/pager.c\nindex 86facec..0b63d99 100644\n--- a/pager.c\n+++ b/pager.c\n@@ -44,12 +44,14 @@ static void wait_for_pager_signal(int signo)\n \traise(signo);\n }\n \n-void setup_pager(void)\n+const char *git_pager(void)\n {\n-\tconst char *pager = getenv(\"GIT_PAGER\");\n+\tconst char *pager;\n \n \tif (!isatty(1))\n-\t\treturn;\n+\t\treturn NULL;\n+\n+\tpager = getenv(\"GIT_PAGER\");\n \tif (!pager) {\n \t\tif (!pager_program)\n \t\t\tgit_config(git_default_config, NULL);\n@@ -60,6 +62,16 @@ void setup_pager(void)\n \tif (!pager)\n \t\tpager = \"less\";\n \telse if (!*pager || !strcmp(pager, \"cat\"))\n+\t\tpager = NULL;\n+\n+\treturn pager;\n+}\n+\n+void setup_pager(void)\n+{\n+\tconst char *pager = git_pager();\n+\n+\tif (!pager)\n \t\treturn;\n \n \tspawned_pager = 1; /* means we are emitting to terminal */\ndiff --git a/var.c b/var.c\nindex 342dc2c..18dad57 100644\n--- a/var.c\n+++ b/var.c\n@@ -17,6 +17,15 @@ static const char *editor(int flag)\n \treturn pgm;\n }\n \n+static const char *pager(int flag)\n+{\n+\tconst char *pgm = git_pager();\n+\n+\tif (!pgm)\n+\t\tpgm = \"cat\";\n+\treturn pgm;\n+}\n+\n struct git_var {\n \tconst char *name;\n \tconst char *(*read)(int);\n@@ -25,6 +34,7 @@ static struct git_var git_vars[] = {\n \t{ \"GIT_COMMITTER_IDENT\", git_committer_info },\n \t{ \"GIT_AUTHOR_IDENT\",   git_author_info },\n \t{ \"GIT_EDITOR\", editor },\n+\t{ \"GIT_PAGER\", pager },\n \t{ \"\", NULL },\n };\n \n-- \n1.6.5.2\n"},{"id":"126368","messageId":"20091030103217.GF1610@progeny.tock","threadId":"21405","inReplyTo":"20091030101634.GA1610@progeny.tock","subject":"[PATCH 5/8] add -i, send-email, svn, p4, etc: use \"git var GIT_EDITOR\"","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-30T10:32:17Z","receivedAt":"2009-10-30T10:32:17Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Use the new \"git var GIT_EDITOR\" feature to decide what editor to\nuse, instead of duplicating its logic elsewhere.  This should make\nthe behavior of commands in edge cases (e.g., editor names with\nspaces) a little more consistent.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n Documentation/config.txt         |    4 +---\n Documentation/git-commit.txt     |    2 +-\n Documentation/git-send-email.txt |    4 ++--\n contrib/fast-import/git-p4       |    5 +----\n git-add--interactive.perl        |    3 +--\n git-send-email.perl              |    3 ++-\n git-sh-setup.sh                  |   19 ++++++-------------\n git-svn.perl                     |    5 ++---\n 8 files changed, 16 insertions(+), 29 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex d1e2120..5181b77 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -387,9 +387,7 @@ core.editor::\n \tCommands such as `commit` and `tag` that lets you edit\n \tmessages by launching an editor uses the value of this\n \tvariable when it is set, and the environment variable\n-\t`GIT_EDITOR` is not set.  The order of preference is\n-\t`GIT_EDITOR` environment, `core.editor`, `VISUAL` and\n-\t`EDITOR` environment variables and then finally `vi`.\n+\t`GIT_EDITOR` is not set.  See linkgit:git-var[1].\n \n core.pager::\n \tThe command that git will use to paginate output.  Can\ndiff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt\nindex 0578a40..3ea80c8 100644\n--- a/Documentation/git-commit.txt\n+++ b/Documentation/git-commit.txt\n@@ -323,7 +323,7 @@ ENVIRONMENT AND CONFIGURATION VARIABLES\n The editor used to edit the commit log message will be chosen from the\n GIT_EDITOR environment variable, the core.editor configuration variable, the\n VISUAL environment variable, or the EDITOR environment variable (in that\n-order).\n+order).  See linkgit:git-var[1] for details.\n \n HOOKS\n -----\ndiff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt\nindex 767cf4d..c85d7f4 100644\n--- a/Documentation/git-send-email.txt\n+++ b/Documentation/git-send-email.txt\n@@ -60,8 +60,8 @@ The --bcc option must be repeated for each user you want on the bcc list.\n The --cc option must be repeated for each user you want on the cc list.\n \n --compose::\n-\tUse $GIT_EDITOR, core.editor, $VISUAL, or $EDITOR to edit an\n-\tintroductory message for the patch series.\n+\tInvoke a text editor (see GIT_EDITOR in linkgit:git-var[1])\n+\tto edit an introductory message for the patch series.\n +\n When '--compose' is used, git send-email will use the From, Subject, and\n In-Reply-To headers specified in the message. If the body of the message\ndiff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4\nindex e710219..48059d0 100755\n--- a/contrib/fast-import/git-p4\n+++ b/contrib/fast-import/git-p4\n@@ -729,13 +729,10 @@ class P4Submit(Command):\n             tmpFile.write(submitTemplate + separatorLine + diff + newdiff)\n             tmpFile.close()\n             mtime = os.stat(fileName).st_mtime\n-            defaultEditor = \"vi\"\n-            if platform.system() == \"Windows\":\n-                defaultEditor = \"notepad\"\n             if os.environ.has_key(\"P4EDITOR\"):\n                 editor = os.environ.get(\"P4EDITOR\")\n             else:\n-                editor = os.environ.get(\"EDITOR\", defaultEditor);\n+                editor = read_pipe(\"git var GIT_EDITOR\")\n             system(editor + \" \" + fileName)\n \n             response = \"y\"\ndiff --git a/git-add--interactive.perl b/git-add--interactive.perl\nindex 69aeaf0..0c74e5c 100755\n--- a/git-add--interactive.perl\n+++ b/git-add--interactive.perl\n@@ -987,8 +987,7 @@ sub edit_hunk_manually {\n EOF\n \tclose $fh;\n \n-\tmy $editor = $ENV{GIT_EDITOR} || $repo->config(\"core.editor\")\n-\t\t|| $ENV{VISUAL} || $ENV{EDITOR} || \"vi\";\n+\tchomp(my $editor = run_cmd_pipe(qw(git var GIT_EDITOR)));\n \tsystem('sh', '-c', $editor.' \"$@\"', $editor, $hunkfile);\n \n \tif ($? != 0) {\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex a0279de..4f5da4e 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -162,7 +162,8 @@ my $compose_filename;\n \n # Handle interactive edition of files.\n my $multiedit;\n-my $editor = $ENV{GIT_EDITOR} || Git::config(@repo, \"core.editor\") || $ENV{VISUAL} || $ENV{EDITOR} || \"vi\";\n+my $editor = Git::command_oneline('var', 'GIT_EDITOR');\n+\n sub do_edit {\n \tif (defined($multiedit) && !$multiedit) {\n \t\tmap {\ndiff --git a/git-sh-setup.sh b/git-sh-setup.sh\nindex c41c2f7..99cceeb 100755\n--- a/git-sh-setup.sh\n+++ b/git-sh-setup.sh\n@@ -99,19 +99,12 @@ set_reflog_action() {\n }\n \n git_editor() {\n-\t: \"${GIT_EDITOR:=$(git config core.editor)}\"\n-\t: \"${GIT_EDITOR:=${VISUAL:-${EDITOR}}}\"\n-\tcase \"$GIT_EDITOR,$TERM\" in\n-\t,dumb)\n-\t\techo >&2 \"No editor specified in GIT_EDITOR, core.editor, VISUAL,\"\n-\t\techo >&2 \"or EDITOR. Tried to fall back to vi but terminal is dumb.\"\n-\t\techo >&2 \"Please set one of these variables to an appropriate\"\n-\t\techo >&2 \"editor or run $0 with options that will not cause an\"\n-\t\techo >&2 \"editor to be invoked (e.g., -m or -F for git-commit).\"\n-\t\texit 1\n-\t\t;;\n-\tesac\n-\teval \"${GIT_EDITOR:=vi}\" '\"$@\"'\n+\tif test -z \"${GIT_EDITOR:+set}\"\n+\tthen\n+\t\tGIT_EDITOR=\"$(git var GIT_EDITOR)\" || return $?\n+\tfi\n+\n+\teval \"$GIT_EDITOR\" '\"$@\"'\n }\n \n is_bare_repository () {\ndiff --git a/git-svn.perl b/git-svn.perl\nindex 6a3b501..42c9a72 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -1321,9 +1321,8 @@ sub get_commit_entry {\n \tclose $log_fh or croak $!;\n \n \tif ($_edit || ($type eq 'tree')) {\n-\t\tmy $editor = $ENV{VISUAL} || $ENV{EDITOR} || 'vi';\n-\t\t# TODO: strip out spaces, comments, like git-commit.sh\n-\t\tsystem($editor, $commit_editmsg);\n+\t\tchomp(my $editor = command_oneline(qw(var GIT_EDITOR)));\n+\t\tsystem('sh', '-c', $editor.' \"$@\"', $editor, $commit_editmsg);\n \t}\n \trename $commit_editmsg, $commit_msg or croak $!;\n \t{\n-- \n1.6.5.2\n"},{"id":"126369","messageId":"20091030103354.GG1610@progeny.tock","threadId":"21405","inReplyTo":"20091030101634.GA1610@progeny.tock","subject":"[PATCH 6/8] am -i, git-svn: use \"git var GIT_PAGER\"","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-30T10:33:54Z","receivedAt":"2009-10-30T10:33:54Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Use the new \"git var GIT_PAGER\" command to ask what pager to use.\n\nWithout this change, the core.pager configuration is ignored by\nthese commands.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n git-am.sh    |    5 ++++-\n git-svn.perl |    6 ++----\n 2 files changed, 6 insertions(+), 5 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex c132f50..2649487 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -649,7 +649,10 @@ do\n \t\t[eE]*) git_editor \"$dotest/final-commit\"\n \t\t       action=again ;;\n \t\t[vV]*) action=again\n-\t\t       LESS=-S ${PAGER:-less} \"$dotest/patch\" ;;\n+\t\t       : ${GIT_PAGER=$(git var GIT_PAGER)}\n+\t\t       : ${LESS=-FRSX}\n+\t\t       export LESS\n+\t\t       $GIT_PAGER \"$dotest/patch\" ;;\n \t\t*)     action=again ;;\n \t\tesac\n \t    done\ndiff --git a/git-svn.perl b/git-svn.perl\nindex 42c9a72..c4ca548 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -5171,10 +5171,8 @@ sub git_svn_log_cmd {\n \n # adapted from pager.c\n sub config_pager {\n-\t$pager ||= $ENV{GIT_PAGER} || $ENV{PAGER};\n-\tif (!defined $pager) {\n-\t\t$pager = 'less';\n-\t} elsif (length $pager == 0 || $pager eq 'cat') {\n+\tchomp(my $pager = command_oneline(qw(var GIT_PAGER)));\n+\tif ($pager eq 'cat') {\n \t\t$pager = undef;\n \t}\n \t$ENV{GIT_PAGER_IN_USE} = defined($pager);\n-- \n1.6.5.2\n"},{"id":"126370","messageId":"20091030103558.GH1610@progeny.tock","threadId":"21405","inReplyTo":"20091030101634.GA1610@progeny.tock","subject":"[PATCH 7/8] Provide a build time default-editor setting","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-30T10:35:58Z","receivedAt":"2009-10-30T10:35:58Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Provide a DEFAULT_EDITOR knob to allow setting the fallback\neditor to use instead of vi (when VISUAL, EDITOR, and GIT_EDITOR\nare unset).  The value can be set at build time according to a\nsystem’s policy.  For example, on Debian systems, the default\neditor should be the 'editor' command.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Ben Walton <bwalton@bwalton@artsci.utoronto.ca>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n Makefile          |   17 +++++++++++++++++\n editor.c          |   11 ++++++++---\n t/t7005-editor.sh |   31 ++++++++++++++++++++++++-------\n 3 files changed, 49 insertions(+), 10 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 268aede..625866c 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -200,6 +200,14 @@ all::\n # memory allocators with the nedmalloc allocator written by Niall Douglas.\n #\n # Define NO_REGEX if you have no or inferior regex support in your C library.\n+#\n+# Define DEFAULT_EDITOR to a sensible editor command (defaults to \"vi\") if you\n+# want to use something different.  The value will be interpreted by the shell\n+# if necessary when it is used.  Examples:\n+#\n+#   DEFAULT_EDITOR='~/bin/vi',\n+#   DEFAULT_EDITOR='$GIT_FALLBACK_EDITOR',\n+#   DEFAULT_EDITOR='\"C:\\Program Files\\Vim\\gvim.exe\" --nofork'\n \n GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE\n \t@$(SHELL_PATH) ./GIT-VERSION-GEN\n@@ -1363,6 +1371,15 @@ BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' \\\n \t$(COMPAT_CFLAGS)\n LIB_OBJS += $(COMPAT_OBJS)\n \n+# Quote for C\n+\n+ifdef DEFAULT_EDITOR\n+DEFAULT_EDITOR_CQ = \"$(subst \",\\\",$(subst \\,\\\\,$(DEFAULT_EDITOR)))\"\n+DEFAULT_EDITOR_CQ_SQ = $(subst ','\\'',$(DEFAULT_EDITOR_CQ))\n+\n+BASIC_CFLAGS += -DDEFAULT_EDITOR='$(DEFAULT_EDITOR_CQ_SQ)'\n+endif\n+\n ALL_CFLAGS += $(BASIC_CFLAGS)\n ALL_LDFLAGS += $(BASIC_LDFLAGS)\n \ndiff --git a/editor.c b/editor.c\nindex 9dcf95c..fcf35a8 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -2,6 +2,10 @@\n #include \"strbuf.h\"\n #include \"run-command.h\"\n \n+#ifndef DEFAULT_EDITOR\n+#define DEFAULT_EDITOR \"vi\"\n+#endif\n+\n const char *git_editor(void)\n {\n \tconst char *editor, *terminal;\n@@ -19,15 +23,16 @@ const char *git_editor(void)\n \t\t/* Terminal is dumb but no VISUAL nor EDITOR defined. */\n \t\terror(\n \t\t  \"No editor specified in GIT_EDITOR, core.editor, VISUAL,\\n\"\n-\t\t  \"or EDITOR. Tried to fall back to vi but terminal is dumb.\\n\"\n+\t\t  \"or EDITOR. Tried to fall back to %s but terminal is dumb.\\n\"\n \t\t  \"Please set one of these variables to an appropriate\\n\"\n \t\t  \"editor or run again with options that will not cause an\\n\"\n-\t\t  \"editor to be invoked (e.g., -m or -F for git commit).\");\n+\t\t  \"editor to be invoked (e.g., -m or -F for git commit).\",\n+\t\t  DEFAULT_EDITOR);\n \t\treturn NULL;\n \t}\n \n \tif (!editor)\n-\t\teditor = \"vi\";\n+\t\teditor = DEFAULT_EDITOR;\n \n \treturn editor;\n }\ndiff --git a/t/t7005-editor.sh b/t/t7005-editor.sh\nindex b647957..73ba44c 100755\n--- a/t/t7005-editor.sh\n+++ b/t/t7005-editor.sh\n@@ -4,7 +4,26 @@ test_description='GIT_EDITOR, core.editor, and stuff'\n \n . ./test-lib.sh\n \n-for i in GIT_EDITOR core_editor EDITOR VISUAL vi\n+unset EDITOR VISUAL GIT_EDITOR\n+\n+test_expect_success 'does editor have a simple name (no slashes, etc)?' '\n+\n+\teditor=$(TERM=vt100 git var GIT_EDITOR) &&\n+\ttest -n \"$editor\" &&\n+\tsimple=t &&\n+\tcase \"$editor\" in\n+\t*/* | core_editor | [A-Z]*)\n+\t\tunset simple;;\n+\tesac\n+\n+'\n+if test -z \"${simple+set}\"\n+then\n+\tsay 'skipping editor tests, default editor is not sought on PATH'\n+\ttest_done\n+fi\n+\n+for i in GIT_EDITOR core_editor EDITOR VISUAL \"$editor\"\n do\n \tcat >e-$i.sh <<-EOF\n \t#!$SHELL_PATH\n@@ -12,15 +31,13 @@ do\n \tEOF\n \tchmod +x e-$i.sh\n done\n-unset vi\n-mv e-vi.sh vi\n-unset EDITOR VISUAL GIT_EDITOR\n+mv \"e-$editor.sh\" \"$editor\"\n \n test_expect_success setup '\n \n \tmsg=\"Hand edited\" &&\n \techo \"$msg\" >expect &&\n-\tgit add vi &&\n+\tgit add \"$editor\" &&\n \ttest_tick &&\n \tgit commit -m \"$msg\" &&\n \tgit show -s --pretty=oneline |\n@@ -44,7 +61,7 @@ test_expect_success 'dumb should error out when falling back on vi' '\n \n TERM=vt100\n export TERM\n-for i in vi EDITOR VISUAL core_editor GIT_EDITOR\n+for i in \"$editor\" EDITOR VISUAL core_editor GIT_EDITOR\n do\n \techo \"Edited by $i\" >expect\n \tunset EDITOR VISUAL GIT_EDITOR\n@@ -68,7 +85,7 @@ done\n \n unset EDITOR VISUAL GIT_EDITOR\n git config --unset-all core.editor\n-for i in vi EDITOR VISUAL core_editor GIT_EDITOR\n+for i in \"$editor\" EDITOR VISUAL core_editor GIT_EDITOR\n do\n \techo \"Edited by $i\" >expect\n \tcase \"$i\" in\n-- \n1.6.5.2\n"},{"id":"126371","messageId":"20091030103925.GI1610@progeny.tock","threadId":"21405","inReplyTo":"20091030101634.GA1610@progeny.tock","subject":"[PATCH 8/8] Provide a build time default-pager setting","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-30T10:39:25Z","receivedAt":"2009-10-30T10:39:25Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"From: Junio C Hamano <gitster@pobox.com>\n\nProvide a DEFAULT_PAGER knob so packagers can set the fallback\npager to something appropriate during the build.\n\nExamples:\n\nOn (old) solaris systems, /usr/bin/less (typically the first less\nfound) doesn't understand the default arguments (FXRS), which\nforces users to alter their environment (PATH, GIT_PAGER, LESS,\netc) or have a local or global gitconfig before paging works as\nexpected.\n\nOn Debian systems, by policy packages must fall back to the\n'pager' command, so that changing the target of the\n/usr/bin/pager symlink changes the default pager for all packages\nat once.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Ben Walton <bwalton@artsci.utoronto.ca>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\nPreviously I suggested that the default pager isn’t being tracked\nproperly with TRACK_CFLAGS.  Actually, since it is included in\nBASIC_CFLAGS, it always was.  Sorry for the confusion.\n\n Makefile |   11 +++++++++++\n pager.c  |    6 +++++-\n 2 files changed, 16 insertions(+), 1 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 625866c..18fc50a 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -201,6 +201,10 @@ all::\n #\n # Define NO_REGEX if you have no or inferior regex support in your C library.\n #\n+# Define DEFAULT_PAGER to a sensible pager command (defaults to \"less\") if\n+# you want to use something different.  The value will be interpreted by the\n+# shell at runtime when it is used.\n+#\n # Define DEFAULT_EDITOR to a sensible editor command (defaults to \"vi\") if you\n # want to use something different.  The value will be interpreted by the shell\n # if necessary when it is used.  Examples:\n@@ -1380,6 +1384,13 @@ DEFAULT_EDITOR_CQ_SQ = $(subst ','\\'',$(DEFAULT_EDITOR_CQ))\n BASIC_CFLAGS += -DDEFAULT_EDITOR='$(DEFAULT_EDITOR_CQ_SQ)'\n endif\n \n+ifdef DEFAULT_PAGER\n+DEFAULT_PAGER_CQ = \"$(subst \",\\\",$(subst \\,\\\\,$(DEFAULT_PAGER)))\"\n+DEFAULT_PAGER_CQ_SQ = $(subst ','\\'',$(DEFAULT_PAGER_CQ))\n+\n+BASIC_CFLAGS += -DDEFAULT_PAGER='$(DEFAULT_PAGER_CQ_SQ)'\n+endif\n+\n ALL_CFLAGS += $(BASIC_CFLAGS)\n ALL_LDFLAGS += $(BASIC_LDFLAGS)\n \ndiff --git a/pager.c b/pager.c\nindex 0b63d99..92c03f6 100644\n--- a/pager.c\n+++ b/pager.c\n@@ -2,6 +2,10 @@\n #include \"run-command.h\"\n #include \"sigchain.h\"\n \n+#ifndef DEFAULT_PAGER\n+#define DEFAULT_PAGER \"less\"\n+#endif\n+\n /*\n  * This is split up from the rest of git so that we can do\n  * something different on Windows.\n@@ -60,7 +64,7 @@ const char *git_pager(void)\n \tif (!pager)\n \t\tpager = getenv(\"PAGER\");\n \tif (!pager)\n-\t\tpager = \"less\";\n+\t\tpager = DEFAULT_PAGER;\n \telse if (!*pager || !strcmp(pager, \"cat\"))\n \t\tpager = NULL;\n \n-- \n1.6.5.2\n"},{"id":"126372","messageId":"20091030104958.GJ1610@progeny.tock","threadId":"21405","inReplyTo":"20091030101634.GA1610@progeny.tock","subject":"[PATCH/RFC 9/8] Teach git var to run the editor","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-30T10:49:58Z","receivedAt":"2009-10-30T10:49:58Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Expose the functionality of launch_editor() for scripts to use.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\nAs I mentioned in the cover letter, the analogous change for the pager\nis a little more tricky.  I was wrong to blame Windows for this.  The\nexcellent commit ea27a18 (spawn pager via run_command interface,\n2008-07-22) explains all.\n\nThe difficulties: the pager receives input from the current process\nand the run_pager() function does not take an argument to take input\nfrom somewhere else.  Also the pager is not exec()'d directly, so the\ncurrent process sticks around uselessly until it quits and it is a\nlittle tricky to find the 'less' exit status for \"git var --run\" to\nuse as well.\n\n Documentation/git-var.txt |   10 ++++++++-\n var.c                     |   48 +++++++++++++++++++++++++++++++++++++-------\n 2 files changed, 49 insertions(+), 9 deletions(-)\n\ndiff --git a/Documentation/git-var.txt b/Documentation/git-var.txt\nindex ef6aa81..1bfdb6c 100644\n--- a/Documentation/git-var.txt\n+++ b/Documentation/git-var.txt\n@@ -8,7 +8,10 @@ git-var - Show a git logical variable\n \n SYNOPSIS\n --------\n-'git var' [ -l | <variable> ]\n+[verse]\n+'git var' <variable>\n+'git var' -l\n+'git var' --run <variable> [ args ]\n \n DESCRIPTION\n -----------\n@@ -22,6 +25,11 @@ OPTIONS\n \tas well. (However, the configuration variables listing functionality\n \tis deprecated in favor of 'git config -l'.)\n \n+--run variable [args]::\n+\tIf the specified logical variable represents a command, run that\n+\tcommand.  For example, `git var --run GIT_EDITOR foo.txt` edits\n+\tfoo.txt with the text editor git is configured to use.\n+\n EXAMPLE\n --------\n \t$ git var GIT_AUTHOR_IDENT\ndiff --git a/var.c b/var.c\nindex 18dad57..c97b2e6 100644\n--- a/var.c\n+++ b/var.c\n@@ -6,7 +6,8 @@\n #include \"cache.h\"\n #include \"exec_cmd.h\"\n \n-static const char var_usage[] = \"git var [-l | <variable>]\";\n+static const char var_usage[] =\n+\t\"git var { -l | <variable> | --run <variable> [args] }\";\n \n static const char *editor(int flag)\n {\n@@ -26,16 +27,25 @@ static const char *pager(int flag)\n \treturn pgm;\n }\n \n+static int run_editor(int argc, const char *const *argv)\n+{\n+\tif (argc > 1)\n+\t\treturn error(\"cannot launch editor with more than one file\");\n+\n+\treturn launch_editor(argv[0], NULL, NULL);\n+}\n+\n struct git_var {\n \tconst char *name;\n \tconst char *(*read)(int);\n+\tint (*run)(int argc, const char *const *argv);\n };\n static struct git_var git_vars[] = {\n-\t{ \"GIT_COMMITTER_IDENT\", git_committer_info },\n-\t{ \"GIT_AUTHOR_IDENT\",   git_author_info },\n-\t{ \"GIT_EDITOR\", editor },\n-\t{ \"GIT_PAGER\", pager },\n-\t{ \"\", NULL },\n+\t{ \"GIT_COMMITTER_IDENT\", git_committer_info, NULL },\n+\t{ \"GIT_AUTHOR_IDENT\", git_author_info, NULL },\n+\t{ \"GIT_EDITOR\", editor, run_editor },\n+\t{ \"GIT_PAGER\", pager, NULL },\n+\t{ \"\", NULL, NULL },\n };\n \n static void list_vars(void)\n@@ -59,6 +69,17 @@ static const char *read_var(const char *var)\n \treturn val;\n }\n \n+static int run_var_cmd(const char *var, int argc, char **argv)\n+{\n+\tstruct git_var *ptr;\n+\n+\tfor (ptr = git_vars; ptr->read; ptr++)\n+\t\tif (ptr->run && strcmp(var, ptr->name) == 0)\n+\t\t\treturn ptr->run(argc, (const char *const *)argv);\n+\n+\treturn error(\"%s is not a variable command\", var);\n+}\n+\n static int show_config(const char *var, const char *value, void *cb)\n {\n \tif (value)\n@@ -72,12 +93,23 @@ int main(int argc, char **argv)\n {\n \tconst char *val;\n \tint nongit;\n+\n+\tgit_extract_argv0_path(argv[0]);\n+\n+\tif (argv[1] && strcmp(argv[1], \"--run\") == 0) {\n+\t\tif (argc <= 2)\n+\t\t\tusage(var_usage);\n+\n+\t\tsetup_git_directory_gently(&nongit);\n+\t\tgit_config(git_default_config, NULL);\n+\n+\t\treturn run_var_cmd(argv[2], argc - 3, argv + 3);\n+\t}\n+\n \tif (argc != 2) {\n \t\tusage(var_usage);\n \t}\n \n-\tgit_extract_argv0_path(argv[0]);\n-\n \tsetup_git_directory_gently(&nongit);\n \tval = NULL;\n \n-- \n1.6.5.2\n"},{"id":"126383","messageId":"20091030131742.GA15034@progeny.tock","threadId":"21405","inReplyTo":"20091030103558.GH1610@progeny.tock","subject":"Re: [PATCH 7/8] Provide a build time default-editor setting","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-30T13:17:50Z","receivedAt":"2009-10-30T13:17:50Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Jonathan Nieder wrote:\n\n> Signed-off-by: Ben Walton <bwalton@bwalton@artsci.utoronto.ca>\n\nThat should be \"Ben Walton <bwalton@artsci.utoronto.ca>\", without the\nextra bwalton@.  Sorry for the trouble.\n\nRegards,\nJonathan\n"},{"id":"126430","messageId":"4AEB51C6.7060204@kdbg.org","threadId":"21405","inReplyTo":"20091030102658.GD1610@progeny.tock","subject":"Re: [PATCH 3/8] Teach git var about GIT_EDITOR","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2009-10-30T20:51:18Z","receivedAt":"2009-10-30T20:51:18Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Jonathan Nieder schrieb:\n> From: Johannes Sixt <j.sixt@viscovery.net>\n> \n> Expose the command used by launch_editor() for scripts to use.\n> This should allow one to avoid searching for a proper editor\n> separately in each command.\n> \n> Signed-off-by: Johannes Sixt <j6t@kdbg.org>\n> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\n\nThanks for cleaning up behind me. I don't mind if you take authorship, but \nif you do keep my name, please make it:\n\nFrom: Johannes Sixt <j6t@kdbg.org>\n\n> -int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)\n> +const char *git_editor(void)\n>  {\n>  \tconst char *editor, *terminal;\n>  \n> ... \n>  \tterminal = getenv(\"TERM\");\n> -\tif (!editor && (!terminal || !strcmp(terminal, \"dumb\")))\n> +\tif (!editor && (!terminal || !strcmp(terminal, \"dumb\"))) {\n>  \t\t/* Terminal is dumb but no VISUAL nor EDITOR defined. */\n> -\t\treturn error(\n> +\t\terror(\n>  \t\t  \"No editor specified in GIT_EDITOR, core.editor, VISUAL,\\n\"\n>  \t\t  \"or EDITOR. Tried to fall back to vi but terminal is dumb.\\n\"\n>  \t\t  \"Please set one of these variables to an appropriate\\n\"\n>  \t\t  \"editor or run again with options that will not cause an\\n\"\n>  \t\t  \"editor to be invoked (e.g., -m or -F for git commit).\");\n> +\t\treturn NULL;\n> +\t}\n\nI somehow dislike that this huge error message is in git_editor(). The \nreturn value, NULL, should be indication enough for the callers to handle \nthe situation suitable. In particular, launch_editor() wants to write this \nbig warning, but 'git var -l' can avoid the error message and write only a \nshort notice:\n\nGIT_EDITOR=terminal is dumb, but VISUAL and EDITOR unset\n\n> +static const char *editor(int flag)\n> +{\n> +\tconst char *pgm = git_editor();\n> +\n> +\tif (!pgm && (flag & IDENT_ERROR_ON_NO_NAME))\n> +\t\tdie(\"cannot find a suitable editor\");\n> +\treturn pgm;\n\nThis should be\n\n\treturn pgm ? pgm : \"terminal is dumb, but VISUAL and EDITOR unset\";\n\notherwise, 'git var -l' later trips over printf(\"%s\", NULL).\n\n-- Hannes\n"},{"id":"126451","messageId":"7vvdhwfqon.fsf@alter.siamese.dyndns.org","threadId":"21405","inReplyTo":"20091030224737.GA16565@progeny.tock","subject":"Re: [PATCH 3/8] Teach git var about GIT_EDITOR","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-30T22:43:52Z","receivedAt":"2009-10-30T22:43:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonathan Nieder <jrnieder@gmail.com> writes:\n\n> I am a bit uncomfortable with this error in general.  It makes some\n> sense to refuse to use $VISUAL and fall back to $EDITOR if TERM=dumb,\n> since without this the distinction between VISUAL and EDITOR is not\n> very useful.\n\nMore importantly, that is what people traditionally expected from VISUAL\nand EDITOR and we do that only to follow suit.\n\nThere is no such tradition for GIT_EDITOR nor core.editor and switching\nbehaviour based on the name of editor (\"vi\"? \"vim\"?...) does not feel\nquite right.\n"},{"id":"126450","messageId":"20091030224737.GA16565@progeny.tock","threadId":"21405","inReplyTo":"4AEB51C6.7060204@kdbg.org","subject":"Re: [PATCH 3/8] Teach git var about GIT_EDITOR","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-30T22:47:38Z","receivedAt":"2009-10-30T22:47:38Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Johannes Sixt wrote:\n> Jonathan Nieder schrieb:\n\n>> From: Johannes Sixt <j.sixt@viscovery.net>\n[...]\n> Thanks for cleaning up behind me. I don't mind if you take\n> authorship, but if you do keep my name, please make it:\n> \n> From: Johannes Sixt <j6t@kdbg.org>\n\nThanks for the catch.\n\n>>+\t\terror(\n>> \t\t  \"No editor specified in GIT_EDITOR, core.editor, VISUAL,\\n\"\n>> \t\t  \"or EDITOR. Tried to fall back to vi but terminal is dumb.\\n\"\n>> \t\t  \"Please set one of these variables to an appropriate\\n\"\n>> \t\t  \"editor or run again with options that will not cause an\\n\"\n>> \t\t  \"editor to be invoked (e.g., -m or -F for git commit).\");\n>>+\t\treturn NULL;\n>>+\t}\n> \n> I somehow dislike that this huge error message is in git_editor().\n\nMakes sense.\n\nI am a bit uncomfortable with this error in general.  It makes some\nsense to refuse to use $VISUAL and fall back to $EDITOR if TERM=dumb,\nsince without this the distinction between VISUAL and EDITOR is not\nvery useful.  But wouldn’t that check be equally useful if GIT_EDITOR\nor core.editor is set to vi?  Ideally, vi itself would check TERM and\nerror out, and git would only need to report and handle the exit.\n\nUnfortunately, at least vim is happy to assume a terminal supports\nANSI sequences even if TERM=dumb (e.g., when running from a text\neditor like Acme).  Unless VISUAL, GIT_EDITOR, and core.editor are\nunset, nobody gets the benefit of this check.\n\nShould git error out rather than run $VISUAL when TERM=dumb?  How\nabout $GIT_EDITOR?\n\nThe advice about options to avoid invoking an editor is not very\nhelpful except with 'git commit', so probably only 'git commit' should\nprint that message.\n\n> The return value, NULL, should be indication enough for the callers\n> to handle the situation suitable.\n\nGood idea.\n\n> In particular, launch_editor()\n> wants to write this big warning, but 'git var -l' can avoid the\n> error message and write only a short notice:\n> \n> GIT_EDITOR=terminal is dumb, but VISUAL and EDITOR unset\n\nMaybe 'git var -l' should omit GIT_EDITOR in this situation.\n\nThanks for the comments,\nJonathan\n"},{"id":"126453","messageId":"7vhbtgfpy8.fsf@alter.siamese.dyndns.org","threadId":"21405","inReplyTo":"20091030103925.GI1610@progeny.tock","subject":"Re: [PATCH 8/8] Provide a build time default-pager setting","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-30T22:59:43Z","receivedAt":"2009-10-30T22:59:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"I'll queue these for now probably on 'pu', but with the comments we saw on\nthe list expect them to be followed up with replacement patches.\n\nThanks.\n"},{"id":"126457","messageId":"20091031000118.GA16618@progeny.tock","threadId":"21405","inReplyTo":"7vvdhwfqon.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 3/8] Teach git var about GIT_EDITOR","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-31T00:01:18Z","receivedAt":"2009-10-31T00:01:18Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Junio C Hamano wrote:\n> Jonathan Nieder <jrnieder@gmail.com> writes:\n>\n>> I am a bit uncomfortable with this error in general.  It makes some\n>> sense to refuse to use $VISUAL and fall back to $EDITOR if TERM=dumb,\n>> since without this the distinction between VISUAL and EDITOR is not\n>> very useful.\n>\n> More importantly, that is what people traditionally expected from VISUAL\n> and EDITOR and we do that only to follow suit.\n\nUnfortunately, we don’t do that: we currently still use $VISUAL if\nTERM=dumb and just refuse to fall back to vi in that case.  I’ll add a\npatch to fix this.\n\n> There is no such tradition for GIT_EDITOR nor core.editor\n\nMakes sense.\n\nJonathan\n"},{"id":"126492","messageId":"20091031012050.GA5160@progeny.tock","threadId":"21405","inReplyTo":"20091030101634.GA1610@progeny.tock","subject":"[PATCH v3 0/8] Default pager and editor","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-31T01:20:50Z","receivedAt":"2009-10-31T01:20:50Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Junio C Hamano wrote:\n\n> I'll queue these for now probably on 'pu', but with the comments we saw on\n> the list expect them to be followed up with replacement patches.\n\nHere’s a replacement series.  It omits the longer error message when\nTERM=dumb and the git var --run experiment because I was not happy\nwith where either of those were going.\n\nThanks for all the comments, everyone.\n\nJohannes Sixt (1):\n  Teach git var about GIT_EDITOR\n\nJonathan Nieder (6):\n  Handle more shell metacharacters in editor names\n  Do not use VISUAL editor on dumb terminals\n  Teach git var about GIT_PAGER\n  add -i, send-email, svn, p4, etc: use \"git var GIT_EDITOR\"\n  am -i, git-svn: use \"git var GIT_PAGER\"\n  Provide a build time default-editor setting\n\nJunio C Hamano (1):\n  Provide a build time default-pager setting\n\n Documentation/config.txt         |    4 +---\n Documentation/git-commit.txt     |    2 +-\n Documentation/git-send-email.txt |    4 ++--\n Documentation/git-var.txt        |   14 ++++++++++++++\n Makefile                         |   28 ++++++++++++++++++++++++++++\n cache.h                          |    2 ++\n contrib/fast-import/git-p4       |    5 +----\n editor.c                         |   32 +++++++++++++++++++++++---------\n git-add--interactive.perl        |    3 +--\n git-am.sh                        |    5 ++++-\n git-send-email.perl              |    3 ++-\n git-sh-setup.sh                  |   19 ++++++-------------\n git-svn.perl                     |   11 ++++-------\n pager.c                          |   24 ++++++++++++++++++++----\n t/t7005-editor.sh                |   31 ++++++++++++++++++++++++-------\n var.c                            |   31 ++++++++++++++++++++++++++++++-\n 16 files changed, 163 insertions(+), 55 deletions(-)\n"},{"id":"126493","messageId":"20091031012404.GB5160@progeny.tock","threadId":"21405","inReplyTo":"20091031012050.GA5160@progeny.tock","subject":"[PATCH 1/8] Handle more shell metacharacters in editor names","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-31T01:24:04Z","receivedAt":"2009-10-31T01:24:04Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Pass the editor name to the shell if it contains any susv3 shell\nspecial character (globs, redirections, variable substitutions,\nescapes, etc).  This way, the meaning of some characters will not\nmeaninglessly change when others are added, and git commands\nimplemented in C and in shell scripts will interpret editor names\nin the same way.\n\nThis does not make the GIT_EDITOR setting any more expressive,\nsince one could always use single quotes to force the editor to\nbe passed to the shell.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\nUnchanged from v2.\n\n editor.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/editor.c b/editor.c\nindex 4d469d0..941c0b2 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -28,7 +28,7 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en\n \t\tconst char *args[6];\n \t\tstruct strbuf arg0 = STRBUF_INIT;\n \n-\t\tif (strcspn(editor, \"$ \\t'\") != len) {\n+\t\tif (strcspn(editor, \"|&;<>()$`\\\\\\\"' \\t\\n*?[#~=%\") != len) {\n \t\t\t/* there are specials */\n \t\t\tstrbuf_addf(&arg0, \"%s \\\"$@\\\"\", editor);\n \t\t\targs[i++] = \"sh\";\n-- \n1.6.5.2\n"},{"id":"126494","messageId":"20091031013039.GC5160@progeny.tock","threadId":"21405","inReplyTo":"20091031012050.GA5160@progeny.tock","subject":"[PATCH 2/8] Do not use VISUAL editor on dumb terminals","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-31T01:30:39Z","receivedAt":"2009-10-31T01:30:39Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Refuse to use $VISUAL and fall back to $EDITOR if TERM is unset\nor set to \"dumb\".  Traditionally, VISUAL is set to a screen\neditor and EDITOR to a line-based editor, which should be more\nuseful in that situation.\n\nvim, for example, is happy to assume a terminal supports ANSI\nsequences even if TERM is dumb (e.g., when running from a text\neditor like Acme).  git already refuses to fall back to vi on a\ndumb terminal if GIT_EDITOR, core.editor, VISUAL, and EDITOR are\nunset, but without this patch, that check is suppressed by\nVISUAL=vi.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\nThis patch eases my discomfort about the error message a little.  It\nis not actually needed to support any ways of working I engage in.\n\nIf stdout is redirected, this is probably still making the wrong\nchoice; isatty(STDOUT_FILENO) might be a more useful datum to use.\nBut it does not seem worth complicating the logic further.\n\n editor.c |   12 ++++++------\n 1 files changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/editor.c b/editor.c\nindex 941c0b2..3f13751 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -4,19 +4,19 @@\n \n int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)\n {\n-\tconst char *editor, *terminal;\n+\tconst char *editor = getenv(\"GIT_EDITOR\");\n+\tconst char *terminal = getenv(\"TERM\");\n+\tint terminal_is_dumb = !terminal || !strcmp(terminal, \"dumb\");\n \n-\teditor = getenv(\"GIT_EDITOR\");\n \tif (!editor && editor_program)\n \t\teditor = editor_program;\n-\tif (!editor)\n+\tif (!editor && !terminal_is_dumb)\n \t\teditor = getenv(\"VISUAL\");\n \tif (!editor)\n \t\teditor = getenv(\"EDITOR\");\n \n-\tterminal = getenv(\"TERM\");\n-\tif (!editor && (!terminal || !strcmp(terminal, \"dumb\")))\n-\t\treturn error(\"Terminal is dumb but no VISUAL nor EDITOR defined.\");\n+\tif (!editor && terminal_is_dumb)\n+\t\treturn error(\"terminal is dumb, but EDITOR unset\");\n \n \tif (!editor)\n \t\teditor = \"vi\";\n-- \n1.6.5.2\n"},{"id":"126495","messageId":"20091031013934.GD5160@progeny.tock","threadId":"21405","inReplyTo":"20091031012050.GA5160@progeny.tock","subject":"[PATCH v2 3/8] Teach git var about GIT_EDITOR","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-31T01:39:34Z","receivedAt":"2009-10-31T01:39:34Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"From: Johannes Sixt <j6t@kdbg.org>\n\nExpose the command used by launch_editor() for scripts to use.\nThis should allow one to avoid searching for a proper editor\nseparately in each command.\n\nIf no satisfactory GIT_EDITOR could be chosen, let \"git var -l\"\noutput a warning.  This warning goes to stderr so as not to\nconfuse scripts.  Example:\n\n\tcore.logallrefupdates=true\n\n\t*** Please tell me who you are.\n\n\tRun\n\n\t  git config --global user.email \"you@example.com\"\n\t  git config --global user.name \"Your Name\"\n\n\tto set your account's default identity.\n\tOmit --global to set the identity only in this repository.\n\n\tGIT_COMMITTER_IDENT=user <user@domain> 1256952739 -0500\n\tGIT_AUTHOR_IDENT=user <user@domain> 1256952739 -0500\n\twarning: GIT_EDITOR: terminal is dumb, but EDITOR unset\n\nSigned-off-by: Johannes Sixt <j6t@kdbg.org>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n\n Documentation/git-var.txt |    8 ++++++++\n cache.h                   |    1 +\n editor.c                  |   14 ++++++++++++--\n var.c                     |   21 ++++++++++++++++++++-\n 4 files changed, 41 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-var.txt b/Documentation/git-var.txt\nindex e2f4c09..89e4b4f 100644\n--- a/Documentation/git-var.txt\n+++ b/Documentation/git-var.txt\n@@ -36,6 +36,14 @@ GIT_AUTHOR_IDENT::\n GIT_COMMITTER_IDENT::\n     The person who put a piece of code into git.\n \n+GIT_EDITOR::\n+    Text editor for use by git commands.  The value is meant to be\n+    interpreted by the shell when it is used.  Examples: `~/bin/vi`,\n+    `$SOME_ENVIRONMENT_VARIABLE`, `\"C:\\Program Files\\Vim\\gvim.exe\"\n+    --nofork`.  The order of preference is the `$GIT_EDITOR`\n+    environment variable, then `core.editor` configuration, then\n+    `$VISUAL`, then `$EDITOR`, and then finally 'vi'.\n+\n Diagnostics\n -----------\n You don't exist. Go away!::\ndiff --git a/cache.h b/cache.h\nindex 96840c7..311cfe1 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -750,6 +750,7 @@ extern const char *git_author_info(int);\n extern const char *git_committer_info(int);\n extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int);\n extern const char *fmt_name(const char *name, const char *email);\n+extern const char *git_editor(void);\n \n struct checkout {\n \tconst char *base_dir;\ndiff --git a/editor.c b/editor.c\nindex 3f13751..4f98b72 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -2,7 +2,7 @@\n #include \"strbuf.h\"\n #include \"run-command.h\"\n \n-int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)\n+const char *git_editor(void)\n {\n \tconst char *editor = getenv(\"GIT_EDITOR\");\n \tconst char *terminal = getenv(\"TERM\");\n@@ -16,11 +16,21 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en\n \t\teditor = getenv(\"EDITOR\");\n \n \tif (!editor && terminal_is_dumb)\n-\t\treturn error(\"terminal is dumb, but EDITOR unset\");\n+\t\treturn NULL;\n \n \tif (!editor)\n \t\teditor = \"vi\";\n \n+\treturn editor;\n+}\n+\n+int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)\n+{\n+\tconst char *editor = git_editor();\n+\n+\tif (!editor)\n+\t\treturn error(\"terminal is dumb, but EDITOR unset\");\n+\n \tif (strcmp(editor, \":\")) {\n \t\tsize_t len = strlen(editor);\n \t\tint i = 0;\ndiff --git a/var.c b/var.c\nindex 125c0d1..399f409 100644\n--- a/var.c\n+++ b/var.c\n@@ -8,6 +8,21 @@\n \n static const char var_usage[] = \"git var [-l | <variable>]\";\n \n+static const char *editor(int flag)\n+{\n+\tconst char *pgm = git_editor();\n+\n+\tif (!pgm) {\n+\t\tif (flag & IDENT_ERROR_ON_NO_NAME)\n+\t\t\tdie(\"terminal is dumb, but EDITOR unset\");\n+\t\tif (flag & IDENT_WARN_ON_NO_NAME)\n+\t\t\twarning(\"GIT_EDITOR: terminal is dumb, \"\n+\t\t\t\t\"but EDITOR unset\");\n+\t}\n+\n+\treturn pgm;\n+}\n+\n struct git_var {\n \tconst char *name;\n \tconst char *(*read)(int);\n@@ -15,14 +30,18 @@ struct git_var {\n static struct git_var git_vars[] = {\n \t{ \"GIT_COMMITTER_IDENT\", git_committer_info },\n \t{ \"GIT_AUTHOR_IDENT\",   git_author_info },\n+\t{ \"GIT_EDITOR\", editor },\n \t{ \"\", NULL },\n };\n \n static void list_vars(void)\n {\n \tstruct git_var *ptr;\n+\tconst char *val;\n+\n \tfor (ptr = git_vars; ptr->read; ptr++)\n-\t\tprintf(\"%s=%s\\n\", ptr->name, ptr->read(IDENT_WARN_ON_NO_NAME));\n+\t\tif ((val = ptr->read(IDENT_WARN_ON_NO_NAME)))\n+\t\t\tprintf(\"%s=%s\\n\", ptr->name, val);\n }\n \n static const char *read_var(const char *var)\n-- \n1.6.5.2\n"},{"id":"126496","messageId":"20091031014127.GE5160@progeny.tock","threadId":"21405","inReplyTo":"20091031012050.GA5160@progeny.tock","subject":"[PATCH 4/8] Teach git var about GIT_PAGER","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-31T01:41:27Z","receivedAt":"2009-10-31T01:41:27Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Expose the command found by setup_pager() for scripts to use.\nScripts can use this to avoid repeating the logic to look for a\nproper pager in each command.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\nNo changes from the last version sent.\n\n Documentation/git-var.txt |    6 ++++++\n cache.h                   |    1 +\n pager.c                   |   18 +++++++++++++++---\n var.c                     |   10 ++++++++++\n 4 files changed, 32 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-var.txt b/Documentation/git-var.txt\nindex 89e4b4f..ef6aa81 100644\n--- a/Documentation/git-var.txt\n+++ b/Documentation/git-var.txt\n@@ -44,6 +44,12 @@ GIT_EDITOR::\n     environment variable, then `core.editor` configuration, then\n     `$VISUAL`, then `$EDITOR`, and then finally 'vi'.\n \n+GIT_PAGER::\n+    Text viewer for use by git commands (e.g., 'less').  The value\n+    is meant to be interpreted by the shell.  The order of preference\n+    is the `$GIT_PAGER` environment variable, then `core.pager`\n+    configuration, then `$PAGER`, and then finally 'less'.\n+\n Diagnostics\n -----------\n You don't exist. Go away!::\ndiff --git a/cache.h b/cache.h\nindex 311cfe1..5aaa4ba 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -751,6 +751,7 @@ extern const char *git_committer_info(int);\n extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int);\n extern const char *fmt_name(const char *name, const char *email);\n extern const char *git_editor(void);\n+extern const char *git_pager(void);\n \n struct checkout {\n \tconst char *base_dir;\ndiff --git a/pager.c b/pager.c\nindex 86facec..0b63d99 100644\n--- a/pager.c\n+++ b/pager.c\n@@ -44,12 +44,14 @@ static void wait_for_pager_signal(int signo)\n \traise(signo);\n }\n \n-void setup_pager(void)\n+const char *git_pager(void)\n {\n-\tconst char *pager = getenv(\"GIT_PAGER\");\n+\tconst char *pager;\n \n \tif (!isatty(1))\n-\t\treturn;\n+\t\treturn NULL;\n+\n+\tpager = getenv(\"GIT_PAGER\");\n \tif (!pager) {\n \t\tif (!pager_program)\n \t\t\tgit_config(git_default_config, NULL);\n@@ -60,6 +62,16 @@ void setup_pager(void)\n \tif (!pager)\n \t\tpager = \"less\";\n \telse if (!*pager || !strcmp(pager, \"cat\"))\n+\t\tpager = NULL;\n+\n+\treturn pager;\n+}\n+\n+void setup_pager(void)\n+{\n+\tconst char *pager = git_pager();\n+\n+\tif (!pager)\n \t\treturn;\n \n \tspawned_pager = 1; /* means we are emitting to terminal */\ndiff --git a/var.c b/var.c\nindex 399f409..facec11 100644\n--- a/var.c\n+++ b/var.c\n@@ -23,6 +23,15 @@ static const char *editor(int flag)\n \treturn pgm;\n }\n \n+static const char *pager(int flag)\n+{\n+\tconst char *pgm = git_pager();\n+\n+\tif (!pgm)\n+\t\tpgm = \"cat\";\n+\treturn pgm;\n+}\n+\n struct git_var {\n \tconst char *name;\n \tconst char *(*read)(int);\n@@ -31,6 +40,7 @@ static struct git_var git_vars[] = {\n \t{ \"GIT_COMMITTER_IDENT\", git_committer_info },\n \t{ \"GIT_AUTHOR_IDENT\",   git_author_info },\n \t{ \"GIT_EDITOR\", editor },\n+\t{ \"GIT_PAGER\", pager },\n \t{ \"\", NULL },\n };\n \n-- \n1.6.5.2\n"},{"id":"126497","messageId":"20091031014234.GF5160@progeny.tock","threadId":"21405","inReplyTo":"20091031012050.GA5160@progeny.tock","subject":"[PATCH 5/8] add -i, send-email, svn, p4, etc: use \"git var GIT_EDITOR\"","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-31T01:42:34Z","receivedAt":"2009-10-31T01:42:34Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Use the new \"git var GIT_EDITOR\" feature to decide what editor to\nuse, instead of duplicating its logic elsewhere.  This should make\nthe behavior of commands in edge cases (e.g., editor names with\nspaces) a little more consistent.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n Documentation/config.txt         |    4 +---\n Documentation/git-commit.txt     |    2 +-\n Documentation/git-send-email.txt |    4 ++--\n contrib/fast-import/git-p4       |    5 +----\n git-add--interactive.perl        |    3 +--\n git-send-email.perl              |    3 ++-\n git-sh-setup.sh                  |   19 ++++++-------------\n git-svn.perl                     |    5 ++---\n 8 files changed, 16 insertions(+), 29 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex d1e2120..5181b77 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -387,9 +387,7 @@ core.editor::\n \tCommands such as `commit` and `tag` that lets you edit\n \tmessages by launching an editor uses the value of this\n \tvariable when it is set, and the environment variable\n-\t`GIT_EDITOR` is not set.  The order of preference is\n-\t`GIT_EDITOR` environment, `core.editor`, `VISUAL` and\n-\t`EDITOR` environment variables and then finally `vi`.\n+\t`GIT_EDITOR` is not set.  See linkgit:git-var[1].\n \n core.pager::\n \tThe command that git will use to paginate output.  Can\ndiff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt\nindex 0578a40..3ea80c8 100644\n--- a/Documentation/git-commit.txt\n+++ b/Documentation/git-commit.txt\n@@ -323,7 +323,7 @@ ENVIRONMENT AND CONFIGURATION VARIABLES\n The editor used to edit the commit log message will be chosen from the\n GIT_EDITOR environment variable, the core.editor configuration variable, the\n VISUAL environment variable, or the EDITOR environment variable (in that\n-order).\n+order).  See linkgit:git-var[1] for details.\n \n HOOKS\n -----\ndiff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt\nindex 767cf4d..c85d7f4 100644\n--- a/Documentation/git-send-email.txt\n+++ b/Documentation/git-send-email.txt\n@@ -60,8 +60,8 @@ The --bcc option must be repeated for each user you want on the bcc list.\n The --cc option must be repeated for each user you want on the cc list.\n \n --compose::\n-\tUse $GIT_EDITOR, core.editor, $VISUAL, or $EDITOR to edit an\n-\tintroductory message for the patch series.\n+\tInvoke a text editor (see GIT_EDITOR in linkgit:git-var[1])\n+\tto edit an introductory message for the patch series.\n +\n When '--compose' is used, git send-email will use the From, Subject, and\n In-Reply-To headers specified in the message. If the body of the message\ndiff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4\nindex e710219..48059d0 100755\n--- a/contrib/fast-import/git-p4\n+++ b/contrib/fast-import/git-p4\n@@ -729,13 +729,10 @@ class P4Submit(Command):\n             tmpFile.write(submitTemplate + separatorLine + diff + newdiff)\n             tmpFile.close()\n             mtime = os.stat(fileName).st_mtime\n-            defaultEditor = \"vi\"\n-            if platform.system() == \"Windows\":\n-                defaultEditor = \"notepad\"\n             if os.environ.has_key(\"P4EDITOR\"):\n                 editor = os.environ.get(\"P4EDITOR\")\n             else:\n-                editor = os.environ.get(\"EDITOR\", defaultEditor);\n+                editor = read_pipe(\"git var GIT_EDITOR\")\n             system(editor + \" \" + fileName)\n \n             response = \"y\"\ndiff --git a/git-add--interactive.perl b/git-add--interactive.perl\nindex 69aeaf0..0c74e5c 100755\n--- a/git-add--interactive.perl\n+++ b/git-add--interactive.perl\n@@ -987,8 +987,7 @@ sub edit_hunk_manually {\n EOF\n \tclose $fh;\n \n-\tmy $editor = $ENV{GIT_EDITOR} || $repo->config(\"core.editor\")\n-\t\t|| $ENV{VISUAL} || $ENV{EDITOR} || \"vi\";\n+\tchomp(my $editor = run_cmd_pipe(qw(git var GIT_EDITOR)));\n \tsystem('sh', '-c', $editor.' \"$@\"', $editor, $hunkfile);\n \n \tif ($? != 0) {\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex a0279de..4f5da4e 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -162,7 +162,8 @@ my $compose_filename;\n \n # Handle interactive edition of files.\n my $multiedit;\n-my $editor = $ENV{GIT_EDITOR} || Git::config(@repo, \"core.editor\") || $ENV{VISUAL} || $ENV{EDITOR} || \"vi\";\n+my $editor = Git::command_oneline('var', 'GIT_EDITOR');\n+\n sub do_edit {\n \tif (defined($multiedit) && !$multiedit) {\n \t\tmap {\ndiff --git a/git-sh-setup.sh b/git-sh-setup.sh\nindex c41c2f7..99cceeb 100755\n--- a/git-sh-setup.sh\n+++ b/git-sh-setup.sh\n@@ -99,19 +99,12 @@ set_reflog_action() {\n }\n \n git_editor() {\n-\t: \"${GIT_EDITOR:=$(git config core.editor)}\"\n-\t: \"${GIT_EDITOR:=${VISUAL:-${EDITOR}}}\"\n-\tcase \"$GIT_EDITOR,$TERM\" in\n-\t,dumb)\n-\t\techo >&2 \"No editor specified in GIT_EDITOR, core.editor, VISUAL,\"\n-\t\techo >&2 \"or EDITOR. Tried to fall back to vi but terminal is dumb.\"\n-\t\techo >&2 \"Please set one of these variables to an appropriate\"\n-\t\techo >&2 \"editor or run $0 with options that will not cause an\"\n-\t\techo >&2 \"editor to be invoked (e.g., -m or -F for git-commit).\"\n-\t\texit 1\n-\t\t;;\n-\tesac\n-\teval \"${GIT_EDITOR:=vi}\" '\"$@\"'\n+\tif test -z \"${GIT_EDITOR:+set}\"\n+\tthen\n+\t\tGIT_EDITOR=\"$(git var GIT_EDITOR)\" || return $?\n+\tfi\n+\n+\teval \"$GIT_EDITOR\" '\"$@\"'\n }\n \n is_bare_repository () {\ndiff --git a/git-svn.perl b/git-svn.perl\nindex 6a3b501..42c9a72 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -1321,9 +1321,8 @@ sub get_commit_entry {\n \tclose $log_fh or croak $!;\n \n \tif ($_edit || ($type eq 'tree')) {\n-\t\tmy $editor = $ENV{VISUAL} || $ENV{EDITOR} || 'vi';\n-\t\t# TODO: strip out spaces, comments, like git-commit.sh\n-\t\tsystem($editor, $commit_editmsg);\n+\t\tchomp(my $editor = command_oneline(qw(var GIT_EDITOR)));\n+\t\tsystem('sh', '-c', $editor.' \"$@\"', $editor, $commit_editmsg);\n \t}\n \trename $commit_editmsg, $commit_msg or croak $!;\n \t{\n-- \n1.6.5.2\n"},{"id":"126498","messageId":"20091031014319.GG5160@progeny.tock","threadId":"21405","inReplyTo":"20091031012050.GA5160@progeny.tock","subject":"[PATCH 6/8] am -i, git-svn: use \"git var GIT_PAGER\"","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-31T01:43:19Z","receivedAt":"2009-10-31T01:43:19Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Use the new \"git var GIT_PAGER\" command to ask what pager to use.\n\nWithout this change, the core.pager configuration is ignored by\nthese commands.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n git-am.sh    |    5 ++++-\n git-svn.perl |    6 ++----\n 2 files changed, 6 insertions(+), 5 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex c132f50..2649487 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -649,7 +649,10 @@ do\n \t\t[eE]*) git_editor \"$dotest/final-commit\"\n \t\t       action=again ;;\n \t\t[vV]*) action=again\n-\t\t       LESS=-S ${PAGER:-less} \"$dotest/patch\" ;;\n+\t\t       : ${GIT_PAGER=$(git var GIT_PAGER)}\n+\t\t       : ${LESS=-FRSX}\n+\t\t       export LESS\n+\t\t       $GIT_PAGER \"$dotest/patch\" ;;\n \t\t*)     action=again ;;\n \t\tesac\n \t    done\ndiff --git a/git-svn.perl b/git-svn.perl\nindex 42c9a72..c4ca548 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -5171,10 +5171,8 @@ sub git_svn_log_cmd {\n \n # adapted from pager.c\n sub config_pager {\n-\t$pager ||= $ENV{GIT_PAGER} || $ENV{PAGER};\n-\tif (!defined $pager) {\n-\t\t$pager = 'less';\n-\t} elsif (length $pager == 0 || $pager eq 'cat') {\n+\tchomp(my $pager = command_oneline(qw(var GIT_PAGER)));\n+\tif ($pager eq 'cat') {\n \t\t$pager = undef;\n \t}\n \t$ENV{GIT_PAGER_IN_USE} = defined($pager);\n-- \n1.6.5.2\n"},{"id":"126499","messageId":"20091031014441.GH5160@progeny.tock","threadId":"21405","inReplyTo":"20091031012050.GA5160@progeny.tock","subject":"[PATCH 7/8] Provide a build time default-editor setting","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-31T01:44:41Z","receivedAt":"2009-10-31T01:44:41Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Provide a DEFAULT_EDITOR knob to allow setting the fallback\neditor to use instead of vi (when VISUAL, EDITOR, and GIT_EDITOR\nare unset).  The value can be set at build time according to a\nsystem’s policy.  For example, on Debian systems, the default\neditor should be the 'editor' command.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Ben Walton <bwalton@artsci.utoronto.ca>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n Makefile          |   17 +++++++++++++++++\n editor.c          |    6 +++++-\n t/t7005-editor.sh |   31 ++++++++++++++++++++++++-------\n 3 files changed, 46 insertions(+), 8 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 268aede..625866c 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -200,6 +200,14 @@ all::\n # memory allocators with the nedmalloc allocator written by Niall Douglas.\n #\n # Define NO_REGEX if you have no or inferior regex support in your C library.\n+#\n+# Define DEFAULT_EDITOR to a sensible editor command (defaults to \"vi\") if you\n+# want to use something different.  The value will be interpreted by the shell\n+# if necessary when it is used.  Examples:\n+#\n+#   DEFAULT_EDITOR='~/bin/vi',\n+#   DEFAULT_EDITOR='$GIT_FALLBACK_EDITOR',\n+#   DEFAULT_EDITOR='\"C:\\Program Files\\Vim\\gvim.exe\" --nofork'\n \n GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE\n \t@$(SHELL_PATH) ./GIT-VERSION-GEN\n@@ -1363,6 +1371,15 @@ BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' \\\n \t$(COMPAT_CFLAGS)\n LIB_OBJS += $(COMPAT_OBJS)\n \n+# Quote for C\n+\n+ifdef DEFAULT_EDITOR\n+DEFAULT_EDITOR_CQ = \"$(subst \",\\\",$(subst \\,\\\\,$(DEFAULT_EDITOR)))\"\n+DEFAULT_EDITOR_CQ_SQ = $(subst ','\\'',$(DEFAULT_EDITOR_CQ))\n+\n+BASIC_CFLAGS += -DDEFAULT_EDITOR='$(DEFAULT_EDITOR_CQ_SQ)'\n+endif\n+\n ALL_CFLAGS += $(BASIC_CFLAGS)\n ALL_LDFLAGS += $(BASIC_LDFLAGS)\n \ndiff --git a/editor.c b/editor.c\nindex 4f98b72..2aac807 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -2,6 +2,10 @@\n #include \"strbuf.h\"\n #include \"run-command.h\"\n \n+#ifndef DEFAULT_EDITOR\n+#define DEFAULT_EDITOR \"vi\"\n+#endif\n+\n const char *git_editor(void)\n {\n \tconst char *editor = getenv(\"GIT_EDITOR\");\n@@ -19,7 +23,7 @@ const char *git_editor(void)\n \t\treturn NULL;\n \n \tif (!editor)\n-\t\teditor = \"vi\";\n+\t\teditor = DEFAULT_EDITOR;\n \n \treturn editor;\n }\ndiff --git a/t/t7005-editor.sh b/t/t7005-editor.sh\nindex b647957..73ba44c 100755\n--- a/t/t7005-editor.sh\n+++ b/t/t7005-editor.sh\n@@ -4,7 +4,26 @@ test_description='GIT_EDITOR, core.editor, and stuff'\n \n . ./test-lib.sh\n \n-for i in GIT_EDITOR core_editor EDITOR VISUAL vi\n+unset EDITOR VISUAL GIT_EDITOR\n+\n+test_expect_success 'does editor have a simple name (no slashes, etc)?' '\n+\n+\teditor=$(TERM=vt100 git var GIT_EDITOR) &&\n+\ttest -n \"$editor\" &&\n+\tsimple=t &&\n+\tcase \"$editor\" in\n+\t*/* | core_editor | [A-Z]*)\n+\t\tunset simple;;\n+\tesac\n+\n+'\n+if test -z \"${simple+set}\"\n+then\n+\tsay 'skipping editor tests, default editor is not sought on PATH'\n+\ttest_done\n+fi\n+\n+for i in GIT_EDITOR core_editor EDITOR VISUAL \"$editor\"\n do\n \tcat >e-$i.sh <<-EOF\n \t#!$SHELL_PATH\n@@ -12,15 +31,13 @@ do\n \tEOF\n \tchmod +x e-$i.sh\n done\n-unset vi\n-mv e-vi.sh vi\n-unset EDITOR VISUAL GIT_EDITOR\n+mv \"e-$editor.sh\" \"$editor\"\n \n test_expect_success setup '\n \n \tmsg=\"Hand edited\" &&\n \techo \"$msg\" >expect &&\n-\tgit add vi &&\n+\tgit add \"$editor\" &&\n \ttest_tick &&\n \tgit commit -m \"$msg\" &&\n \tgit show -s --pretty=oneline |\n@@ -44,7 +61,7 @@ test_expect_success 'dumb should error out when falling back on vi' '\n \n TERM=vt100\n export TERM\n-for i in vi EDITOR VISUAL core_editor GIT_EDITOR\n+for i in \"$editor\" EDITOR VISUAL core_editor GIT_EDITOR\n do\n \techo \"Edited by $i\" >expect\n \tunset EDITOR VISUAL GIT_EDITOR\n@@ -68,7 +85,7 @@ done\n \n unset EDITOR VISUAL GIT_EDITOR\n git config --unset-all core.editor\n-for i in vi EDITOR VISUAL core_editor GIT_EDITOR\n+for i in \"$editor\" EDITOR VISUAL core_editor GIT_EDITOR\n do\n \techo \"Edited by $i\" >expect\n \tcase \"$i\" in\n-- \n1.6.5.2\n"},{"id":"126500","messageId":"20091031014534.GI5160@progeny.tock","threadId":"21405","inReplyTo":"20091031012050.GA5160@progeny.tock","subject":"[PATCH 8/8] Provide a build time default-pager setting","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-31T01:45:34Z","receivedAt":"2009-10-31T01:45:34Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"From: Junio C Hamano <gitster@pobox.com>\n\nProvide a DEFAULT_PAGER knob so packagers can set the fallback\npager to something appropriate during the build.\n\nExamples:\n\nOn (old) solaris systems, /usr/bin/less (typically the first less\nfound) doesn't understand the default arguments (FXRS), which\nforces users to alter their environment (PATH, GIT_PAGER, LESS,\netc) or have a local or global gitconfig before paging works as\nexpected.\n\nOn Debian systems, by policy packages must fall back to the\n'pager' command, so that changing the target of the\n/usr/bin/pager symlink changes the default pager for all packages\nat once.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Ben Walton <bwalton@artsci.utoronto.ca>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n Makefile |   11 +++++++++++\n pager.c  |    6 +++++-\n 2 files changed, 16 insertions(+), 1 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 625866c..18fc50a 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -201,6 +201,10 @@ all::\n #\n # Define NO_REGEX if you have no or inferior regex support in your C library.\n #\n+# Define DEFAULT_PAGER to a sensible pager command (defaults to \"less\") if\n+# you want to use something different.  The value will be interpreted by the\n+# shell at runtime when it is used.\n+#\n # Define DEFAULT_EDITOR to a sensible editor command (defaults to \"vi\") if you\n # want to use something different.  The value will be interpreted by the shell\n # if necessary when it is used.  Examples:\n@@ -1380,6 +1384,13 @@ DEFAULT_EDITOR_CQ_SQ = $(subst ','\\'',$(DEFAULT_EDITOR_CQ))\n BASIC_CFLAGS += -DDEFAULT_EDITOR='$(DEFAULT_EDITOR_CQ_SQ)'\n endif\n \n+ifdef DEFAULT_PAGER\n+DEFAULT_PAGER_CQ = \"$(subst \",\\\",$(subst \\,\\\\,$(DEFAULT_PAGER)))\"\n+DEFAULT_PAGER_CQ_SQ = $(subst ','\\'',$(DEFAULT_PAGER_CQ))\n+\n+BASIC_CFLAGS += -DDEFAULT_PAGER='$(DEFAULT_PAGER_CQ_SQ)'\n+endif\n+\n ALL_CFLAGS += $(BASIC_CFLAGS)\n ALL_LDFLAGS += $(BASIC_LDFLAGS)\n \ndiff --git a/pager.c b/pager.c\nindex 0b63d99..92c03f6 100644\n--- a/pager.c\n+++ b/pager.c\n@@ -2,6 +2,10 @@\n #include \"run-command.h\"\n #include \"sigchain.h\"\n \n+#ifndef DEFAULT_PAGER\n+#define DEFAULT_PAGER \"less\"\n+#endif\n+\n /*\n  * This is split up from the rest of git so that we can do\n  * something different on Windows.\n@@ -60,7 +64,7 @@ const char *git_pager(void)\n \tif (!pager)\n \t\tpager = getenv(\"PAGER\");\n \tif (!pager)\n-\t\tpager = \"less\";\n+\t\tpager = DEFAULT_PAGER;\n \telse if (!*pager || !strcmp(pager, \"cat\"))\n \t\tpager = NULL;\n \n-- \n1.6.5.2\n"},{"id":"126502","messageId":"7vk4yccodl.fsf@alter.siamese.dyndns.org","threadId":"21405","inReplyTo":"20091031013934.GD5160@progeny.tock","subject":"Re: [PATCH v2 3/8] Teach git var about GIT_EDITOR","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-31T02:01:58Z","receivedAt":"2009-10-31T02:01:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonathan Nieder <jrnieder@gmail.com> writes:\n\n> From: Johannes Sixt <j6t@kdbg.org>\n>\n> Expose the command used by launch_editor() for scripts to use.\n> This should allow one to avoid searching for a proper editor\n> separately in each command.\n>\n> If no satisfactory GIT_EDITOR could be chosen, let \"git var -l\"\n> output a warning.  This warning goes to stderr so as not to\n> confuse scripts.  Example:\n>\n> \tcore.logallrefupdates=true\n>\n> \t*** Please tell me who you are.\n>\n> \tRun\n>\n> \t  git config --global user.email \"you@example.com\"\n> \t  git config --global user.name \"Your Name\"\n>\n> \tto set your account's default identity.\n> \tOmit --global to set the identity only in this repository.\n>\n> \tGIT_COMMITTER_IDENT=user <user@domain> 1256952739 -0500\n> \tGIT_AUTHOR_IDENT=user <user@domain> 1256952739 -0500\n> \twarning: GIT_EDITOR: terminal is dumb, but EDITOR unset\n\nSorry, I cannot grok this example.  Is it supposed to be a transcript\nof a user session?  What did the user type?\n"},{"id":"126504","messageId":"7vfx90co1e.fsf@alter.siamese.dyndns.org","threadId":"21405","inReplyTo":"20091031014441.GH5160@progeny.tock","subject":"Re: [PATCH 7/8] Provide a build time default-editor setting","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-31T02:09:17Z","receivedAt":"2009-10-31T02:09:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonathan Nieder <jrnieder@gmail.com> writes:\n\n> +test_expect_success 'does editor have a simple name (no slashes, etc)?' '\n> +\n> +\teditor=$(TERM=vt100 git var GIT_EDITOR) &&\n> +\ttest -n \"$editor\" &&\n> +\tsimple=t &&\n> +\tcase \"$editor\" in\n> +\t*/* | core_editor | [A-Z]*)\n\nHmm, what are the latter two cases designed to catch?\n"},{"id":"126505","messageId":"20091031022347.GA5569@progeny.tock","threadId":"21405","inReplyTo":"7vk4yccodl.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v2 3/8] Teach git var about GIT_EDITOR","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-31T02:23:47Z","receivedAt":"2009-10-31T02:23:47Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Junio C Hamano wrote:\n\n>> \tcore.logallrefupdates=true\n>>\n>> \t*** Please tell me who you are.\n>>\n>> \tRun\n>>\n>> \t  git config --global user.email \"you@example.com\"\n>> \t  git config --global user.name \"Your Name\"\n>>\n>> \tto set your account's default identity.\n>> \tOmit --global to set the identity only in this repository.\n>>\n>> \tGIT_COMMITTER_IDENT=user <user@domain> 1256952739 -0500\n>> \tGIT_AUTHOR_IDENT=user <user@domain> 1256952739 -0500\n>> \twarning: GIT_EDITOR: terminal is dumb, but EDITOR unset\n> \n> Sorry, I cannot grok this example.  Is it supposed to be a transcript\n> of a user session?  What did the user type?\n\nOh, sorry about that.  The user typed 'git var -l', and that is all\noutput from that.  More realistic examples:\n\n$ # what scripts see\n$ git var -l 2>/dev/null\ngc.auto=0\nrerere.enabled\nmerge.log\nmerge.conflictstyle=diff3\ncore.repositoryformatversion=0\ncore.filemode=true\ncore.bare=false\ncore.logallrefupdates=true\nremote.origin.fetch=+refs/heads/*:refs/remotes/origin/*\nremote.origin.url=git://repo.or.cz/git\nbranch.master.remote=origin\nbranch.master.merge=refs/heads/master\nGIT_COMMITTER_IDENT=user <user@domain> 1256952739 -0500\nGIT_AUTHOR_IDENT=user <user@domain> 1256952739 -0500\n$\n$ # what scripts pass on to the user\n$ git var -l >/dev/null\n\n*** Please tell me who you are.\n\nRun\n\n  git config --global user.email \"you@example.com\"\n  git config --global user.name \"Your Name\"\n\nto set your account's default identity.\nOmit --global to set the identity only in this repository.\n\nwarning: GIT_EDITOR: terminal is dumb, but EDITOR unset\n$ \n\nAt least, that is what I was imagining (that’s one way to use git var,\nanyway).\n\nWould a more friendly message be helpful here?  I am not sure how 'git\nvar -l' gets used.  I never liked using it directly myself, mostly\nbecause the long list of configuration items can be overwhelming.\n\nJonathan\n"},{"id":"126506","messageId":"7vws2cb8bp.fsf@alter.siamese.dyndns.org","threadId":"21405","inReplyTo":"20091031022347.GA5569@progeny.tock","subject":"Re: [PATCH v2 3/8] Teach git var about GIT_EDITOR","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-31T02:34:02Z","receivedAt":"2009-10-31T02:34:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonathan Nieder <jrnieder@gmail.com> writes:\n\n> Junio C Hamano wrote:\n>\n>>> \tcore.logallrefupdates=true\n>>>\n>>> \t*** Please tell me who you are.\n>>>\n>>> \tRun\n>>>\n>>> \t  git config --global user.email \"you@example.com\"\n>>> \t  git config --global user.name \"Your Name\"\n>>>\n>>> \tto set your account's default identity.\n>>> \tOmit --global to set the identity only in this repository.\n>>>\n>>> \tGIT_COMMITTER_IDENT=user <user@domain> 1256952739 -0500\n>>> \tGIT_AUTHOR_IDENT=user <user@domain> 1256952739 -0500\n>>> \twarning: GIT_EDITOR: terminal is dumb, but EDITOR unset\n>> \n>> Sorry, I cannot grok this example.  Is it supposed to be a transcript\n>> of a user session?  What did the user type?\n>\n> Oh, sorry about that.  The user typed 'git var -l', and that is all\n> output from that.  More realistic examples:\n>\n> $ # what scripts see\n> $ git var -l 2>/dev/null\n> gc.auto=0\n> rerere.enabled\n> merge.log\n> merge.conflictstyle=diff3\n> core.repositoryformatversion=0\n> core.filemode=true\n> core.bare=false\n> core.logallrefupdates=true\n> remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*\n> remote.origin.url=git://repo.or.cz/git\n> branch.master.remote=origin\n> branch.master.merge=refs/heads/master\n> GIT_COMMITTER_IDENT=user <user@domain> 1256952739 -0500\n> GIT_AUTHOR_IDENT=user <user@domain> 1256952739 -0500\n> $\n> $ # what scripts pass on to the user\n> $ git var -l >/dev/null\n>\n> *** Please tell me who you are.\n>\n> Run\n>\n>   git config --global user.email \"you@example.com\"\n>   git config --global user.name \"Your Name\"\n>\n> to set your account's default identity.\n> Omit --global to set the identity only in this repository.\n>\n> warning: GIT_EDITOR: terminal is dumb, but EDITOR unset\n> $ \n\nThis is more readable.\n\nBut the user did not even ask for GIT_EDITOR.  Should it even mention\n\"unusable\"?  or should it just say something like\n\n\tGIT_EDITOR=\n\nwithout complaining?\n\nFor that matter, I also wonder if we can squelch the user.email one when\nwe are only listing the variables (I know it is not part of this topic,\nbut I can still wonder).\n\n> Would a more friendly message be helpful here?  I am not sure how 'git\n> var -l' gets used.  I never liked using it directly myself, mostly\n> because the long list of configuration items can be overwhelming.\n\nI think people run \"git var -l\", store the results in variables (think\nPerl or Python script) and read from there, instead of making separate\ninvocations of \"git var\" for individual variables.\n"},{"id":"126508","messageId":"20091031032647.GA5583@progeny.tock","threadId":"21405","inReplyTo":"7vfx90co1e.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 7/8] Provide a build time default-editor setting","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-31T03:26:47Z","receivedAt":"2009-10-31T03:26:47Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Junio C Hamano wrote:\n> Jonathan Nieder <jrnieder@gmail.com> writes:\n \n>> +test_expect_success 'does editor have a simple name (no slashes, etc)?' '\n>> +\n>> +\teditor=$(TERM=vt100 git var GIT_EDITOR) &&\n>> +\ttest -n \"$editor\" &&\n>> +\tsimple=t &&\n>> +\tcase \"$editor\" in\n>> +\t*/* | core_editor | [A-Z]*)\n> \n> Hmm, what are the latter two cases designed to catch?\n\nBoth are meant to allow the test to work without too many changes.\nThe core_editor case is a little pedantic, since it is unlikely to\nactually come up in practice.  With a default editor of core_editor,\nthe initial loop will overwrite e-core_editor.sh (to be used through\nthe core.editor configuration) with e-core_editor.sh (to be used as a\nfallback editor) before renaming it to core_editor.\n\nI missed some other cases: If editor is .git, e-GIT_EDITOR.sh, etc,\nthe mv will still misbehave.\n\nThe [A-Z]* test is to avoid changing the loop around line 86:\n\n| unset EDITOR VISUAL GIT_EDITOR\n| git config --unset-all core.editor\n| for i in \"$editor\" EDITOR VISUAL core_editor GIT_EDITOR\n| do\n|\techo \"Edited by $i\" >expect\n|\tcase \"$i\" in\n|\tcore_editor)\n|\t\tgit config core.editor ./e-core_editor.sh\n|\t\t;;\n|\t[A-Z]*)\n|\t\teval \"$i=./e-$i.sh\"\n|\t\texport $i\n|\t\t;;\n|\tesac\n|\ttest_expect_success \"Using $i (override)\" '\n|\t\tgit --exec-path=. commit --amend &&\n|\t\tgit show -s --pretty=oneline |\n|\t\tsed -e \"s/^[0-9a-f]* //\" >actual &&\n|\t\tdiff actual expect\n|\t'\n| done\n\nwhich I do not think is worth making more complicated.\n\nMaybe it would be better to just check for an editor consisting only\nof alphabetical characters.  Perhaps something like the following:\n\n-- %< --\nFrom: Jonathan Nieder <jrnieder@gmail.com>\nSubject: [PATCH] Provide a build time default-editor setting\n\nProvide a DEFAULT_EDITOR knob to allow setting the fallback\neditor to use instead of vi (when VISUAL, EDITOR, and GIT_EDITOR\nare unset).  The value can be set at build time according to a\nsystem’s policy.  For example, on Debian systems, the default\neditor should be the 'editor' command.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Ben Walton <bwalton@artsci.utoronto.ca>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n Makefile          |   17 +++++++++++++++++\n editor.c          |    6 +++++-\n t/t7005-editor.sh |   27 ++++++++++++++++++++-------\n 3 files changed, 42 insertions(+), 8 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 268aede..625866c 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -200,6 +200,14 @@ all::\n # memory allocators with the nedmalloc allocator written by Niall Douglas.\n #\n # Define NO_REGEX if you have no or inferior regex support in your C library.\n+#\n+# Define DEFAULT_EDITOR to a sensible editor command (defaults to \"vi\") if you\n+# want to use something different.  The value will be interpreted by the shell\n+# if necessary when it is used.  Examples:\n+#\n+#   DEFAULT_EDITOR='~/bin/vi',\n+#   DEFAULT_EDITOR='$GIT_FALLBACK_EDITOR',\n+#   DEFAULT_EDITOR='\"C:\\Program Files\\Vim\\gvim.exe\" --nofork'\n \n GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE\n \t@$(SHELL_PATH) ./GIT-VERSION-GEN\n@@ -1363,6 +1371,15 @@ BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' \\\n \t$(COMPAT_CFLAGS)\n LIB_OBJS += $(COMPAT_OBJS)\n \n+# Quote for C\n+\n+ifdef DEFAULT_EDITOR\n+DEFAULT_EDITOR_CQ = \"$(subst \",\\\",$(subst \\,\\\\,$(DEFAULT_EDITOR)))\"\n+DEFAULT_EDITOR_CQ_SQ = $(subst ','\\'',$(DEFAULT_EDITOR_CQ))\n+\n+BASIC_CFLAGS += -DDEFAULT_EDITOR='$(DEFAULT_EDITOR_CQ_SQ)'\n+endif\n+\n ALL_CFLAGS += $(BASIC_CFLAGS)\n ALL_LDFLAGS += $(BASIC_LDFLAGS)\n \ndiff --git a/editor.c b/editor.c\nindex 4f98b72..2aac807 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -2,6 +2,10 @@\n #include \"strbuf.h\"\n #include \"run-command.h\"\n \n+#ifndef DEFAULT_EDITOR\n+#define DEFAULT_EDITOR \"vi\"\n+#endif\n+\n const char *git_editor(void)\n {\n \tconst char *editor = getenv(\"GIT_EDITOR\");\n@@ -19,7 +23,7 @@ const char *git_editor(void)\n \t\treturn NULL;\n \n \tif (!editor)\n-\t\teditor = \"vi\";\n+\t\teditor = DEFAULT_EDITOR;\n \n \treturn editor;\n }\ndiff --git a/t/t7005-editor.sh b/t/t7005-editor.sh\nindex b647957..13c37de 100755\n--- a/t/t7005-editor.sh\n+++ b/t/t7005-editor.sh\n@@ -4,7 +4,22 @@ test_description='GIT_EDITOR, core.editor, and stuff'\n \n . ./test-lib.sh\n \n-for i in GIT_EDITOR core_editor EDITOR VISUAL vi\n+unset EDITOR VISUAL GIT_EDITOR\n+\n+test_expect_success 'determine default editor' '\n+\n+\teditor=$(TERM=vt100 git var GIT_EDITOR) &&\n+\ttest -n \"$editor\"\n+\n+'\n+\n+if ! test -z \"$(printf '%s\\n' \"$editor\" | sed '/^[a-z]*$/d')\"\n+then\n+\tsay 'skipping editor tests, default editor name too complicated'\n+\ttest_done\n+fi\n+\n+for i in GIT_EDITOR core_editor EDITOR VISUAL \"$editor\"\n do\n \tcat >e-$i.sh <<-EOF\n \t#!$SHELL_PATH\n@@ -12,15 +27,13 @@ do\n \tEOF\n \tchmod +x e-$i.sh\n done\n-unset vi\n-mv e-vi.sh vi\n-unset EDITOR VISUAL GIT_EDITOR\n+mv \"e-$editor.sh\" \"$editor\"\n \n test_expect_success setup '\n \n \tmsg=\"Hand edited\" &&\n \techo \"$msg\" >expect &&\n-\tgit add vi &&\n+\tgit add \"$editor\" &&\n \ttest_tick &&\n \tgit commit -m \"$msg\" &&\n \tgit show -s --pretty=oneline |\n@@ -44,7 +57,7 @@ test_expect_success 'dumb should error out when falling back on vi' '\n \n TERM=vt100\n export TERM\n-for i in vi EDITOR VISUAL core_editor GIT_EDITOR\n+for i in \"$editor\" EDITOR VISUAL core_editor GIT_EDITOR\n do\n \techo \"Edited by $i\" >expect\n \tunset EDITOR VISUAL GIT_EDITOR\n@@ -68,7 +81,7 @@ done\n \n unset EDITOR VISUAL GIT_EDITOR\n git config --unset-all core.editor\n-for i in vi EDITOR VISUAL core_editor GIT_EDITOR\n+for i in \"$editor\" EDITOR VISUAL core_editor GIT_EDITOR\n do\n \techo \"Edited by $i\" >expect\n \tcase \"$i\" in\n-- \n1.6.5.2\n"},{"id":"126509","messageId":"20091031040003.GA6022@progeny.tock","threadId":"21405","inReplyTo":"7vws2cb8bp.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v2 3/8] Teach git var about GIT_EDITOR","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-31T04:00:03Z","receivedAt":"2009-10-31T04:00:03Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Junio C Hamano wrote:\n\n> But the user did not even ask for GIT_EDITOR.  Should it even mention\n> \"unusable\"?  or should it just say something like\n> \n> \tGIT_EDITOR=\n> \n> without complaining?\n> \n> For that matter, I also wonder if we can squelch the user.email one when\n> we are only listing the variables (I know it is not part of this topic,\n> but I can still wonder).\n[...]\n> I think people run \"git var -l\", store the results in variables (think\n> Perl or Python script) and read from there, instead of making separate\n> invocations of \"git var\" for individual variables.\n\nIn that case, most variable-specific warnings should be suppressed as\nirrelevant.  So squelching the warnings makes sense.\n\nHow about this patch?  With the \"git var GIT_EDITOR\" patch applied on\ntop, \"git var -l\" silently omits the GIT_EDITOR variable when a suitable\neditor cannot be found.\n\n-- %< --\nSubject: Suppress warnings from \"git var -l\"\n\nFor scripts using \"git var -l\" to read all logical variables at\nonce, not all per-variable warnings will be relevant.  Suppress\nthem.\n\nThe git source tree does not include any scripts using \"git var\n-l\", so this change should not affect other git commands.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n ident.c |    2 +-\n var.c   |    2 +-\n 2 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/ident.c b/ident.c\nindex 99f1c85..26409b2 100644\n--- a/ident.c\n+++ b/ident.c\n@@ -205,7 +205,7 @@ const char *fmt_ident(const char *name, const char *email,\n \t\tif ((warn_on_no_name || error_on_no_name) &&\n \t\t    name == git_default_name && env_hint) {\n \t\t\tfprintf(stderr, env_hint, au_env, co_env);\n-\t\t\tenv_hint = NULL; /* warn only once, for \"git var -l\" */\n+\t\t\tenv_hint = NULL; /* warn only once */\n \t\t}\n \t\tif (error_on_no_name)\n \t\t\tdie(\"empty ident %s <%s> not allowed\", name, email);\ndiff --git a/var.c b/var.c\nindex 125c0d1..dacbaab 100644\n--- a/var.c\n+++ b/var.c\n@@ -22,7 +22,7 @@ static void list_vars(void)\n {\n \tstruct git_var *ptr;\n \tfor (ptr = git_vars; ptr->read; ptr++)\n-\t\tprintf(\"%s=%s\\n\", ptr->name, ptr->read(IDENT_WARN_ON_NO_NAME));\n+\t\tprintf(\"%s=%s\\n\", ptr->name, ptr->read(0));\n }\n \n static const char *read_var(const char *var)\n-- \n1.6.5.2\n"},{"id":"126510","messageId":"20091031040436.GB6022@progeny.tock","threadId":"21405","inReplyTo":"20091031040003.GA6022@progeny.tock","subject":"[PATCH v3] Teach git var about GIT_EDITOR","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-31T04:04:36Z","receivedAt":"2009-10-31T04:04:36Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"From: Johannes Sixt <j6t@kdbg.org>\n\nExpose the command used by launch_editor() for scripts to use.\nThis should allow one to avoid searching for a proper editor\nseparately in each command.\n\nSigned-off-by: Johannes Sixt <j6t@kdbg.org>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\nJonathan Nieder wrote:\n\n> How about this patch?  With the \"git var GIT_EDITOR\" patch applied on\n> top, \"git var -l\" silently omits the GIT_EDITOR variable when a suitable\n> editor cannot be found.\n> \n> -- %< --\n> Subject: Suppress warnings from \"git var -l\"\n> \n> For scripts using \"git var -l\" to read all logical variables at\n> once, not all per-variable warnings will be relevant.  Suppress\n> them.\n\nHere’s the \"git var GIT_EDITOR\" patch again, rebased on top of the\naforementioned patch.  The rest of the series should apply without\nchanges.\n\n Documentation/git-var.txt |    8 ++++++++\n cache.h                   |    1 +\n editor.c                  |   14 ++++++++++++--\n var.c                     |   16 +++++++++++++++-\n 4 files changed, 36 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-var.txt b/Documentation/git-var.txt\nindex e2f4c09..89e4b4f 100644\n--- a/Documentation/git-var.txt\n+++ b/Documentation/git-var.txt\n@@ -36,6 +36,14 @@ GIT_AUTHOR_IDENT::\n GIT_COMMITTER_IDENT::\n     The person who put a piece of code into git.\n \n+GIT_EDITOR::\n+    Text editor for use by git commands.  The value is meant to be\n+    interpreted by the shell when it is used.  Examples: `~/bin/vi`,\n+    `$SOME_ENVIRONMENT_VARIABLE`, `\"C:\\Program Files\\Vim\\gvim.exe\"\n+    --nofork`.  The order of preference is the `$GIT_EDITOR`\n+    environment variable, then `core.editor` configuration, then\n+    `$VISUAL`, then `$EDITOR`, and then finally 'vi'.\n+\n Diagnostics\n -----------\n You don't exist. Go away!::\ndiff --git a/cache.h b/cache.h\nindex 96840c7..311cfe1 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -750,6 +750,7 @@ extern const char *git_author_info(int);\n extern const char *git_committer_info(int);\n extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int);\n extern const char *fmt_name(const char *name, const char *email);\n+extern const char *git_editor(void);\n \n struct checkout {\n \tconst char *base_dir;\ndiff --git a/editor.c b/editor.c\nindex 3f13751..4f98b72 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -2,7 +2,7 @@\n #include \"strbuf.h\"\n #include \"run-command.h\"\n \n-int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)\n+const char *git_editor(void)\n {\n \tconst char *editor = getenv(\"GIT_EDITOR\");\n \tconst char *terminal = getenv(\"TERM\");\n@@ -16,11 +16,21 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en\n \t\teditor = getenv(\"EDITOR\");\n \n \tif (!editor && terminal_is_dumb)\n-\t\treturn error(\"terminal is dumb, but EDITOR unset\");\n+\t\treturn NULL;\n \n \tif (!editor)\n \t\teditor = \"vi\";\n \n+\treturn editor;\n+}\n+\n+int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)\n+{\n+\tconst char *editor = git_editor();\n+\n+\tif (!editor)\n+\t\treturn error(\"terminal is dumb, but EDITOR unset\");\n+\n \tif (strcmp(editor, \":\")) {\n \t\tsize_t len = strlen(editor);\n \t\tint i = 0;\ndiff --git a/var.c b/var.c\nindex dacbaab..12a8512 100644\n--- a/var.c\n+++ b/var.c\n@@ -8,6 +8,16 @@\n \n static const char var_usage[] = \"git var [-l | <variable>]\";\n \n+static const char *editor(int flag)\n+{\n+\tconst char *pgm = git_editor();\n+\n+\tif (!pgm && flag & IDENT_ERROR_ON_NO_NAME)\n+\t\tdie(\"terminal is dumb, but VISUAL and EDITOR unset\");\n+\n+\treturn pgm;\n+}\n+\n struct git_var {\n \tconst char *name;\n \tconst char *(*read)(int);\n@@ -15,14 +25,18 @@ struct git_var {\n static struct git_var git_vars[] = {\n \t{ \"GIT_COMMITTER_IDENT\", git_committer_info },\n \t{ \"GIT_AUTHOR_IDENT\",   git_author_info },\n+\t{ \"GIT_EDITOR\", editor },\n \t{ \"\", NULL },\n };\n \n static void list_vars(void)\n {\n \tstruct git_var *ptr;\n+\tconst char *val;\n+\n \tfor (ptr = git_vars; ptr->read; ptr++)\n-\t\tprintf(\"%s=%s\\n\", ptr->name, ptr->read(0));\n+\t\tif ((val = ptr->read(0))\n+\t\t\tprintf(\"%s=%s\\n\", ptr->name, val);\n }\n \n static const char *read_var(const char *var)\n-- \n1.6.5.2\n"},{"id":"126512","messageId":"20091031045358.GA9565@progeny.tock","threadId":"21405","inReplyTo":"20091031040436.GB6022@progeny.tock","subject":"Re: [PATCH v3] Teach git var about GIT_EDITOR","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-31T04:53:58Z","receivedAt":"2009-10-31T04:53:58Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"A typo fix --- sorry for the noise.\n\nJonathan Nieder wrote:\n\n> --- a/var.c\n> +++ b/var.c\n> @@ -8,6 +8,16 @@\n>  \n>  static const char var_usage[] = \"git var [-l | <variable>]\";\n>  \n> +static const char *editor(int flag)\n> +{\n> +\tconst char *pgm = git_editor();\n> +\n> +\tif (!pgm && flag & IDENT_ERROR_ON_NO_NAME)\n> +\t\tdie(\"terminal is dumb, but VISUAL and EDITOR unset\");\n\nAgh...  s/VISUAL and //.\n\nAll right, time to sleep.  Apologies for all the mistakes, and thanks\nfor the help catching them.\n\nKind regards,\nJonathan\n"},{"id":"126515","messageId":"20091031074624.GA635@progeny.tock","threadId":"21405","inReplyTo":"20091031013039.GC5160@progeny.tock","subject":"[PATCH v2 2/8] Do not use VISUAL editor on dumb terminals","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-31T07:46:24Z","receivedAt":"2009-10-31T07:46:24Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Jonathan Nieder wrote:\n\n> Refuse to use $VISUAL and fall back to $EDITOR if TERM is unset\n> or set to \"dumb\".  Traditionally, VISUAL is set to a screen\n> editor and EDITOR to a line-based editor, which should be more\n> useful in that situation.\n\nI was too lazy to wait for tests to finish on this one, and lo and\nbehold, they did not pass.\n\nThese additional changes seem to help, and they also add a test to\nexplain the change in editor behavior.  The patch with these changes\nsquashed is also included in this message, below the scissors mark.\n\nIn the controlled environment used for tests, TERM is set to dumb\nand ever since commit 02b3566 (test-lib.sh: Add a test_set_editor\nfunction to safely set $VISUAL, 2008-05-04), most tests set VISUAL\nwhen they want to set an editor for git to use.  With this patch, they\nshould be using EDITOR instead.\n\n--- a/t/t7005-editor.sh\n+++ b/t/t7005-editor.sh\n@@ -42,6 +42,16 @@ test_expect_success 'dumb should error out when falling back on vi' '\n \tfi\n '\n \n+test_expect_success 'dumb should prefer EDITOR to VISUAL' '\n+\n+\tEDITOR=./e-EDITOR.sh &&\n+\tVISUAL=./e-VISUAL.sh &&\n+\texport EDITOR VISUAL &&\n+\tgit commit --amend &&\n+\ttest \"$(git show -s --format=%s)\" = \"Edited by EDITOR\"\n+\n+'\n+\n TERM=vt100\n export TERM\n for i in vi EDITOR VISUAL core_editor GIT_EDITOR\n--- a/t/t7501-commit.sh\n+++ b/t/t7501-commit.sh\n@@ -86,7 +86,7 @@ chmod 755 editor\n \n test_expect_success \\\n \t\"amend commit\" \\\n-\t\"VISUAL=./editor git commit --amend\"\n+\t\"EDITOR=./editor git commit --amend\"\n \n test_expect_success \\\n \t\"passing -m and -F\" \\\n@@ -107,7 +107,7 @@ chmod 755 editor\n test_expect_success \\\n \t\"editing message from other commit\" \\\n \t\"echo 'hula hula' >file && \\\n-\t VISUAL=./editor git commit -c HEAD^ -a\"\n+\t EDITOR=./editor git commit -c HEAD^ -a\"\n \n test_expect_success \\\n \t\"message from stdin\" \\\n@@ -141,10 +141,10 @@ EOF\n test_expect_success \\\n \t'editor not invoked if -F is given' '\n \t echo \"moo\" >file &&\n-\t VISUAL=./editor git commit -a -F msg &&\n+\t EDITOR=./editor git commit -a -F msg &&\n \t git show -s --pretty=format:\"%s\" | grep -q good &&\n \t echo \"quack\" >file &&\n-\t echo \"Another good message.\" | VISUAL=./editor git commit -a -F - &&\n+\t echo \"Another good message.\" | EDITOR=./editor git commit -a -F - &&\n \t git show -s --pretty=format:\"%s\" | grep -q good\n \t '\n # We could just check the head sha1, but checking each commit makes it\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -30,7 +30,7 @@ TZ=UTC\n TERM=dumb\n export LANG LC_ALL PAGER TERM TZ\n EDITOR=:\n-VISUAL=:\n+unset VISUAL\n unset GIT_EDITOR\n unset AUTHOR_DATE\n unset AUTHOR_EMAIL\n@@ -58,7 +58,7 @@ GIT_MERGE_VERBOSITY=5\n export GIT_MERGE_VERBOSITY\n export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME\n export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME\n-export EDITOR VISUAL\n+export EDITOR\n GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}\n \n # Protect ourselves from common misconfiguration to export\n@@ -207,8 +207,8 @@ trap 'die' EXIT\n test_set_editor () {\n \tFAKE_EDITOR=\"$1\"\n \texport FAKE_EDITOR\n-\tVISUAL='\"$FAKE_EDITOR\"'\n-\texport VISUAL\n+\tEDITOR='\"$FAKE_EDITOR\"'\n+\texport EDITOR\n }\n \n test_tick () {\n\n-- %< --\nSubject: [PATCH] Do not use VISUAL editor on dumb terminals\n\nRefuse to use $VISUAL and fall back to $EDITOR if TERM is unset\nor set to \"dumb\".  Traditionally, VISUAL is set to a screen\neditor and EDITOR to a line-based editor, which should be more\nuseful in that situation.\n\nvim, for example, is happy to assume a terminal supports ANSI\nsequences even if TERM is dumb (e.g., when running from a text\neditor like Acme).  git already refuses to fall back to vi on a\ndumb terminal if GIT_EDITOR, core.editor, VISUAL, and EDITOR are\nunset, but without this patch, that check is suppressed by\nVISUAL=vi.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Jonathan Nieder <jrn@progeny.tock>\n---\n\n editor.c          |   12 ++++++------\n t/t7005-editor.sh |   10 ++++++++++\n t/t7501-commit.sh |    8 ++++----\n t/test-lib.sh     |    8 ++++----\n 4 files changed, 24 insertions(+), 14 deletions(-)\n\ndiff --git a/editor.c b/editor.c\nindex 941c0b2..3f13751 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -4,19 +4,19 @@\n \n int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)\n {\n-\tconst char *editor, *terminal;\n+\tconst char *editor = getenv(\"GIT_EDITOR\");\n+\tconst char *terminal = getenv(\"TERM\");\n+\tint terminal_is_dumb = !terminal || !strcmp(terminal, \"dumb\");\n \n-\teditor = getenv(\"GIT_EDITOR\");\n \tif (!editor && editor_program)\n \t\teditor = editor_program;\n-\tif (!editor)\n+\tif (!editor && !terminal_is_dumb)\n \t\teditor = getenv(\"VISUAL\");\n \tif (!editor)\n \t\teditor = getenv(\"EDITOR\");\n \n-\tterminal = getenv(\"TERM\");\n-\tif (!editor && (!terminal || !strcmp(terminal, \"dumb\")))\n-\t\treturn error(\"Terminal is dumb but no VISUAL nor EDITOR defined.\");\n+\tif (!editor && terminal_is_dumb)\n+\t\treturn error(\"terminal is dumb, but EDITOR unset\");\n \n \tif (!editor)\n \t\teditor = \"vi\";\ndiff --git a/t/t7005-editor.sh b/t/t7005-editor.sh\nindex b647957..a95fe19 100755\n--- a/t/t7005-editor.sh\n+++ b/t/t7005-editor.sh\n@@ -42,6 +42,16 @@ test_expect_success 'dumb should error out when falling back on vi' '\n \tfi\n '\n \n+test_expect_success 'dumb should prefer EDITOR to VISUAL' '\n+\n+\tEDITOR=./e-EDITOR.sh &&\n+\tVISUAL=./e-VISUAL.sh &&\n+\texport EDITOR VISUAL &&\n+\tgit commit --amend &&\n+\ttest \"$(git show -s --format=%s)\" = \"Edited by EDITOR\"\n+\n+'\n+\n TERM=vt100\n export TERM\n for i in vi EDITOR VISUAL core_editor GIT_EDITOR\ndiff --git a/t/t7501-commit.sh b/t/t7501-commit.sh\nindex d2de576..a603f6d 100755\n--- a/t/t7501-commit.sh\n+++ b/t/t7501-commit.sh\n@@ -86,7 +86,7 @@ chmod 755 editor\n \n test_expect_success \\\n \t\"amend commit\" \\\n-\t\"VISUAL=./editor git commit --amend\"\n+\t\"EDITOR=./editor git commit --amend\"\n \n test_expect_success \\\n \t\"passing -m and -F\" \\\n@@ -107,7 +107,7 @@ chmod 755 editor\n test_expect_success \\\n \t\"editing message from other commit\" \\\n \t\"echo 'hula hula' >file && \\\n-\t VISUAL=./editor git commit -c HEAD^ -a\"\n+\t EDITOR=./editor git commit -c HEAD^ -a\"\n \n test_expect_success \\\n \t\"message from stdin\" \\\n@@ -141,10 +141,10 @@ EOF\n test_expect_success \\\n \t'editor not invoked if -F is given' '\n \t echo \"moo\" >file &&\n-\t VISUAL=./editor git commit -a -F msg &&\n+\t EDITOR=./editor git commit -a -F msg &&\n \t git show -s --pretty=format:\"%s\" | grep -q good &&\n \t echo \"quack\" >file &&\n-\t echo \"Another good message.\" | VISUAL=./editor git commit -a -F - &&\n+\t echo \"Another good message.\" | EDITOR=./editor git commit -a -F - &&\n \t git show -s --pretty=format:\"%s\" | grep -q good\n \t '\n # We could just check the head sha1, but checking each commit makes it\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex f2ca536..ec3336a 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -30,7 +30,7 @@ TZ=UTC\n TERM=dumb\n export LANG LC_ALL PAGER TERM TZ\n EDITOR=:\n-VISUAL=:\n+unset VISUAL\n unset GIT_EDITOR\n unset AUTHOR_DATE\n unset AUTHOR_EMAIL\n@@ -58,7 +58,7 @@ GIT_MERGE_VERBOSITY=5\n export GIT_MERGE_VERBOSITY\n export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME\n export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME\n-export EDITOR VISUAL\n+export EDITOR\n GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}\n \n # Protect ourselves from common misconfiguration to export\n@@ -207,8 +207,8 @@ trap 'die' EXIT\n test_set_editor () {\n \tFAKE_EDITOR=\"$1\"\n \texport FAKE_EDITOR\n-\tVISUAL='\"$FAKE_EDITOR\"'\n-\texport VISUAL\n+\tEDITOR='\"$FAKE_EDITOR\"'\n+\texport EDITOR\n }\n \n test_tick () {\n-- \n1.6.5.2\n\n> \n> vim, for example, is happy to assume a terminal supports ANSI\n> sequences even if TERM is dumb (e.g., when running from a text\n> editor like Acme).  git already refuses to fall back to vi on a\n> dumb terminal if GIT_EDITOR, core.editor, VISUAL, and EDITOR are\n> unset, but without this patch, that check is suppressed by\n> VISUAL=vi.\n> \n> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\n> ---\n> This patch eases my discomfort about the error message a little.  It\n> is not actually needed to support any ways of working I engage in.\n> \n> If stdout is redirected, this is probably still making the wrong\n> choice; isatty(STDOUT_FILENO) might be a more useful datum to use.\n> But it does not seem worth complicating the logic further.\n> \n>  editor.c |   12 ++++++------\n>  1 files changed, 6 insertions(+), 6 deletions(-)\n> \n> diff --git a/editor.c b/editor.c\n> index 941c0b2..3f13751 100644\n> --- a/editor.c\n> +++ b/editor.c\n> @@ -4,19 +4,19 @@\n>  \n>  int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)\n>  {\n> -\tconst char *editor, *terminal;\n> +\tconst char *editor = getenv(\"GIT_EDITOR\");\n> +\tconst char *terminal = getenv(\"TERM\");\n> +\tint terminal_is_dumb = !terminal || !strcmp(terminal, \"dumb\");\n>  \n> -\teditor = getenv(\"GIT_EDITOR\");\n>  \tif (!editor && editor_program)\n>  \t\teditor = editor_program;\n> -\tif (!editor)\n> +\tif (!editor && !terminal_is_dumb)\n>  \t\teditor = getenv(\"VISUAL\");\n>  \tif (!editor)\n>  \t\teditor = getenv(\"EDITOR\");\n>  \n> -\tterminal = getenv(\"TERM\");\n> -\tif (!editor && (!terminal || !strcmp(terminal, \"dumb\")))\n> -\t\treturn error(\"Terminal is dumb but no VISUAL nor EDITOR defined.\");\n> +\tif (!editor && terminal_is_dumb)\n> +\t\treturn error(\"terminal is dumb, but EDITOR unset\");\n>  \n>  \tif (!editor)\n>  \t\teditor = \"vi\";\n> -- \n> 1.6.5.2\n> \n"},{"id":"126516","messageId":"20091031075627.GB635@progeny.tock","threadId":"21405","inReplyTo":"20091031045358.GA9565@progeny.tock","subject":"[PATCH v4] Teach git var about GIT_EDITOR","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-31T07:56:28Z","receivedAt":"2009-10-31T07:56:28Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Expose the command used by launch_editor() for scripts to use.\nThis should allow one to avoid searching for a proper editor\nseparately in each command.\n\nSigned-off-by: Johannes Sixt <j6t@kdbg.org>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\nThere was another typo in the patch I sent.  The paper-bag fix:\n\n\tdiff -u b/var.c b/var.c\n\t--- b/var.c\n\t+++ b/var.c\n\t@@ -35,7 +35,7 @@\n\t\tconst char *val;\n\t\n\t\tfor (ptr = git_vars; ptr->read; ptr++)\n\t-\t\tif ((val = ptr->read(0))\n\t+\t\tif ((val = ptr->read(0)))\n\t\t\t\tprintf(\"%s=%s\\n\", ptr->name, val);\n\t }\n\t\n\nHere’s an updated patch.  This one shouldn’t have any bugs (yeah, right).\n\nGood night again,\nJonathan\n\n Documentation/git-var.txt |    8 ++++++++\n cache.h                   |    1 +\n editor.c                  |   14 ++++++++++++--\n var.c                     |   16 +++++++++++++++-\n 4 files changed, 36 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-var.txt b/Documentation/git-var.txt\nindex e2f4c09..89e4b4f 100644\n--- a/Documentation/git-var.txt\n+++ b/Documentation/git-var.txt\n@@ -36,6 +36,14 @@ GIT_AUTHOR_IDENT::\n GIT_COMMITTER_IDENT::\n     The person who put a piece of code into git.\n \n+GIT_EDITOR::\n+    Text editor for use by git commands.  The value is meant to be\n+    interpreted by the shell when it is used.  Examples: `~/bin/vi`,\n+    `$SOME_ENVIRONMENT_VARIABLE`, `\"C:\\Program Files\\Vim\\gvim.exe\"\n+    --nofork`.  The order of preference is the `$GIT_EDITOR`\n+    environment variable, then `core.editor` configuration, then\n+    `$VISUAL`, then `$EDITOR`, and then finally 'vi'.\n+\n Diagnostics\n -----------\n You don't exist. Go away!::\ndiff --git a/cache.h b/cache.h\nindex 96840c7..311cfe1 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -750,6 +750,7 @@ extern const char *git_author_info(int);\n extern const char *git_committer_info(int);\n extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int);\n extern const char *fmt_name(const char *name, const char *email);\n+extern const char *git_editor(void);\n \n struct checkout {\n \tconst char *base_dir;\ndiff --git a/editor.c b/editor.c\nindex 3f13751..4f98b72 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -2,7 +2,7 @@\n #include \"strbuf.h\"\n #include \"run-command.h\"\n \n-int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)\n+const char *git_editor(void)\n {\n \tconst char *editor = getenv(\"GIT_EDITOR\");\n \tconst char *terminal = getenv(\"TERM\");\n@@ -16,11 +16,21 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en\n \t\teditor = getenv(\"EDITOR\");\n \n \tif (!editor && terminal_is_dumb)\n-\t\treturn error(\"terminal is dumb, but EDITOR unset\");\n+\t\treturn NULL;\n \n \tif (!editor)\n \t\teditor = \"vi\";\n \n+\treturn editor;\n+}\n+\n+int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)\n+{\n+\tconst char *editor = git_editor();\n+\n+\tif (!editor)\n+\t\treturn error(\"terminal is dumb, but EDITOR unset\");\n+\n \tif (strcmp(editor, \":\")) {\n \t\tsize_t len = strlen(editor);\n \t\tint i = 0;\ndiff --git a/var.c b/var.c\nindex dacbaab..a303757 100644\n--- a/var.c\n+++ b/var.c\n@@ -8,6 +8,16 @@\n \n static const char var_usage[] = \"git var [-l | <variable>]\";\n \n+static const char *editor(int flag)\n+{\n+\tconst char *pgm = git_editor();\n+\n+\tif (!pgm && flag & IDENT_ERROR_ON_NO_NAME)\n+\t\tdie(\"terminal is dumb, but EDITOR unset\");\n+\n+\treturn pgm;\n+}\n+\n struct git_var {\n \tconst char *name;\n \tconst char *(*read)(int);\n@@ -15,14 +25,18 @@ struct git_var {\n static struct git_var git_vars[] = {\n \t{ \"GIT_COMMITTER_IDENT\", git_committer_info },\n \t{ \"GIT_AUTHOR_IDENT\",   git_author_info },\n+\t{ \"GIT_EDITOR\", editor },\n \t{ \"\", NULL },\n };\n \n static void list_vars(void)\n {\n \tstruct git_var *ptr;\n+\tconst char *val;\n+\n \tfor (ptr = git_vars; ptr->read; ptr++)\n-\t\tprintf(\"%s=%s\\n\", ptr->name, ptr->read(0));\n+\t\tif ((val = ptr->read(0)))\n+\t\t\tprintf(\"%s=%s\\n\", ptr->name, val);\n }\n \n static const char *read_var(const char *var)\n-- \n1.6.5.2\n"},{"id":"126530","messageId":"4AEC92C5.3000700@kdbg.org","threadId":"21405","inReplyTo":"20091031013934.GD5160@progeny.tock","subject":"Re: [PATCH v2 3/8] Teach git var about GIT_EDITOR","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2009-10-31T19:40:53Z","receivedAt":"2009-10-31T19:40:53Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Jonathan Nieder schrieb:\n> From: Johannes Sixt <j6t@kdbg.org>\n> \n> Expose the command used by launch_editor() for scripts to use...\n >\n> Signed-off-by: Johannes Sixt <j6t@kdbg.org>\n> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\n\nThis patch has grown far beyond my original submission. I can't validly \nsign it off anymore. Please take authorship ;)\n\n-- Hannes\n"},{"id":"126531","messageId":"7vzl775ol5.fsf@alter.siamese.dyndns.org","threadId":"21405","inReplyTo":"20091031032647.GA5583@progeny.tock","subject":"Re: [PATCH 7/8] Provide a build time default-editor setting","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-31T19:51:34Z","receivedAt":"2009-10-31T19:51:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonathan Nieder <jrnieder@gmail.com> writes:\n\n> Junio C Hamano wrote:\n>> Jonathan Nieder <jrnieder@gmail.com> writes:\n>  \n>>> +test_expect_success 'does editor have a simple name (no slashes, etc)?' '\n>>> +\n>>> +\teditor=$(TERM=vt100 git var GIT_EDITOR) &&\n>>> +\ttest -n \"$editor\" &&\n>>> +\tsimple=t &&\n>>> +\tcase \"$editor\" in\n>>> +\t*/* | core_editor | [A-Z]*)\n>> \n>> Hmm, what are the latter two cases designed to catch?\n>\n> Both are meant to allow the test to work without too many changes.\n\nHonestly speaking, my preference is to see if the built-in editor is\nexactly spelled as 'v' 'i', and skip this test altogether if it isn't.\nThen the patch only needs to insert these lines (and reword \"default\neditor name too complicated\" to \"using customized default editor\") without\ntouching the rest.  It simply does not look worth the complication.\n\nYou _might_ be able to skip only the \"vi\" part of the test when you see\nthat the built-in default is customized, though.  I didn't look closely\nenough.\n\n> diff --git a/t/t7005-editor.sh b/t/t7005-editor.sh\n> ...\n> +unset EDITOR VISUAL GIT_EDITOR\n> +\n> +test_expect_success 'determine default editor' '\n> +\n> +\teditor=$(TERM=vt100 git var GIT_EDITOR) &&\n> +\ttest -n \"$editor\"\n> +\n> +'\n> +\n> +if ! test -z \"$(printf '%s\\n' \"$editor\" | sed '/^[a-z]*$/d')\"\n> +then\n> +\tsay 'skipping editor tests, default editor name too complicated'\n> +\ttest_done\n> +fi\n> +\n"},{"id":"126537","messageId":"20091031212144.GA5022@progeny.tock","threadId":"21405","inReplyTo":"7vzl775ol5.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 7/8] Provide a build time default-editor setting","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-10-31T21:21:45Z","receivedAt":"2009-10-31T21:21:45Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Junio C Hamano wrote:\n\n> Honestly speaking, my preference is to see if the built-in editor is\n> exactly spelled as 'v' 'i', and skip this test altogether if it isn't.\n\nThat does make sense.  But let me try one last time, before doing\nthat.  (I should have sat down and thought this through carefully\nbefore sending the first version --- sorry.)\n\nThough the first two iterations of the patch were pretty ugly, the\nthird was just 's/vi/\"$editor\"/g' after setting editor and bailing out\nif it does not consist of lowercase letters.  As you mentioned, it\nmakes more sense to skip only the \"vi\" part of the test.\n\nTested with DEFAULT_EDITOR=vi, vim, /usr/bin/nonexistent.\n\n t/t7005-editor.sh |   37 +++++++++++++++++++++++++------------\n 1 files changed, 25 insertions(+), 12 deletions(-)\n\ndiff --git a/t/t7005-editor.sh b/t/t7005-editor.sh\nindex a95fe19..5257f4d 100755\n--- a/t/t7005-editor.sh\n+++ b/t/t7005-editor.sh\n@@ -4,7 +4,21 @@ test_description='GIT_EDITOR, core.editor, and stuff'\n \n . ./test-lib.sh\n \n-for i in GIT_EDITOR core_editor EDITOR VISUAL vi\n+unset EDITOR VISUAL GIT_EDITOR\n+\n+test_expect_success 'determine default editor' '\n+\n+\tvi=$(TERM=vt100 git var GIT_EDITOR) &&\n+\ttest -n \"$vi\"\n+\n+'\n+\n+if ! expr \"$vi\" : '^[a-z]*$' >/dev/null\n+then\n+\tvi=\n+fi\n+\n+for i in GIT_EDITOR core_editor EDITOR VISUAL $vi\n do\n \tcat >e-$i.sh <<-EOF\n \t#!$SHELL_PATH\n@@ -12,19 +26,18 @@ do\n \tEOF\n \tchmod +x e-$i.sh\n done\n-unset vi\n-mv e-vi.sh vi\n-unset EDITOR VISUAL GIT_EDITOR\n+\n+if ! test -z \"$vi\"\n+then\n+\tmv e-$vi.sh $vi\n+fi\n \n test_expect_success setup '\n \n-\tmsg=\"Hand edited\" &&\n+\tmsg=\"Hand-edited\" &&\n+\ttest_commit \"$msg\" &&\n \techo \"$msg\" >expect &&\n-\tgit add vi &&\n-\ttest_tick &&\n-\tgit commit -m \"$msg\" &&\n-\tgit show -s --pretty=oneline |\n-\tsed -e \"s/^[0-9a-f]* //\" >actual &&\n+\tgit show -s --format=%s > actual &&\n \tdiff actual expect\n \n '\n@@ -54,7 +67,7 @@ test_expect_success 'dumb should prefer EDITOR to VISUAL' '\n \n TERM=vt100\n export TERM\n-for i in vi EDITOR VISUAL core_editor GIT_EDITOR\n+for i in $vi EDITOR VISUAL core_editor GIT_EDITOR\n do\n \techo \"Edited by $i\" >expect\n \tunset EDITOR VISUAL GIT_EDITOR\n@@ -78,7 +91,7 @@ done\n \n unset EDITOR VISUAL GIT_EDITOR\n git config --unset-all core.editor\n-for i in vi EDITOR VISUAL core_editor GIT_EDITOR\n+for i in $vi EDITOR VISUAL core_editor GIT_EDITOR\n do\n \techo \"Edited by $i\" >expect\n \tcase \"$i\" in\n"},{"id":"126544","messageId":"7vocnm3m14.fsf@alter.siamese.dyndns.org","threadId":"21405","inReplyTo":"20091031075627.GB635@progeny.tock","subject":"Re: [PATCH v4] Teach git var about GIT_EDITOR","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-11-01T04:29:43Z","receivedAt":"2009-11-01T04:29:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonathan Nieder <jrnieder@gmail.com> writes:\n\n> Expose the command used by launch_editor() for scripts to use.\n> This should allow one to avoid searching for a proper editor\n> separately in each command.\n\nOk, so the idea is...\n\n * git_editor(void) uses the logic to decide which editor to use that used\n   to live in launch_editor().  The function returns NULL if there is no\n   suitable editor; the caller is expected to issue an error message when\n   appropriate.\n\n * launch_editor() uses git_editor() and gives the error message the same\n   way as before when EDITOR is not set.\n\n * \"git var GIT_EDITOR\" gives the editor name, or an error message when\n   there is no appropriate one.\n\n * \"git var -l\" gives GIT_EDITOR=name only if there is an appropriate\n   editor.\n\nThe above all look sensible, but IIRC, the true \"vi\" fell back on \"ex\"\nmode on dumb terminals and was usable as a line editor, so we should be\nable to run it even on dumb terminals.  I do not know about vi-clones\nthough.\n"},{"id":"126545","messageId":"7vhbte3m0r.fsf@alter.siamese.dyndns.org","threadId":"21405","inReplyTo":"20091031212144.GA5022@progeny.tock","subject":"Re: [PATCH 7/8] Provide a build time default-editor setting","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-11-01T04:29:56Z","receivedAt":"2009-11-01T04:29:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonathan Nieder <jrnieder@gmail.com> writes:\n\n> +unset EDITOR VISUAL GIT_EDITOR\n> +\n> +test_expect_success 'determine default editor' '\n> +\n> +\tvi=$(TERM=vt100 git var GIT_EDITOR) &&\n> +\ttest -n \"$vi\"\n> +\n> +'\n> +\n> +if ! expr \"$vi\" : '^[a-z]*$' >/dev/null\n> +then\n> +\tvi=\n> +fi\n> +\n> +for i in GIT_EDITOR core_editor EDITOR VISUAL $vi\n> ...\n> -for i in vi EDITOR VISUAL core_editor GIT_EDITOR\n> +for i in $vi EDITOR VISUAL core_editor GIT_EDITOR\n>  do\n>  \techo \"Edited by $i\" >expect\n>  \tunset EDITOR VISUAL GIT_EDITOR\n> @@ -78,7 +91,7 @@ done\n>  \n>  unset EDITOR VISUAL GIT_EDITOR\n>  git config --unset-all core.editor\n> -for i in vi EDITOR VISUAL core_editor GIT_EDITOR\n> +for i in $vi EDITOR VISUAL core_editor GIT_EDITOR\n>  do\n\nBeautiful ;-)\n"},{"id":"127396","messageId":"20091111235100.GA1140@progeny.tock","threadId":"21405","inReplyTo":"20091031012050.GA5160@progeny.tock","subject":"[PATCH v4 0/9] Default pager and editor","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-11-11T23:51:00Z","receivedAt":"2009-11-11T23:51:00Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Junio C Hamano wrote: \n\n> * jn/editor-pager (2009-10-30) 8 commits\n>  - Provide a build time default-pager setting\n>  - Provide a build time default-editor setting\n>  - am -i, git-svn: use \"git var GIT_PAGER\"\n>  - add -i, send-email, svn, p4, etc: use \"git var GIT_EDITOR\"\n>  - Teach git var about GIT_PAGER\n>  - Teach git var about GIT_EDITOR\n>  - Do not use VISUAL editor on dumb terminals\n>  - Handle more shell metacharacters in editor names\n> \n> Any comments?\n\nHere’s a reroll.  The interdiff is very small:\n\ndiff --git a/ident.c b/ident.c\nindex 99f1c85..26409b2 100644\n--- a/ident.c\n+++ b/ident.c\n@@ -205,7 +205,7 @@ const char *fmt_ident(const char *name, const char *email,\n \t\tif ((warn_on_no_name || error_on_no_name) &&\n \t\t    name == git_default_name && env_hint) {\n \t\t\tfprintf(stderr, env_hint, au_env, co_env);\n-\t\t\tenv_hint = NULL; /* warn only once, for \"git var -l\" */\n+\t\t\tenv_hint = NULL; /* warn only once */\n \t\t}\n \t\tif (error_on_no_name)\n \t\t\tdie(\"empty ident %s <%s> not allowed\", name, email);\n\nand the corresponding hunk in patch 3 could be safely discarded.\nAside from that, patch 3 has been unsquashed from patch 4, since it is\nan independent fix that might be worth ejecting; the Signed-off-by\nlines on patches 2 and 4 have been fixed; and the commit message for\npatch 4 has been expanded to explain more.\n\nIn short, nothing of substance has changed.  If you are reminded of\nany thoughts on the series, please let me know.\n\nI think it is fair to say every one of these patches except the first\nwas someone else’s idea.  Thanks, everyone.\n\nJonathan Nieder (8):\n  Handle more shell metacharacters in editor names\n  Do not use VISUAL editor on dumb terminals\n  Suppress warnings from \"git var -l\"\n  Teach git var about GIT_EDITOR\n  Teach git var about GIT_PAGER\n  add -i, send-email, svn, p4, etc: use \"git var GIT_EDITOR\"\n  am -i, git-svn: use \"git var GIT_PAGER\"\n  Provide a build time default-editor setting\n\nJunio C Hamano (1):\n  Provide a build time default-pager setting\n\n Documentation/config.txt         |    4 +--\n Documentation/git-commit.txt     |    2 +-\n Documentation/git-send-email.txt |    4 +-\n Documentation/git-var.txt        |   14 +++++++++++\n Makefile                         |   28 ++++++++++++++++++++++\n cache.h                          |    2 +\n contrib/fast-import/git-p4       |    5 +---\n editor.c                         |   32 ++++++++++++++++++-------\n git-add--interactive.perl        |    3 +-\n git-am.sh                        |    5 +++-\n git-send-email.perl              |    3 +-\n git-sh-setup.sh                  |   19 +++++----------\n git-svn.perl                     |   11 +++-----\n ident.c                          |    2 +-\n pager.c                          |   24 ++++++++++++++++---\n t/t7005-editor.sh                |   47 ++++++++++++++++++++++++++++---------\n t/t7501-commit.sh                |    8 +++---\n t/test-lib.sh                    |    8 +++---\n var.c                            |   26 ++++++++++++++++++++-\n 19 files changed, 178 insertions(+), 69 deletions(-)\n"},{"id":"127397","messageId":"20091111235244.GB1140@progeny.tock","threadId":"21405","inReplyTo":"20091111235100.GA1140@progeny.tock","subject":"[PATCH 1/9] Handle more shell metacharacters in editor names","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-11-11T23:52:44Z","receivedAt":"2009-11-11T23:52:44Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Pass the editor name to the shell if it contains any susv3 shell\nspecial character (globs, redirections, variable substitutions,\nescapes, etc).  This way, the meaning of some characters will not\nmeaninglessly change when others are added, and git commands\nimplemented in C and in shell scripts will interpret editor names\nin the same way.\n\nThis does not make the GIT_EDITOR setting any more expressive,\nsince one could always use single quotes to force the editor to\nbe passed to the shell.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\nUnchanged from jn/editor-pager, included only for reference.\n\n editor.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/editor.c b/editor.c\nindex 4d469d0..941c0b2 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -28,7 +28,7 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en\n \t\tconst char *args[6];\n \t\tstruct strbuf arg0 = STRBUF_INIT;\n \n-\t\tif (strcspn(editor, \"$ \\t'\") != len) {\n+\t\tif (strcspn(editor, \"|&;<>()$`\\\\\\\"' \\t\\n*?[#~=%\") != len) {\n \t\t\t/* there are specials */\n \t\t\tstrbuf_addf(&arg0, \"%s \\\"$@\\\"\", editor);\n \t\t\targs[i++] = \"sh\";\n-- \n1.6.5.2\n"},{"id":"127398","messageId":"20091111235607.GC1140@progeny.tock","threadId":"21405","inReplyTo":"20091111235100.GA1140@progeny.tock","subject":"[PATCH 2/9] Do not use VISUAL editor on dumb terminals","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-11-11T23:56:07Z","receivedAt":"2009-11-11T23:56:07Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Refuse to use $VISUAL and fall back to $EDITOR if TERM is unset\nor set to \"dumb\".  Traditionally, VISUAL is set to a screen\neditor and EDITOR to a line-based editor, which should be more\nuseful in that situation.\n\nvim, for example, is happy to assume a terminal supports ANSI\nsequences even if TERM is dumb (e.g., when running from a text\neditor like Acme).  git already refuses to fall back to vi on a\ndumb terminal if GIT_EDITOR, core.editor, VISUAL, and EDITOR are\nunset, but without this patch, that check is suppressed by\nVISUAL=vi.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\nFixes broken sign-off, patch unchanged.\n\nI am personally most interested in this for usage from a text editor,\nbut vim does not set TERM=dumb like it probably ought to.  A more\nrealistic everyday example might be \"ssh user@domain git commit\".\n\n editor.c          |   12 ++++++------\n t/t7005-editor.sh |   10 ++++++++++\n t/t7501-commit.sh |    8 ++++----\n t/test-lib.sh     |    8 ++++----\n 4 files changed, 24 insertions(+), 14 deletions(-)\n\ndiff --git a/editor.c b/editor.c\nindex 941c0b2..3f13751 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -4,19 +4,19 @@\n \n int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)\n {\n-\tconst char *editor, *terminal;\n+\tconst char *editor = getenv(\"GIT_EDITOR\");\n+\tconst char *terminal = getenv(\"TERM\");\n+\tint terminal_is_dumb = !terminal || !strcmp(terminal, \"dumb\");\n \n-\teditor = getenv(\"GIT_EDITOR\");\n \tif (!editor && editor_program)\n \t\teditor = editor_program;\n-\tif (!editor)\n+\tif (!editor && !terminal_is_dumb)\n \t\teditor = getenv(\"VISUAL\");\n \tif (!editor)\n \t\teditor = getenv(\"EDITOR\");\n \n-\tterminal = getenv(\"TERM\");\n-\tif (!editor && (!terminal || !strcmp(terminal, \"dumb\")))\n-\t\treturn error(\"Terminal is dumb but no VISUAL nor EDITOR defined.\");\n+\tif (!editor && terminal_is_dumb)\n+\t\treturn error(\"terminal is dumb, but EDITOR unset\");\n \n \tif (!editor)\n \t\teditor = \"vi\";\ndiff --git a/t/t7005-editor.sh b/t/t7005-editor.sh\nindex b647957..a95fe19 100755\n--- a/t/t7005-editor.sh\n+++ b/t/t7005-editor.sh\n@@ -42,6 +42,16 @@ test_expect_success 'dumb should error out when falling back on vi' '\n \tfi\n '\n \n+test_expect_success 'dumb should prefer EDITOR to VISUAL' '\n+\n+\tEDITOR=./e-EDITOR.sh &&\n+\tVISUAL=./e-VISUAL.sh &&\n+\texport EDITOR VISUAL &&\n+\tgit commit --amend &&\n+\ttest \"$(git show -s --format=%s)\" = \"Edited by EDITOR\"\n+\n+'\n+\n TERM=vt100\n export TERM\n for i in vi EDITOR VISUAL core_editor GIT_EDITOR\ndiff --git a/t/t7501-commit.sh b/t/t7501-commit.sh\nindex d2de576..a603f6d 100755\n--- a/t/t7501-commit.sh\n+++ b/t/t7501-commit.sh\n@@ -86,7 +86,7 @@ chmod 755 editor\n \n test_expect_success \\\n \t\"amend commit\" \\\n-\t\"VISUAL=./editor git commit --amend\"\n+\t\"EDITOR=./editor git commit --amend\"\n \n test_expect_success \\\n \t\"passing -m and -F\" \\\n@@ -107,7 +107,7 @@ chmod 755 editor\n test_expect_success \\\n \t\"editing message from other commit\" \\\n \t\"echo 'hula hula' >file && \\\n-\t VISUAL=./editor git commit -c HEAD^ -a\"\n+\t EDITOR=./editor git commit -c HEAD^ -a\"\n \n test_expect_success \\\n \t\"message from stdin\" \\\n@@ -141,10 +141,10 @@ EOF\n test_expect_success \\\n \t'editor not invoked if -F is given' '\n \t echo \"moo\" >file &&\n-\t VISUAL=./editor git commit -a -F msg &&\n+\t EDITOR=./editor git commit -a -F msg &&\n \t git show -s --pretty=format:\"%s\" | grep -q good &&\n \t echo \"quack\" >file &&\n-\t echo \"Another good message.\" | VISUAL=./editor git commit -a -F - &&\n+\t echo \"Another good message.\" | EDITOR=./editor git commit -a -F - &&\n \t git show -s --pretty=format:\"%s\" | grep -q good\n \t '\n # We could just check the head sha1, but checking each commit makes it\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex f2ca536..ec3336a 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -30,7 +30,7 @@ TZ=UTC\n TERM=dumb\n export LANG LC_ALL PAGER TERM TZ\n EDITOR=:\n-VISUAL=:\n+unset VISUAL\n unset GIT_EDITOR\n unset AUTHOR_DATE\n unset AUTHOR_EMAIL\n@@ -58,7 +58,7 @@ GIT_MERGE_VERBOSITY=5\n export GIT_MERGE_VERBOSITY\n export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME\n export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME\n-export EDITOR VISUAL\n+export EDITOR\n GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}\n \n # Protect ourselves from common misconfiguration to export\n@@ -207,8 +207,8 @@ trap 'die' EXIT\n test_set_editor () {\n \tFAKE_EDITOR=\"$1\"\n \texport FAKE_EDITOR\n-\tVISUAL='\"$FAKE_EDITOR\"'\n-\texport VISUAL\n+\tEDITOR='\"$FAKE_EDITOR\"'\n+\texport EDITOR\n }\n \n test_tick () {\n-- \n1.6.5.2\n"},{"id":"127399","messageId":"20091111235735.GD1140@progeny.tock","threadId":"21405","inReplyTo":"20091111235100.GA1140@progeny.tock","subject":"[PATCH 3/9] Suppress warnings from \"git var -l\"","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-11-11T23:57:36Z","receivedAt":"2009-11-11T23:57:36Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"For scripts using \"git var -l\" to read all logical variables at\nonce, not all per-variable warnings will be relevant.  So suppress\nthem.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\nThis is a separate issue that might even deserve to be ejected\nfrom the series.\n\nChanges from jn/editor-pager: unsquashed from the next patch, added\nback comment-changing hunk.  Of course, there’s no harm in omitting\nthe comment change, but it describes a change in reality: before this\npatch, that code gets run multiple times by \"git var -l\"; afterwards,\nby no one (except possible out-of-tree users).\n\n ident.c |    2 +-\n var.c   |    2 +-\n 2 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/ident.c b/ident.c\nindex 99f1c85..26409b2 100644\n--- a/ident.c\n+++ b/ident.c\n@@ -205,7 +205,7 @@ const char *fmt_ident(const char *name, const char *email,\n \t\tif ((warn_on_no_name || error_on_no_name) &&\n \t\t    name == git_default_name && env_hint) {\n \t\t\tfprintf(stderr, env_hint, au_env, co_env);\n-\t\t\tenv_hint = NULL; /* warn only once, for \"git var -l\" */\n+\t\t\tenv_hint = NULL; /* warn only once */\n \t\t}\n \t\tif (error_on_no_name)\n \t\t\tdie(\"empty ident %s <%s> not allowed\", name, email);\ndiff --git a/var.c b/var.c\nindex 125c0d1..dacbaab 100644\n--- a/var.c\n+++ b/var.c\n@@ -22,7 +22,7 @@ static void list_vars(void)\n {\n \tstruct git_var *ptr;\n \tfor (ptr = git_vars; ptr->read; ptr++)\n-\t\tprintf(\"%s=%s\\n\", ptr->name, ptr->read(IDENT_WARN_ON_NO_NAME));\n+\t\tprintf(\"%s=%s\\n\", ptr->name, ptr->read(0));\n }\n \n static const char *read_var(const char *var)\n-- \n1.6.5.2\n"},{"id":"127400","messageId":"20091112000126.GE1140@progeny.tock","threadId":"21405","inReplyTo":"20091111235100.GA1140@progeny.tock","subject":"[PATCH 4/9] Teach git var about GIT_EDITOR","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-11-12T00:01:27Z","receivedAt":"2009-11-12T00:01:27Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Expose the command used by launch_editor() for scripts to use.\nThis should allow one to avoid searching for a proper editor\nseparately in each command.\n\ngit_editor(void) uses the logic to decide which editor to use\nthat used to live in launch_editor().  The function returns NULL\nif there is no suitable editor; the caller is expected to issue\nan error message when appropriate.\n\nlaunch_editor() uses git_editor() and gives the error message the\nsame way as before when EDITOR is not set.\n\n\"git var GIT_EDITOR\" gives the editor name, or an error message\nwhen there is no appropriate one.\n\n\"git var -l\" gives GIT_EDITOR=name only if there is an\nappropriate editor.\n\nOriginally-submitted-by: Johannes Sixt <j6t@kdbg.org>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\nChanges from the version in pu:\n * unsquashed with the previous patch;\n * replaces Hannes’s sign-off with something more descriptive (see\n<http://thread.gmane.org/gmane.comp.version-control.git/131471/focus=131851>);\n * nicer commit message based on Junio’s summary.\n\n Documentation/git-var.txt |    8 ++++++++\n cache.h                   |    1 +\n editor.c                  |   14 ++++++++++++--\n var.c                     |   16 +++++++++++++++-\n 4 files changed, 36 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-var.txt b/Documentation/git-var.txt\nindex e2f4c09..89e4b4f 100644\n--- a/Documentation/git-var.txt\n+++ b/Documentation/git-var.txt\n@@ -36,6 +36,14 @@ GIT_AUTHOR_IDENT::\n GIT_COMMITTER_IDENT::\n     The person who put a piece of code into git.\n \n+GIT_EDITOR::\n+    Text editor for use by git commands.  The value is meant to be\n+    interpreted by the shell when it is used.  Examples: `~/bin/vi`,\n+    `$SOME_ENVIRONMENT_VARIABLE`, `\"C:\\Program Files\\Vim\\gvim.exe\"\n+    --nofork`.  The order of preference is the `$GIT_EDITOR`\n+    environment variable, then `core.editor` configuration, then\n+    `$VISUAL`, then `$EDITOR`, and then finally 'vi'.\n+\n Diagnostics\n -----------\n You don't exist. Go away!::\ndiff --git a/cache.h b/cache.h\nindex 96840c7..311cfe1 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -750,6 +750,7 @@ extern const char *git_author_info(int);\n extern const char *git_committer_info(int);\n extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int);\n extern const char *fmt_name(const char *name, const char *email);\n+extern const char *git_editor(void);\n \n struct checkout {\n \tconst char *base_dir;\ndiff --git a/editor.c b/editor.c\nindex 3f13751..70618f1 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -2,7 +2,7 @@\n #include \"strbuf.h\"\n #include \"run-command.h\"\n \n-int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)\n+const char *git_editor(void)\n {\n \tconst char *editor = getenv(\"GIT_EDITOR\");\n \tconst char *terminal = getenv(\"TERM\");\n@@ -16,11 +16,21 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en\n \t\teditor = getenv(\"EDITOR\");\n \n \tif (!editor && terminal_is_dumb)\n-\t\treturn error(\"terminal is dumb, but EDITOR unset\");\n+\t\treturn NULL;\n \n \tif (!editor)\n \t\teditor = \"vi\";\n \n+\treturn editor;\n+}\n+\n+int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)\n+{\n+\tconst char *editor = git_editor();\n+\n+\tif (!editor)\n+\t\treturn error(\"Terminal is dumb, but EDITOR unset\");\n+\n \tif (strcmp(editor, \":\")) {\n \t\tsize_t len = strlen(editor);\n \t\tint i = 0;\ndiff --git a/var.c b/var.c\nindex dacbaab..b502487 100644\n--- a/var.c\n+++ b/var.c\n@@ -8,6 +8,16 @@\n \n static const char var_usage[] = \"git var [-l | <variable>]\";\n \n+static const char *editor(int flag)\n+{\n+\tconst char *pgm = git_editor();\n+\n+\tif (!pgm && flag & IDENT_ERROR_ON_NO_NAME)\n+\t\tdie(\"Terminal is dumb, but EDITOR unset\");\n+\n+\treturn pgm;\n+}\n+\n struct git_var {\n \tconst char *name;\n \tconst char *(*read)(int);\n@@ -15,14 +25,18 @@ struct git_var {\n static struct git_var git_vars[] = {\n \t{ \"GIT_COMMITTER_IDENT\", git_committer_info },\n \t{ \"GIT_AUTHOR_IDENT\",   git_author_info },\n+\t{ \"GIT_EDITOR\", editor },\n \t{ \"\", NULL },\n };\n \n static void list_vars(void)\n {\n \tstruct git_var *ptr;\n+\tconst char *val;\n+\n \tfor (ptr = git_vars; ptr->read; ptr++)\n-\t\tprintf(\"%s=%s\\n\", ptr->name, ptr->read(0));\n+\t\tif ((val = ptr->read(0)))\n+\t\t\tprintf(\"%s=%s\\n\", ptr->name, val);\n }\n \n static const char *read_var(const char *var)\n-- \n1.6.5.2\n"},{"id":"127401","messageId":"20091112000208.GF1140@progeny.tock","threadId":"21405","inReplyTo":"20091111235100.GA1140@progeny.tock","subject":"[PATCH 5/9] Teach git var about GIT_PAGER","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-11-12T00:02:09Z","receivedAt":"2009-11-12T00:02:09Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Expose the command found by setup_pager() for scripts to use.\nScripts can use this to avoid repeating the logic to look for a\nproper pager in each command.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\nThe rest of the series is unchanged from pu.\n\n Documentation/git-var.txt |    6 ++++++\n cache.h                   |    1 +\n pager.c                   |   18 +++++++++++++++---\n var.c                     |   10 ++++++++++\n 4 files changed, 32 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-var.txt b/Documentation/git-var.txt\nindex 89e4b4f..ef6aa81 100644\n--- a/Documentation/git-var.txt\n+++ b/Documentation/git-var.txt\n@@ -44,6 +44,12 @@ GIT_EDITOR::\n     environment variable, then `core.editor` configuration, then\n     `$VISUAL`, then `$EDITOR`, and then finally 'vi'.\n \n+GIT_PAGER::\n+    Text viewer for use by git commands (e.g., 'less').  The value\n+    is meant to be interpreted by the shell.  The order of preference\n+    is the `$GIT_PAGER` environment variable, then `core.pager`\n+    configuration, then `$PAGER`, and then finally 'less'.\n+\n Diagnostics\n -----------\n You don't exist. Go away!::\ndiff --git a/cache.h b/cache.h\nindex 311cfe1..5aaa4ba 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -751,6 +751,7 @@ extern const char *git_committer_info(int);\n extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int);\n extern const char *fmt_name(const char *name, const char *email);\n extern const char *git_editor(void);\n+extern const char *git_pager(void);\n \n struct checkout {\n \tconst char *base_dir;\ndiff --git a/pager.c b/pager.c\nindex 86facec..0b63d99 100644\n--- a/pager.c\n+++ b/pager.c\n@@ -44,12 +44,14 @@ static void wait_for_pager_signal(int signo)\n \traise(signo);\n }\n \n-void setup_pager(void)\n+const char *git_pager(void)\n {\n-\tconst char *pager = getenv(\"GIT_PAGER\");\n+\tconst char *pager;\n \n \tif (!isatty(1))\n-\t\treturn;\n+\t\treturn NULL;\n+\n+\tpager = getenv(\"GIT_PAGER\");\n \tif (!pager) {\n \t\tif (!pager_program)\n \t\t\tgit_config(git_default_config, NULL);\n@@ -60,6 +62,16 @@ void setup_pager(void)\n \tif (!pager)\n \t\tpager = \"less\";\n \telse if (!*pager || !strcmp(pager, \"cat\"))\n+\t\tpager = NULL;\n+\n+\treturn pager;\n+}\n+\n+void setup_pager(void)\n+{\n+\tconst char *pager = git_pager();\n+\n+\tif (!pager)\n \t\treturn;\n \n \tspawned_pager = 1; /* means we are emitting to terminal */\ndiff --git a/var.c b/var.c\nindex b502487..d9892f8 100644\n--- a/var.c\n+++ b/var.c\n@@ -18,6 +18,15 @@ static const char *editor(int flag)\n \treturn pgm;\n }\n \n+static const char *pager(int flag)\n+{\n+\tconst char *pgm = git_pager();\n+\n+\tif (!pgm)\n+\t\tpgm = \"cat\";\n+\treturn pgm;\n+}\n+\n struct git_var {\n \tconst char *name;\n \tconst char *(*read)(int);\n@@ -26,6 +35,7 @@ static struct git_var git_vars[] = {\n \t{ \"GIT_COMMITTER_IDENT\", git_committer_info },\n \t{ \"GIT_AUTHOR_IDENT\",   git_author_info },\n \t{ \"GIT_EDITOR\", editor },\n+\t{ \"GIT_PAGER\", pager },\n \t{ \"\", NULL },\n };\n \n-- \n1.6.5.2\n"},{"id":"127402","messageId":"20091112000236.GG1140@progeny.tock","threadId":"21405","inReplyTo":"20091111235100.GA1140@progeny.tock","subject":"[PATCH 6/9] add -i, send-email, svn, p4, etc: use \"git var GIT_EDITOR\"","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-11-12T00:02:36Z","receivedAt":"2009-11-12T00:02:36Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Use the new \"git var GIT_EDITOR\" feature to decide what editor to\nuse, instead of duplicating its logic elsewhere.  This should make\nthe behavior of commands in edge cases (e.g., editor names with\nspaces) a little more consistent.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\nUnchanged from pu.\n\n Documentation/config.txt         |    4 +---\n Documentation/git-commit.txt     |    2 +-\n Documentation/git-send-email.txt |    4 ++--\n contrib/fast-import/git-p4       |    5 +----\n git-add--interactive.perl        |    3 +--\n git-send-email.perl              |    3 ++-\n git-sh-setup.sh                  |   19 ++++++-------------\n git-svn.perl                     |    5 ++---\n 8 files changed, 16 insertions(+), 29 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex d1e2120..5181b77 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -387,9 +387,7 @@ core.editor::\n \tCommands such as `commit` and `tag` that lets you edit\n \tmessages by launching an editor uses the value of this\n \tvariable when it is set, and the environment variable\n-\t`GIT_EDITOR` is not set.  The order of preference is\n-\t`GIT_EDITOR` environment, `core.editor`, `VISUAL` and\n-\t`EDITOR` environment variables and then finally `vi`.\n+\t`GIT_EDITOR` is not set.  See linkgit:git-var[1].\n \n core.pager::\n \tThe command that git will use to paginate output.  Can\ndiff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt\nindex 0578a40..3ea80c8 100644\n--- a/Documentation/git-commit.txt\n+++ b/Documentation/git-commit.txt\n@@ -323,7 +323,7 @@ ENVIRONMENT AND CONFIGURATION VARIABLES\n The editor used to edit the commit log message will be chosen from the\n GIT_EDITOR environment variable, the core.editor configuration variable, the\n VISUAL environment variable, or the EDITOR environment variable (in that\n-order).\n+order).  See linkgit:git-var[1] for details.\n \n HOOKS\n -----\ndiff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt\nindex 767cf4d..c85d7f4 100644\n--- a/Documentation/git-send-email.txt\n+++ b/Documentation/git-send-email.txt\n@@ -60,8 +60,8 @@ The --bcc option must be repeated for each user you want on the bcc list.\n The --cc option must be repeated for each user you want on the cc list.\n \n --compose::\n-\tUse $GIT_EDITOR, core.editor, $VISUAL, or $EDITOR to edit an\n-\tintroductory message for the patch series.\n+\tInvoke a text editor (see GIT_EDITOR in linkgit:git-var[1])\n+\tto edit an introductory message for the patch series.\n +\n When '--compose' is used, git send-email will use the From, Subject, and\n In-Reply-To headers specified in the message. If the body of the message\ndiff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4\nindex e710219..48059d0 100755\n--- a/contrib/fast-import/git-p4\n+++ b/contrib/fast-import/git-p4\n@@ -729,13 +729,10 @@ class P4Submit(Command):\n             tmpFile.write(submitTemplate + separatorLine + diff + newdiff)\n             tmpFile.close()\n             mtime = os.stat(fileName).st_mtime\n-            defaultEditor = \"vi\"\n-            if platform.system() == \"Windows\":\n-                defaultEditor = \"notepad\"\n             if os.environ.has_key(\"P4EDITOR\"):\n                 editor = os.environ.get(\"P4EDITOR\")\n             else:\n-                editor = os.environ.get(\"EDITOR\", defaultEditor);\n+                editor = read_pipe(\"git var GIT_EDITOR\")\n             system(editor + \" \" + fileName)\n \n             response = \"y\"\ndiff --git a/git-add--interactive.perl b/git-add--interactive.perl\nindex 69aeaf0..0c74e5c 100755\n--- a/git-add--interactive.perl\n+++ b/git-add--interactive.perl\n@@ -987,8 +987,7 @@ sub edit_hunk_manually {\n EOF\n \tclose $fh;\n \n-\tmy $editor = $ENV{GIT_EDITOR} || $repo->config(\"core.editor\")\n-\t\t|| $ENV{VISUAL} || $ENV{EDITOR} || \"vi\";\n+\tchomp(my $editor = run_cmd_pipe(qw(git var GIT_EDITOR)));\n \tsystem('sh', '-c', $editor.' \"$@\"', $editor, $hunkfile);\n \n \tif ($? != 0) {\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex a0279de..4f5da4e 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -162,7 +162,8 @@ my $compose_filename;\n \n # Handle interactive edition of files.\n my $multiedit;\n-my $editor = $ENV{GIT_EDITOR} || Git::config(@repo, \"core.editor\") || $ENV{VISUAL} || $ENV{EDITOR} || \"vi\";\n+my $editor = Git::command_oneline('var', 'GIT_EDITOR');\n+\n sub do_edit {\n \tif (defined($multiedit) && !$multiedit) {\n \t\tmap {\ndiff --git a/git-sh-setup.sh b/git-sh-setup.sh\nindex c41c2f7..99cceeb 100755\n--- a/git-sh-setup.sh\n+++ b/git-sh-setup.sh\n@@ -99,19 +99,12 @@ set_reflog_action() {\n }\n \n git_editor() {\n-\t: \"${GIT_EDITOR:=$(git config core.editor)}\"\n-\t: \"${GIT_EDITOR:=${VISUAL:-${EDITOR}}}\"\n-\tcase \"$GIT_EDITOR,$TERM\" in\n-\t,dumb)\n-\t\techo >&2 \"No editor specified in GIT_EDITOR, core.editor, VISUAL,\"\n-\t\techo >&2 \"or EDITOR. Tried to fall back to vi but terminal is dumb.\"\n-\t\techo >&2 \"Please set one of these variables to an appropriate\"\n-\t\techo >&2 \"editor or run $0 with options that will not cause an\"\n-\t\techo >&2 \"editor to be invoked (e.g., -m or -F for git-commit).\"\n-\t\texit 1\n-\t\t;;\n-\tesac\n-\teval \"${GIT_EDITOR:=vi}\" '\"$@\"'\n+\tif test -z \"${GIT_EDITOR:+set}\"\n+\tthen\n+\t\tGIT_EDITOR=\"$(git var GIT_EDITOR)\" || return $?\n+\tfi\n+\n+\teval \"$GIT_EDITOR\" '\"$@\"'\n }\n \n is_bare_repository () {\ndiff --git a/git-svn.perl b/git-svn.perl\nindex 6a3b501..42c9a72 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -1321,9 +1321,8 @@ sub get_commit_entry {\n \tclose $log_fh or croak $!;\n \n \tif ($_edit || ($type eq 'tree')) {\n-\t\tmy $editor = $ENV{VISUAL} || $ENV{EDITOR} || 'vi';\n-\t\t# TODO: strip out spaces, comments, like git-commit.sh\n-\t\tsystem($editor, $commit_editmsg);\n+\t\tchomp(my $editor = command_oneline(qw(var GIT_EDITOR)));\n+\t\tsystem('sh', '-c', $editor.' \"$@\"', $editor, $commit_editmsg);\n \t}\n \trename $commit_editmsg, $commit_msg or croak $!;\n \t{\n-- \n1.6.5.2\n"},{"id":"127403","messageId":"20091112000303.GH1140@progeny.tock","threadId":"21405","inReplyTo":"20091111235100.GA1140@progeny.tock","subject":"[PATCH 7/9] am -i, git-svn: use \"git var GIT_PAGER\"","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-11-12T00:03:04Z","receivedAt":"2009-11-12T00:03:04Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Use the new \"git var GIT_PAGER\" command to ask what pager to use.\n\nWithout this change, the core.pager configuration is ignored by\nthese commands.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\nUnchanged.\n\n git-am.sh    |    5 ++++-\n git-svn.perl |    6 ++----\n 2 files changed, 6 insertions(+), 5 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex c132f50..2649487 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -649,7 +649,10 @@ do\n \t\t[eE]*) git_editor \"$dotest/final-commit\"\n \t\t       action=again ;;\n \t\t[vV]*) action=again\n-\t\t       LESS=-S ${PAGER:-less} \"$dotest/patch\" ;;\n+\t\t       : ${GIT_PAGER=$(git var GIT_PAGER)}\n+\t\t       : ${LESS=-FRSX}\n+\t\t       export LESS\n+\t\t       $GIT_PAGER \"$dotest/patch\" ;;\n \t\t*)     action=again ;;\n \t\tesac\n \t    done\ndiff --git a/git-svn.perl b/git-svn.perl\nindex 42c9a72..c4ca548 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -5171,10 +5171,8 @@ sub git_svn_log_cmd {\n \n # adapted from pager.c\n sub config_pager {\n-\t$pager ||= $ENV{GIT_PAGER} || $ENV{PAGER};\n-\tif (!defined $pager) {\n-\t\t$pager = 'less';\n-\t} elsif (length $pager == 0 || $pager eq 'cat') {\n+\tchomp(my $pager = command_oneline(qw(var GIT_PAGER)));\n+\tif ($pager eq 'cat') {\n \t\t$pager = undef;\n \t}\n \t$ENV{GIT_PAGER_IN_USE} = defined($pager);\n-- \n1.6.5.2\n"},{"id":"127404","messageId":"20091112000355.GI1140@progeny.tock","threadId":"21405","inReplyTo":"20091111235100.GA1140@progeny.tock","subject":"[PATCH 8/9] Provide a build time default-editor setting","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-11-12T00:03:55Z","receivedAt":"2009-11-12T00:03:55Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Provide a DEFAULT_EDITOR knob to allow setting the fallback\neditor to use instead of vi (when VISUAL, EDITOR, and GIT_EDITOR\nare unset).  The value can be set at build time according to a\nsystem’s policy.  For example, on Debian systems, the default\neditor should be the 'editor' command.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Ben Walton <bwalton@artsci.utoronto.ca>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\nUnchanged.\n\n Makefile          |   17 +++++++++++++++++\n editor.c          |    6 +++++-\n t/t7005-editor.sh |   37 +++++++++++++++++++++++++------------\n 3 files changed, 47 insertions(+), 13 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 268aede..625866c 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -200,6 +200,14 @@ all::\n # memory allocators with the nedmalloc allocator written by Niall Douglas.\n #\n # Define NO_REGEX if you have no or inferior regex support in your C library.\n+#\n+# Define DEFAULT_EDITOR to a sensible editor command (defaults to \"vi\") if you\n+# want to use something different.  The value will be interpreted by the shell\n+# if necessary when it is used.  Examples:\n+#\n+#   DEFAULT_EDITOR='~/bin/vi',\n+#   DEFAULT_EDITOR='$GIT_FALLBACK_EDITOR',\n+#   DEFAULT_EDITOR='\"C:\\Program Files\\Vim\\gvim.exe\" --nofork'\n \n GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE\n \t@$(SHELL_PATH) ./GIT-VERSION-GEN\n@@ -1363,6 +1371,15 @@ BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' \\\n \t$(COMPAT_CFLAGS)\n LIB_OBJS += $(COMPAT_OBJS)\n \n+# Quote for C\n+\n+ifdef DEFAULT_EDITOR\n+DEFAULT_EDITOR_CQ = \"$(subst \",\\\",$(subst \\,\\\\,$(DEFAULT_EDITOR)))\"\n+DEFAULT_EDITOR_CQ_SQ = $(subst ','\\'',$(DEFAULT_EDITOR_CQ))\n+\n+BASIC_CFLAGS += -DDEFAULT_EDITOR='$(DEFAULT_EDITOR_CQ_SQ)'\n+endif\n+\n ALL_CFLAGS += $(BASIC_CFLAGS)\n ALL_LDFLAGS += $(BASIC_LDFLAGS)\n \ndiff --git a/editor.c b/editor.c\nindex 70618f1..615f575 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -2,6 +2,10 @@\n #include \"strbuf.h\"\n #include \"run-command.h\"\n \n+#ifndef DEFAULT_EDITOR\n+#define DEFAULT_EDITOR \"vi\"\n+#endif\n+\n const char *git_editor(void)\n {\n \tconst char *editor = getenv(\"GIT_EDITOR\");\n@@ -19,7 +23,7 @@ const char *git_editor(void)\n \t\treturn NULL;\n \n \tif (!editor)\n-\t\teditor = \"vi\";\n+\t\teditor = DEFAULT_EDITOR;\n \n \treturn editor;\n }\ndiff --git a/t/t7005-editor.sh b/t/t7005-editor.sh\nindex a95fe19..5257f4d 100755\n--- a/t/t7005-editor.sh\n+++ b/t/t7005-editor.sh\n@@ -4,7 +4,21 @@ test_description='GIT_EDITOR, core.editor, and stuff'\n \n . ./test-lib.sh\n \n-for i in GIT_EDITOR core_editor EDITOR VISUAL vi\n+unset EDITOR VISUAL GIT_EDITOR\n+\n+test_expect_success 'determine default editor' '\n+\n+\tvi=$(TERM=vt100 git var GIT_EDITOR) &&\n+\ttest -n \"$vi\"\n+\n+'\n+\n+if ! expr \"$vi\" : '^[a-z]*$' >/dev/null\n+then\n+\tvi=\n+fi\n+\n+for i in GIT_EDITOR core_editor EDITOR VISUAL $vi\n do\n \tcat >e-$i.sh <<-EOF\n \t#!$SHELL_PATH\n@@ -12,19 +26,18 @@ do\n \tEOF\n \tchmod +x e-$i.sh\n done\n-unset vi\n-mv e-vi.sh vi\n-unset EDITOR VISUAL GIT_EDITOR\n+\n+if ! test -z \"$vi\"\n+then\n+\tmv e-$vi.sh $vi\n+fi\n \n test_expect_success setup '\n \n-\tmsg=\"Hand edited\" &&\n+\tmsg=\"Hand-edited\" &&\n+\ttest_commit \"$msg\" &&\n \techo \"$msg\" >expect &&\n-\tgit add vi &&\n-\ttest_tick &&\n-\tgit commit -m \"$msg\" &&\n-\tgit show -s --pretty=oneline |\n-\tsed -e \"s/^[0-9a-f]* //\" >actual &&\n+\tgit show -s --format=%s > actual &&\n \tdiff actual expect\n \n '\n@@ -54,7 +67,7 @@ test_expect_success 'dumb should prefer EDITOR to VISUAL' '\n \n TERM=vt100\n export TERM\n-for i in vi EDITOR VISUAL core_editor GIT_EDITOR\n+for i in $vi EDITOR VISUAL core_editor GIT_EDITOR\n do\n \techo \"Edited by $i\" >expect\n \tunset EDITOR VISUAL GIT_EDITOR\n@@ -78,7 +91,7 @@ done\n \n unset EDITOR VISUAL GIT_EDITOR\n git config --unset-all core.editor\n-for i in vi EDITOR VISUAL core_editor GIT_EDITOR\n+for i in $vi EDITOR VISUAL core_editor GIT_EDITOR\n do\n \techo \"Edited by $i\" >expect\n \tcase \"$i\" in\n-- \n1.6.5.2\n"},{"id":"127405","messageId":"20091112000422.GJ1140@progeny.tock","threadId":"21405","inReplyTo":"20091111235100.GA1140@progeny.tock","subject":"[PATCH 9/9] Provide a build time default-pager setting","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2009-11-12T00:04:22Z","receivedAt":"2009-11-12T00:04:22Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Provide a DEFAULT_PAGER knob so packagers can set the fallback\npager to something appropriate during the build.\n\nExamples:\n\nOn (old) solaris systems, /usr/bin/less (typically the first less\nfound) doesn't understand the default arguments (FXRS), which\nforces users to alter their environment (PATH, GIT_PAGER, LESS,\netc) or have a local or global gitconfig before paging works as\nexpected.\n\nOn Debian systems, by policy packages must fall back to the\n'pager' command, so that changing the target of the\n/usr/bin/pager symlink changes the default pager for all packages\nat once.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Ben Walton <bwalton@artsci.utoronto.ca>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\nAs in pu.\n\n Makefile |   11 +++++++++++\n pager.c  |    6 +++++-\n 2 files changed, 16 insertions(+), 1 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 625866c..18fc50a 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -201,6 +201,10 @@ all::\n #\n # Define NO_REGEX if you have no or inferior regex support in your C library.\n #\n+# Define DEFAULT_PAGER to a sensible pager command (defaults to \"less\") if\n+# you want to use something different.  The value will be interpreted by the\n+# shell at runtime when it is used.\n+#\n # Define DEFAULT_EDITOR to a sensible editor command (defaults to \"vi\") if you\n # want to use something different.  The value will be interpreted by the shell\n # if necessary when it is used.  Examples:\n@@ -1380,6 +1384,13 @@ DEFAULT_EDITOR_CQ_SQ = $(subst ','\\'',$(DEFAULT_EDITOR_CQ))\n BASIC_CFLAGS += -DDEFAULT_EDITOR='$(DEFAULT_EDITOR_CQ_SQ)'\n endif\n \n+ifdef DEFAULT_PAGER\n+DEFAULT_PAGER_CQ = \"$(subst \",\\\",$(subst \\,\\\\,$(DEFAULT_PAGER)))\"\n+DEFAULT_PAGER_CQ_SQ = $(subst ','\\'',$(DEFAULT_PAGER_CQ))\n+\n+BASIC_CFLAGS += -DDEFAULT_PAGER='$(DEFAULT_PAGER_CQ_SQ)'\n+endif\n+\n ALL_CFLAGS += $(BASIC_CFLAGS)\n ALL_LDFLAGS += $(BASIC_LDFLAGS)\n \ndiff --git a/pager.c b/pager.c\nindex 0b63d99..92c03f6 100644\n--- a/pager.c\n+++ b/pager.c\n@@ -2,6 +2,10 @@\n #include \"run-command.h\"\n #include \"sigchain.h\"\n \n+#ifndef DEFAULT_PAGER\n+#define DEFAULT_PAGER \"less\"\n+#endif\n+\n /*\n  * This is split up from the rest of git so that we can do\n  * something different on Windows.\n@@ -60,7 +64,7 @@ const char *git_pager(void)\n \tif (!pager)\n \t\tpager = getenv(\"PAGER\");\n \tif (!pager)\n-\t\tpager = \"less\";\n+\t\tpager = DEFAULT_PAGER;\n \telse if (!*pager || !strcmp(pager, \"cat\"))\n \t\tpager = NULL;\n \n-- \n1.6.5.2\n"},{"id":"127588","messageId":"7vk4xsrwek.fsf@alter.siamese.dyndns.org","threadId":"21405","inReplyTo":"20091111235100.GA1140@progeny.tock","subject":"Re: [PATCH v4 0/9] Default pager and editor","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-11-15T09:04:51Z","receivedAt":"2009-11-15T09:04:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks, re-queued.\n\nI've been sick and in bed for the past few days, so apologies for a late\nreply.\n"}]}