Skip to content

Commit d82f33e

Browse files
sbeyergitster
authored andcommitted
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>
1 parent d9d9e6e commit d82f33e

3 files changed

Lines changed: 57 additions & 53 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ LIB_OBJS += diff-no-index.o
410410
LIB_OBJS += diff-lib.o
411411
LIB_OBJS += diff.o
412412
LIB_OBJS += dir.o
413+
LIB_OBJS += editor.o
413414
LIB_OBJS += entry.o
414415
LIB_OBJS += environment.o
415416
LIB_OBJS += exec_cmd.o

builtin-tag.c

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -23,59 +23,6 @@ static const char * const git_tag_usage[] = {
2323

2424
static char signingkey[1000];
2525

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-
7926
struct tag_filter {
8027
const char *pattern;
8128
int lines;

editor.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

0 commit comments

Comments
 (0)