| 552 | } |
| 553 | |
| 554 | int notes_merge(struct notes_merge_options *o, |
| 555 | struct notes_tree *local_tree, |
| 556 | struct object_id *result_oid) |
| 557 | { |
| 558 | struct object_id local_oid, remote_oid; |
| 559 | struct commit *local, *remote; |
| 560 | struct commit_list *bases = NULL; |
| 561 | const struct object_id *base_oid, *base_tree_oid; |
| 562 | int result = 0; |
| 563 | |
| 564 | assert(o->local_ref && o->remote_ref); |
| 565 | assert(!strcmp(o->local_ref, local_tree->ref)); |
| 566 | oidclr(result_oid, the_repository->hash_algo); |
| 567 | |
| 568 | trace_printf("notes_merge(o->local_ref = %s, o->remote_ref = %s)\n", |
| 569 | o->local_ref, o->remote_ref); |
| 570 | |
| 571 | /* Dereference o->local_ref into local_sha1 */ |
| 572 | if (refs_read_ref_full(get_main_ref_store(the_repository), o->local_ref, 0, &local_oid, NULL)) |
| 573 | die("Failed to resolve local notes ref '%s'", o->local_ref); |
| 574 | else if (!check_refname_format(o->local_ref, 0) && |
| 575 | is_null_oid(&local_oid)) |
| 576 | local = NULL; /* local_oid == null_oid indicates unborn ref */ |
| 577 | else if (!(local = lookup_commit_reference(o->repo, &local_oid))) |
| 578 | die("Could not parse local commit %s (%s)", |
| 579 | oid_to_hex(&local_oid), o->local_ref); |
| 580 | trace_printf("\tlocal commit: %.7s\n", oid_to_hex(&local_oid)); |
| 581 | |
| 582 | /* Dereference o->remote_ref into remote_oid */ |
| 583 | if (repo_get_oid(the_repository, o->remote_ref, &remote_oid)) { |
| 584 | /* |
| 585 | * Failed to get remote_oid. If o->remote_ref looks like an |
| 586 | * unborn ref, perform the merge using an empty notes tree. |
| 587 | */ |
| 588 | if (!check_refname_format(o->remote_ref, 0)) { |
| 589 | oidclr(&remote_oid, the_repository->hash_algo); |
| 590 | remote = NULL; |
| 591 | } else { |
| 592 | die("Failed to resolve remote notes ref '%s'", |
| 593 | o->remote_ref); |
| 594 | } |
| 595 | } else if (!(remote = lookup_commit_reference(o->repo, &remote_oid))) { |
| 596 | die("Could not parse remote commit %s (%s)", |
| 597 | oid_to_hex(&remote_oid), o->remote_ref); |
| 598 | } |
| 599 | trace_printf("\tremote commit: %.7s\n", oid_to_hex(&remote_oid)); |
| 600 | |
| 601 | if (!local && !remote) |
| 602 | die("Cannot merge empty notes ref (%s) into empty notes ref " |
| 603 | "(%s)", o->remote_ref, o->local_ref); |
| 604 | if (!local) { |
| 605 | /* result == remote commit */ |
| 606 | oidcpy(result_oid, &remote_oid); |
| 607 | goto found_result; |
| 608 | } |
| 609 | if (!remote) { |
| 610 | /* result == local commit */ |
| 611 | oidcpy(result_oid, &local_oid); |
no test coverage detected