| 323 | } |
| 324 | |
| 325 | static 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 | |
| 367 | static int replace_parents(struct strbuf *buf, int argc, const char **argv) |
| 368 | { |
no test coverage detected