MCPcopy Index your code
hub / github.com/git/git / launch_specified_editor

Function launch_specified_editor

editor.c:60–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58}
59
60static int launch_specified_editor(const char *editor, const char *path,
61 struct strbuf *buffer, const char *const *env)
62{
63 if (!editor)
64 return error("Terminal is dumb, but EDITOR unset");
65
66 if (strcmp(editor, ":")) {
67 struct strbuf realpath = STRBUF_INIT;
68 struct child_process p = CHILD_PROCESS_INIT;
69 int ret, sig;
70 int print_waiting_for_editor = advice_enabled(ADVICE_WAITING_FOR_EDITOR) && isatty(2);
71
72 if (print_waiting_for_editor) {
73 /*
74 * A dumb terminal cannot erase the line later on. Add a
75 * newline to separate the hint from subsequent output.
76 *
77 * Make sure that our message is separated with a whitespace
78 * from further cruft that may be written by the editor.
79 */
80 const char term = is_terminal_dumb() ? '\n' : ' ';
81
82 fprintf(stderr,
83 _("hint: Waiting for your editor to close the file...%c"),
84 term);
85 fflush(stderr);
86 }
87
88 strbuf_realpath(&realpath, path, 1);
89
90 strvec_pushl(&p.args, editor, realpath.buf, NULL);
91 if (env)
92 strvec_pushv(&p.env, (const char **)env);
93 p.use_shell = 1;
94 p.trace2_child_class = "editor";
95 if (start_command(&p) < 0) {
96 strbuf_release(&realpath);
97 return error("unable to start editor '%s'", editor);
98 }
99
100 sigchain_push(SIGINT, SIG_IGN);
101 sigchain_push(SIGQUIT, SIG_IGN);
102 ret = finish_command(&p);
103 strbuf_release(&realpath);
104 sig = ret - 128;
105 sigchain_pop(SIGINT);
106 sigchain_pop(SIGQUIT);
107 if (sig == SIGINT || sig == SIGQUIT)
108 raise(sig);
109 if (print_waiting_for_editor && !is_terminal_dumb())
110 /*
111 * Erase the entire line to avoid wasting the
112 * vertical space.
113 */
114 term_clear_line();
115 if (ret)
116 return error("there was a problem with the editor '%s'",
117 editor);

Callers 2

launch_editorFunction · 0.85
launch_sequence_editorFunction · 0.85

Calls 14

errorFunction · 0.85
advice_enabledFunction · 0.85
is_terminal_dumbFunction · 0.85
strbuf_realpathFunction · 0.85
strvec_pushlFunction · 0.85
strvec_pushvFunction · 0.85
start_commandFunction · 0.85
strbuf_releaseFunction · 0.85
sigchain_pushFunction · 0.85
finish_commandFunction · 0.85
sigchain_popFunction · 0.85
term_clear_lineFunction · 0.85

Tested by

no test coverage detected