@matheusbsbs / matheus-bagliano / commits / 8f4b576ad1
Fork 0

Provide a build time default-editor setting

Provide a DEFAULT_EDITOR knob to allow setting the fallback editor to use instead of vi (when VISUAL, EDITOR, and GIT_EDITOR are unset). The value can be set at build time according to a system’s policy. For example, on Debian systems, the default editor should be the 'editor' command. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Ben Walton <bwalton@artsci.utoronto.ca> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Oct 30, 2009 at 20:44 UTC 8f4b576ad14943a7b14cb8937eb321b7bfd91ee7
3 files changed +47 -13
Makefile
+17
@@ -200,6 +200,14 @@ all::
200 # memory allocators with the nedmalloc allocator written by Niall Douglas.
201 #
202 # Define NO_REGEX if you have no or inferior regex support in your C library.
203 +#
204 +# Define DEFAULT_EDITOR to a sensible editor command (defaults to "vi") if you
205 +# want to use something different. The value will be interpreted by the shell
206 +# if necessary when it is used. Examples:
207 +#
208 +# DEFAULT_EDITOR='~/bin/vi',
209 +# DEFAULT_EDITOR='$GIT_FALLBACK_EDITOR',
210 +# DEFAULT_EDITOR='"C:\Program Files\Vim\gvim.exe" --nofork'
211
212 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
213 @$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -1363,6 +1371,15 @@ BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' \
1371 $(COMPAT_CFLAGS)
1372 LIB_OBJS += $(COMPAT_OBJS)
1373
1374 +# Quote for C
1375 +
1376 +ifdef DEFAULT_EDITOR
1377 +DEFAULT_EDITOR_CQ = "$(subst ",\",$(subst \,\\,$(DEFAULT_EDITOR)))"
1378 +DEFAULT_EDITOR_CQ_SQ = $(subst ','\'',$(DEFAULT_EDITOR_CQ))
1379 +
1380 +BASIC_CFLAGS += -DDEFAULT_EDITOR='$(DEFAULT_EDITOR_CQ_SQ)'
1381 +endif
1382 +
1383 ALL_CFLAGS += $(BASIC_CFLAGS)
1384 ALL_LDFLAGS += $(BASIC_LDFLAGS)
1385
editor.c
+5 -1
@@ -2,6 +2,10 @@
2 #include "strbuf.h"
3 #include "run-command.h"
4
5 +#ifndef DEFAULT_EDITOR
6 +#define DEFAULT_EDITOR "vi"
7 +#endif
8 +
9 const char *git_editor(void)
10 {
11 const char *editor = getenv("GIT_EDITOR");
@@ -19,7 +23,7 @@ const char *git_editor(void)
23 return NULL;
24
25 if (!editor)
22 - editor = "vi";
26 + editor = DEFAULT_EDITOR;
27
28 return editor;
29 }
t/t7005-editor.sh
+25 -12
@@ -4,7 +4,21 @@ test_description='GIT_EDITOR, core.editor, and stuff'
4
5 . ./test-lib.sh
6
7 -for i in GIT_EDITOR core_editor EDITOR VISUAL vi
7 +unset EDITOR VISUAL GIT_EDITOR
8 +
9 +test_expect_success 'determine default editor' '
10 +
11 + vi=$(TERM=vt100 git var GIT_EDITOR) &&
12 + test -n "$vi"
13 +
14 +'
15 +
16 +if ! expr "$vi" : '^[a-z]*$' >/dev/null
17 +then
18 + vi=
19 +fi
20 +
21 +for i in GIT_EDITOR core_editor EDITOR VISUAL $vi
22 do
23 cat >e-$i.sh <<-EOF
24 #!$SHELL_PATH
@@ -12,19 +26,18 @@ do
26 EOF
27 chmod +x e-$i.sh
28 done
15 -unset vi
16 -mv e-vi.sh vi
17 -unset EDITOR VISUAL GIT_EDITOR
29 +
30 +if ! test -z "$vi"
31 +then
32 + mv e-$vi.sh $vi
33 +fi
34
35 test_expect_success setup '
36
21 - msg="Hand edited" &&
37 + msg="Hand-edited" &&
38 + test_commit "$msg" &&
39 echo "$msg" >expect &&
23 - git add vi &&
24 - test_tick &&
25 - git commit -m "$msg" &&
26 - git show -s --pretty=oneline |
27 - sed -e "s/^[0-9a-f]* //" >actual &&
40 + git show -s --format=%s > actual &&
41 diff actual expect
42
43 '
@@ -54,7 +67,7 @@ test_expect_success 'dumb should prefer EDITOR to VISUAL' '
67
68 TERM=vt100
69 export TERM
57 -for i in vi EDITOR VISUAL core_editor GIT_EDITOR
70 +for i in $vi EDITOR VISUAL core_editor GIT_EDITOR
71 do
72 echo "Edited by $i" >expect
73 unset EDITOR VISUAL GIT_EDITOR
@@ -78,7 +91,7 @@ done
91
92 unset EDITOR VISUAL GIT_EDITOR
93 git config --unset-all core.editor
81 -for i in vi EDITOR VISUAL core_editor GIT_EDITOR
94 +for i in $vi EDITOR VISUAL core_editor GIT_EDITOR
95 do
96 echo "Edited by $i" >expect
97 case "$i" in