Move launch_editor() from builtin-tag.c to editor.c
launch_editor() is declared in strbuf.h but defined in builtin-tag.c. This patch moves launch_editor() into a new source file editor.c, but keeps the declaration in strbuf.h. Signed-off-by: Stephan Beyer <s-beyer@gmx.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stephan Beyer committed
Jul 25, 2008 at 18:28 UTC
d82f33e20dcf068e679eff2a16ecf8fe7b10fb31
3 files changed
+57
-53
Makefile
+1
@@ -410,6 +410,7 @@ LIB_OBJS += diff-no-index.o
410
LIB_OBJS += diff-lib.o
411
LIB_OBJS += diff.o
412
LIB_OBJS += dir.o
413
+LIB_OBJS += editor.o
414
LIB_OBJS += entry.o
415
LIB_OBJS += environment.o
416
LIB_OBJS += exec_cmd.o
builtin-tag.c
-53
@@ -23,59 +23,6 @@ static const char * const git_tag_usage[] = {
23
24
static char signingkey[1000];
25
26
-void launch_editor(const char *path, struct strbuf *buffer, const char *const *env)
27
-{
28
- const char *editor, *terminal;
29
-
30
- editor = getenv("GIT_EDITOR");
31
- if (!editor && editor_program)
32
- editor = editor_program;
33
- if (!editor)
34
- editor = getenv("VISUAL");
35
- if (!editor)
36
- editor = getenv("EDITOR");
37
-
38
- terminal = getenv("TERM");
39
- if (!editor && (!terminal || !strcmp(terminal, "dumb"))) {
40
- fprintf(stderr,
41
- "Terminal is dumb but no VISUAL nor EDITOR defined.\n"
42
- "Please supply the message using either -m or -F option.\n");
43
- exit(1);
44
- }
45
-
46
- if (!editor)
47
- editor = "vi";
48
-
49
- if (strcmp(editor, ":")) {
50
- size_t len = strlen(editor);
51
- int i = 0;
52
- const char *args[6];
53
- struct strbuf arg0;
54
-
55
- strbuf_init(&arg0, 0);
56
- if (strcspn(editor, "$ \t'") != len) {
57
- /* there are specials */
58
- strbuf_addf(&arg0, "%s \"$@\"", editor);
59
- args[i++] = "sh";
60
- args[i++] = "-c";
61
- args[i++] = arg0.buf;
62
- }
63
- args[i++] = editor;
64
- args[i++] = path;
65
- args[i] = NULL;
66
-
67
- if (run_command_v_opt_cd_env(args, 0, NULL, env))
68
- die("There was a problem with the editor %s.", editor);
69
- strbuf_release(&arg0);
70
- }
71
-
72
- if (!buffer)
73
- return;
74
- if (strbuf_read_file(buffer, path, 0) < 0)
75
- die("could not read message file '%s': %s",
76
- path, strerror(errno));
77
-}
78
-
26
struct tag_filter {
27
const char *pattern;
28
int lines;
editor.c
new
+56
@@ -0,0 +1,56 @@
1
+#include "cache.h"
2
+#include "strbuf.h"
3
+#include "run-command.h"
4
+
5
+void launch_editor(const char *path, struct strbuf *buffer, const char *const *env)
6
+{
7
+ const char *editor, *terminal;
8
+
9
+ editor = getenv("GIT_EDITOR");
10
+ if (!editor && editor_program)
11
+ editor = editor_program;
12
+ if (!editor)
13
+ editor = getenv("VISUAL");
14
+ if (!editor)
15
+ editor = getenv("EDITOR");
16
+
17
+ terminal = getenv("TERM");
18
+ if (!editor && (!terminal || !strcmp(terminal, "dumb"))) {
19
+ fprintf(stderr,
20
+ "Terminal is dumb but no VISUAL nor EDITOR defined.\n"
21
+ "Please supply the message using either -m or -F option.\n");
22
+ exit(1);
23
+ }
24
+
25
+ if (!editor)
26
+ editor = "vi";
27
+
28
+ if (strcmp(editor, ":")) {
29
+ size_t len = strlen(editor);
30
+ int i = 0;
31
+ const char *args[6];
32
+ struct strbuf arg0;
33
+
34
+ strbuf_init(&arg0, 0);
35
+ if (strcspn(editor, "$ \t'") != len) {
36
+ /* there are specials */
37
+ strbuf_addf(&arg0, "%s \"$@\"", editor);
38
+ args[i++] = "sh";
39
+ args[i++] = "-c";
40
+ args[i++] = arg0.buf;
41
+ }
42
+ args[i++] = editor;
43
+ args[i++] = path;
44
+ args[i] = NULL;
45
+
46
+ if (run_command_v_opt_cd_env(args, 0, NULL, env))
47
+ die("There was a problem with the editor %s.", editor);
48
+ strbuf_release(&arg0);
49
+ }
50
+
51
+ if (!buffer)
52
+ return;
53
+ if (strbuf_read_file(buffer, path, 0) < 0)
54
+ die("could not read message file '%s': %s",
55
+ path, strerror(errno));
56
+}