git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH/RFC 2/2] Provide a build time default-editor setting

From
David Roundy <roundyd@physics.oregonstate.edu>
Date
Oct 29, 2009, 10:36 UTC
Message-ID
<117f2cc80910290336k1e7b5877uc472ad511bb6f5ae@mail.gmail.com>
In-Reply-To
<20091029075021.GC15403@progeny.tock>

Any chance this will be exported as plumbing? I know it's pretty high-level, but it'd be handy to have be able to write `git editor $FILENAME` and just have it do the right thing. This would also mean that the perl scripts below could be simplified.

Same goes for pager, of course...
David
On Thu, Oct 29, 2009 at 3:50 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:
Show 244 quoted lines
> Provide a DEFAULT_EDITOR knob to allow the fallback editor (to
> use instead of vi if VISUAL, EDITOR, and GIT_EDITOR are unset) to
> be set at build time according to a system’s policy.  For
> example, on Debian systems, the default editor should be the
> 'editor' command.
>
> The contrib/fast-import/git-p4 script still uses vi, since it is
> not modified by the Makefile currently, and making it require
> build-time modification would create too much trouble for people
> deploying that script.
>
> This change makes t7005-editor into a mess.  Any ideas for fixing
> this?
>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
> ---
>  Makefile                  |   10 ++++++++++
>  editor.c                  |    2 +-
>  git-add--interactive.perl |    3 ++-
>  git-sh-setup.sh           |    6 ++++--
>  git-svn.perl              |    5 +++--
>  t/Makefile                |    2 ++
>  t/t7005-editor.sh         |   29 ++++++++++++++++++++++-------
>  7 files changed, 44 insertions(+), 13 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index fc1a461..fae8647 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -203,6 +203,9 @@ all::
>  #
>  # Define DEFAULT_PAGER to the path of a sensible pager (defaults to "less") if
>  # you want to use something different.
> +#
> +# Define DEFAULT_EDITOR to a sensible editor command (defaults to "vi") if you
> +# want to use something different.
>
>  GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
>        @$(SHELL_PATH) ./GIT-VERSION-GEN
> @@ -1301,6 +1304,11 @@ ifndef DEFAULT_PAGER
>        DEFAULT_PAGER = less
>  endif
>  BASIC_CFLAGS += -DDEFAULT_PAGER='"$(DEFAULT_PAGER)"'
> +ifndef DEFAULT_EDITOR
> +       DEFAULT_EDITOR = vi
> +endif
> +export DEFAULT_EDITOR
> +BASIC_CFLAGS += -DDEFAULT_EDITOR='"$(DEFAULT_EDITOR)"'
>
>  ifdef USE_NED_ALLOCATOR
>        COMPAT_CFLAGS += -DUSE_NED_ALLOCATOR -DOVERRIDE_STRDUP -DNDEBUG -DREPLACE_SYSTEM_ALLOCATOR -Icompat/nedmalloc
> @@ -1435,6 +1443,7 @@ $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
>            -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
>            -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
>            -e 's/@@NO_CURL@@/$(NO_CURL)/g' \
> +           -e 's|DEFAULT_EDITOR:=vi|DEFAULT_EDITOR:=$(DEFAULT_EDITOR)|' \
>            -e $(BROKEN_PATH_FIX) \
>            $@.sh >$@+ && \
>        chmod +x $@+ && \
> @@ -1459,6 +1468,7 @@ $(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl
>            -e 's|@@INSTLIBDIR@@|'"$$INSTLIBDIR"'|g' \
>            -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
>            -e 's/@@DEFAULT_PAGER@@/$(DEFAULT_PAGER)/g' \
> +           -e 's/@@DEFAULT_EDITOR@@/$(DEFAULT_EDITOR)/g' \
>            $@.perl >$@+ && \
>        chmod +x $@+ && \
>        mv $@+ $@
> diff --git a/editor.c b/editor.c
> index 4d469d0..93b8cbb 100644
> --- a/editor.c
> +++ b/editor.c
> @@ -19,7 +19,7 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
>                return error("Terminal is dumb but no VISUAL nor EDITOR defined.");
>
>        if (!editor)
> -               editor = "vi";
> +               editor = DEFAULT_EDITOR;
>
>        if (strcmp(editor, ":")) {
>                size_t len = strlen(editor);
> diff --git a/git-add--interactive.perl b/git-add--interactive.perl
> index 69aeaf0..c3d932c 100755
> --- a/git-add--interactive.perl
> +++ b/git-add--interactive.perl
> @@ -1,6 +1,7 @@
>  #!/usr/bin/perl -w
>
>  use strict;
> +use constant DEFAULT_EDITOR => '@@DEFAULT_EDITOR@@';
>  use Git;
>
>  binmode(STDOUT, ":raw");
> @@ -988,7 +989,7 @@ EOF
>        close $fh;
>
>        my $editor = $ENV{GIT_EDITOR} || $repo->config("core.editor")
> -               || $ENV{VISUAL} || $ENV{EDITOR} || "vi";
> +               || $ENV{VISUAL} || $ENV{EDITOR} || DEFAULT_EDITOR;
>        system('sh', '-c', $editor.' "$@"', $editor, $hunkfile);
>
>        if ($? != 0) {
> diff --git a/git-sh-setup.sh b/git-sh-setup.sh
> index c41c2f7..d053d56 100755
> --- a/git-sh-setup.sh
> +++ b/git-sh-setup.sh
> @@ -99,19 +99,21 @@ set_reflog_action() {
>  }
>
>  git_editor() {
> +       : "${DEFAULT_EDITOR:=vi}"
>        : "${GIT_EDITOR:=$(git config core.editor)}"
>        : "${GIT_EDITOR:=${VISUAL:-${EDITOR}}}"
>        case "$GIT_EDITOR,$TERM" in
>        ,dumb)
>                echo >&2 "No editor specified in GIT_EDITOR, core.editor, VISUAL,"
> -               echo >&2 "or EDITOR. Tried to fall back to vi but terminal is dumb."
> +               echo >&2 "or EDITOR. Tried to fall back to $DEFAULT_EDITOR" \
> +                       "but terminal is dumb."
>                echo >&2 "Please set one of these variables to an appropriate"
>                echo >&2 "editor or run $0 with options that will not cause an"
>                echo >&2 "editor to be invoked (e.g., -m or -F for git-commit)."
>                exit 1
>                ;;
>        esac
> -       eval "${GIT_EDITOR:=vi}" '"$@"'
> +       eval "${GIT_EDITOR:=$DEFAULT_EDITOR}" '"$@"'
>  }
>
>  is_bare_repository () {
> diff --git a/git-svn.perl b/git-svn.perl
> index c270b23..b98d378 100755
> --- a/git-svn.perl
> +++ b/git-svn.perl
> @@ -3,12 +3,13 @@
>  # License: GPL v2 or later
>  use warnings;
>  use strict;
> -use vars qw/   $AUTHOR $VERSION $DEFAULT_PAGER
> +use vars qw/   $AUTHOR $VERSION $DEFAULT_PAGER $DEFAULT_EDITOR
>                $sha1 $sha1_short $_revision $_repository
>                $_q $_authors $_authors_prog %users/;
>  $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
>  $VERSION = '@@GIT_VERSION@@';
>  $DEFAULT_PAGER = '@@DEFAULT_PAGER@@';
> +$DEFAULT_EDITOR = '@@DEFAULT_EDITOR@@';
>
>  # From which subdir have we been invoked?
>  my $cmd_dir_prefix = eval {
> @@ -1322,7 +1323,7 @@ sub get_commit_entry {
>        close $log_fh or croak $!;
>
>        if ($_edit || ($type eq 'tree')) {
> -               my $editor = $ENV{VISUAL} || $ENV{EDITOR} || 'vi';
> +               my $editor = $ENV{VISUAL} || $ENV{EDITOR} || $DEFAULT_EDITOR;
>                # TODO: strip out spaces, comments, like git-commit.sh
>                system($editor, $commit_editmsg);
>        }
> diff --git a/t/Makefile b/t/Makefile
> index bd09390..9174bbb 100644
> --- a/t/Makefile
> +++ b/t/Makefile
> @@ -9,6 +9,8 @@
>  SHELL_PATH ?= $(SHELL)
>  TAR ?= $(TAR)
>  RM ?= rm -f
> +DEFAULT_EDITOR ?= vi
> +export DEFAULT_EDITOR
>
>  # Shell quote;
>  SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
> diff --git a/t/t7005-editor.sh b/t/t7005-editor.sh
> index b647957..2b76f72 100755
> --- a/t/t7005-editor.sh
> +++ b/t/t7005-editor.sh
> @@ -4,7 +4,18 @@ test_description='GIT_EDITOR, core.editor, and stuff'
>
>  . ./test-lib.sh
>
> -for i in GIT_EDITOR core_editor EDITOR VISUAL vi
> +: ${DEFAULT_EDITOR=vi}
> +
> +unset EDITOR VISUAL GIT_EDITOR
> +
> +case "$DEFAULT_EDITOR" in
> +*/* | [A-Z]*)
> +       DEFAULT_EDITOR=
> +       ;;
> +esac
> +
> +for i in GIT_EDITOR core_editor EDITOR VISUAL \
> +       ${DEFAULT_EDITOR:+"$DEFAULT_EDITOR"}
>  do
>        cat >e-$i.sh <<-EOF
>        #!$SHELL_PATH
> @@ -12,15 +23,17 @@ do
>        EOF
>        chmod +x e-$i.sh
>  done
> -unset vi
> -mv e-vi.sh vi
> -unset EDITOR VISUAL GIT_EDITOR
> +
> +if test -n "$DEFAULT_EDITOR"
> +then
> +       mv "e-$DEFAULT_EDITOR.sh" "$DEFAULT_EDITOR"
> +fi
>
>  test_expect_success setup '
>
>        msg="Hand edited" &&
>        echo "$msg" >expect &&
> -       git add vi &&
> +       git add "e-VISUAL.sh" &&
>        test_tick &&
>        git commit -m "$msg" &&
>        git show -s --pretty=oneline |
> @@ -44,7 +57,8 @@ test_expect_success 'dumb should error out when falling back on vi' '
>
>  TERM=vt100
>  export TERM
> -for i in vi EDITOR VISUAL core_editor GIT_EDITOR
> +for i in ${DEFAULT_EDITOR:+"$DEFAULT_EDITOR"} \
> +       EDITOR VISUAL core_editor GIT_EDITOR
>  do
>        echo "Edited by $i" >expect
>        unset EDITOR VISUAL GIT_EDITOR
> @@ -68,7 +82,8 @@ done
>
>  unset EDITOR VISUAL GIT_EDITOR
>  git config --unset-all core.editor
> -for i in vi EDITOR VISUAL core_editor GIT_EDITOR
> +for i in ${DEFAULT_EDITOR:+"$DEFAULT_EDITOR"} \
> +       EDITOR VISUAL core_editor GIT_EDITOR
>  do
>        echo "Edited by $i" >expect
>        case "$i" in
> --
> 1.6.5.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
-- 
David Roundy
Previous: Jonathan NiederNext: Johannes Sixt
Message 6 of 65 in “packaging vs default pager”
  1. Ben WaltonOct 28, 2009
  2. Junio C HamanoOct 28, 2009
  3. 0/2 Re: packaging vs default pagerJonathan Nieder, Oct 29, 2009
  4. 1/2 Provide a build time default-pager settingJonathan Nieder, Oct 29, 2009
  5. 2/2 Provide a build time default-editor settingJonathan Nieder, Oct 29, 2009
  6. David RoundyOct 29, 2009
  7. Johannes SixtOct 29, 2009
  8. Junio C HamanoOct 29, 2009
  9. Johannes SixtOct 29, 2009
  10. Junio C HamanoOct 29, 2009
  11. David RoundyOct 30, 2009
  12. Junio C HamanoOct 29, 2009
  13. 0/8 Default pager and editorJonathan Nieder, Oct 30, 2009
  14. 1/8 launch_editor: Longer error message when TERM=dumbJonathan Nieder, Oct 30, 2009
  15. 2/8 Handle more shell metacharacters in editor namesJonathan Nieder, Oct 30, 2009
  16. 3/8 Teach git var about GIT_EDITORJonathan Nieder, Oct 30, 2009
  17. Johannes SixtOct 30, 2009
  18. Jonathan NiederOct 30, 2009
  19. Junio C HamanoOct 30, 2009
  20. Jonathan NiederOct 31, 2009
  21. 4/8 Teach git var about GIT_PAGERJonathan Nieder, Oct 30, 2009
  22. 5/8 add -i, send-email, svn, p4, etc: use "git var GIT_EDITOR"Jonathan Nieder, Oct 30, 2009
  23. 6/8 am -i, git-svn: use "git var GIT_PAGER"Jonathan Nieder, Oct 30, 2009
  24. 7/8 Provide a build time default-editor settingJonathan Nieder, Oct 30, 2009
  25. Jonathan NiederOct 30, 2009
  26. 8/8 Provide a build time default-pager settingJonathan Nieder, Oct 30, 2009
  27. Junio C HamanoOct 30, 2009
  28. 9/8 Teach git var to run the editorJonathan Nieder, Oct 30, 2009
  29. 0/8 Default pager and editorJonathan Nieder, Oct 31, 2009
  30. 1/8 Handle more shell metacharacters in editor namesJonathan Nieder, Oct 31, 2009
  31. 2/8 Do not use VISUAL editor on dumb terminalsJonathan Nieder, Oct 31, 2009
  32. 2/8 Do not use VISUAL editor on dumb terminalsJonathan Nieder, Oct 31, 2009
  33. 3/8 Teach git var about GIT_EDITORJonathan Nieder, Oct 31, 2009
  34. Junio C HamanoOct 31, 2009
  35. Jonathan NiederOct 31, 2009
  36. Junio C HamanoOct 31, 2009
  37. Jonathan NiederOct 31, 2009
  38. Teach git var about GIT_EDITORJonathan Nieder, Oct 31, 2009
  39. Jonathan NiederOct 31, 2009
  40. Teach git var about GIT_EDITORJonathan Nieder, Oct 31, 2009
  41. Junio C HamanoNov 1, 2009
  42. Johannes SixtOct 31, 2009
  43. 4/8 Teach git var about GIT_PAGERJonathan Nieder, Oct 31, 2009
  44. 5/8 add -i, send-email, svn, p4, etc: use "git var GIT_EDITOR"Jonathan Nieder, Oct 31, 2009
  45. 6/8 am -i, git-svn: use "git var GIT_PAGER"Jonathan Nieder, Oct 31, 2009
  46. 7/8 Provide a build time default-editor settingJonathan Nieder, Oct 31, 2009
  47. Junio C HamanoOct 31, 2009
  48. Jonathan NiederOct 31, 2009
  49. Junio C HamanoOct 31, 2009
  50. Jonathan NiederOct 31, 2009
  51. Junio C HamanoNov 1, 2009
  52. 8/8 Provide a build time default-pager settingJonathan Nieder, Oct 31, 2009
  53. 0/9 Default pager and editorJonathan Nieder, Nov 11, 2009
  54. 1/9 Handle more shell metacharacters in editor namesJonathan Nieder, Nov 11, 2009
  55. 2/9 Do not use VISUAL editor on dumb terminalsJonathan Nieder, Nov 11, 2009
  56. 3/9 Suppress warnings from "git var -l"Jonathan Nieder, Nov 11, 2009
  57. 4/9 Teach git var about GIT_EDITORJonathan Nieder, Nov 12, 2009
  58. 5/9 Teach git var about GIT_PAGERJonathan Nieder, Nov 12, 2009
  59. 6/9 add -i, send-email, svn, p4, etc: use "git var GIT_EDITOR"Jonathan Nieder, Nov 12, 2009
  60. 7/9 am -i, git-svn: use "git var GIT_PAGER"Jonathan Nieder, Nov 12, 2009
  61. 8/9 Provide a build time default-editor settingJonathan Nieder, Nov 12, 2009
  62. 9/9 Provide a build time default-pager settingJonathan Nieder, Nov 12, 2009
  63. Junio C HamanoNov 15, 2009
  64. 0/2 Default Pager and Editor at build-timeBen Walton, Oct 29, 2009
  65. 1/2 Provide a build time default-pager settingBen Walton, Oct 29, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.