MCPcopy Create free account
hub / github.com/git/git / edit_and_replace

Function edit_and_replace

builtin/replace.c:325–365  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

323}
324
325static int edit_and_replace(const char *object_ref, int force, int raw)
326{
327 char *tmpfile;
328 enum object_type type;
329 struct object_id old_oid, new_oid, prev;
330 struct strbuf ref = STRBUF_INIT;
331
332 if (repo_get_oid(the_repository, object_ref, &old_oid) < 0)
333 return error(_("not a valid object name: '%s'"), object_ref);
334
335 type = odb_read_object_info(the_repository->objects, &old_oid, NULL);
336 if (type < 0)
337 return error(_("unable to get object type for %s"),
338 oid_to_hex(&old_oid));
339
340 if (check_ref_valid(&old_oid, &prev, &ref, force)) {
341 strbuf_release(&ref);
342 return -1;
343 }
344 strbuf_release(&ref);
345
346 tmpfile = repo_git_path(the_repository, "REPLACE_EDITOBJ");
347 if (export_object(&old_oid, type, raw, tmpfile)) {
348 free(tmpfile);
349 return -1;
350 }
351 if (launch_editor(tmpfile, NULL, NULL) < 0) {
352 free(tmpfile);
353 return error(_("editing object file failed"));
354 }
355 if (import_object(&new_oid, type, raw, tmpfile)) {
356 free(tmpfile);
357 return -1;
358 }
359 free(tmpfile);
360
361 if (oideq(&old_oid, &new_oid))
362 return error(_("new object is the same as the old one: '%s'"), oid_to_hex(&old_oid));
363
364 return replace_object_oid(object_ref, &old_oid, "replacement", &new_oid, force);
365}
366
367static int replace_parents(struct strbuf *buf, int argc, const char **argv)
368{

Callers 1

cmd_replaceFunction · 0.85

Calls 12

repo_get_oidFunction · 0.85
errorFunction · 0.85
odb_read_object_infoFunction · 0.85
oid_to_hexFunction · 0.85
check_ref_validFunction · 0.85
strbuf_releaseFunction · 0.85
repo_git_pathFunction · 0.85
export_objectFunction · 0.85
launch_editorFunction · 0.85
import_objectFunction · 0.85
oideqFunction · 0.85
replace_object_oidFunction · 0.85

Tested by

no test coverage detected