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

Function strbuf_edit_interactively

editor.c:138–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136}
137
138int strbuf_edit_interactively(struct repository *r,
139 struct strbuf *buffer, const char *path,
140 const char *const *env)
141{
142 struct strbuf sb = STRBUF_INIT;
143 int fd, res = 0;
144
145 if (!is_absolute_path(path))
146 path = repo_git_path_append(r, &sb, "%s", path);
147
148 fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666);
149 if (fd < 0)
150 res = error_errno(_("could not open '%s' for writing"), path);
151 else if (write_in_full(fd, buffer->buf, buffer->len) < 0) {
152 res = error_errno(_("could not write to '%s'"), path);
153 close(fd);
154 } else if (close(fd) < 0)
155 res = error_errno(_("could not close '%s'"), path);
156 else {
157 strbuf_reset(buffer);
158 if (launch_editor(path, buffer, env) < 0)
159 res = error_errno(_("could not edit '%s'"), path);
160 unlink(path);
161 }
162
163 strbuf_release(&sb);
164 return res;
165}

Callers 1

edit_hunk_manuallyFunction · 0.85

Calls 6

is_absolute_pathFunction · 0.85
repo_git_path_appendFunction · 0.85
error_errnoFunction · 0.85
write_in_fullFunction · 0.85
launch_editorFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected