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

Function edit_patch

builtin/add.c:184–230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

182}
183
184static int edit_patch(struct repository *repo,
185 int argc,
186 const char **argv,
187 const char *prefix)
188{
189 char *file = repo_git_path(repo, "ADD_EDIT.patch");
190 struct child_process child = CHILD_PROCESS_INIT;
191 struct rev_info rev;
192 int out;
193 struct stat st;
194
195 repo_config(repo, git_diff_basic_config, NULL);
196
197 if (repo_read_index(repo) < 0)
198 die(_("could not read the index"));
199
200 repo_init_revisions(repo, &rev, prefix);
201 rev.diffopt.context = 7;
202
203 argc = setup_revisions(argc, argv, &rev, NULL);
204 rev.diffopt.output_format = DIFF_FORMAT_PATCH;
205 rev.diffopt.use_color = GIT_COLOR_NEVER;
206 rev.diffopt.flags.ignore_dirty_submodules = 1;
207 out = xopen(file, O_CREAT | O_WRONLY | O_TRUNC, 0666);
208 rev.diffopt.file = xfdopen(out, "w");
209 rev.diffopt.close_file = 1;
210 run_diff_files(&rev, 0);
211
212 if (launch_editor(file, NULL, NULL))
213 die(_("editing patch failed"));
214
215 if (stat(file, &st))
216 die_errno(_("could not stat '%s'"), file);
217 if (!st.st_size)
218 die(_("empty patch. aborted"));
219
220 child.git_cmd = 1;
221 strvec_pushl(&child.args, "apply", "--recount", "--cached", file,
222 NULL);
223 if (run_command(&child))
224 die(_("could not apply '%s'"), file);
225
226 unlink(file);
227 free(file);
228 release_revisions(&rev);
229 return 0;
230}
231
232static const char ignore_error[] =
233N_("The following paths are ignored by one of your .gitignore files:\n");

Callers 1

cmd_addFunction · 0.85

Calls 15

repo_git_pathFunction · 0.85
repo_read_indexFunction · 0.85
repo_init_revisionsFunction · 0.85
setup_revisionsFunction · 0.85
xopenFunction · 0.85
xfdopenFunction · 0.85
run_diff_filesFunction · 0.85
launch_editorFunction · 0.85
die_errnoFunction · 0.85
strvec_pushlFunction · 0.85
run_commandFunction · 0.85
release_revisionsFunction · 0.85

Tested by

no test coverage detected