notes-merge: convert notes_merge* to struct object_id

Convert notes_merge and notes_merge_commit to use struct object_id. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed May 30, 2017 at 10:30 UTC 5237e0eb599c208d1c3f6da997c06ee18a1dc201
3 files changed +42 -42
builtin/notes.c
+3 -3
@@ -724,7 +724,7 @@ static int merge_commit(struct notes_merge_options *o)
724 if (!o->local_ref)
725 die(_("failed to resolve NOTES_MERGE_REF"));
726
727 - if (notes_merge_commit(o, t, partial, oid.hash))
727 + if (notes_merge_commit(o, t, partial, &oid))
728 die(_("failed to finalize notes merge"));
729
730 /* Reuse existing commit message in reflog message */
@@ -842,9 +842,9 @@ static int merge(int argc, const char **argv, const char *prefix)
842 remote_ref.buf, default_notes_ref());
843 strbuf_add(&(o.commit_msg), msg.buf + 7, msg.len - 7); /* skip "notes: " */
844
845 - result = notes_merge(&o, t, result_oid.hash);
845 + result = notes_merge(&o, t, &result_oid);
846
847 - if (result >= 0) /* Merge resulted (trivially) in result_sha1 */
847 + if (result >= 0) /* Merge resulted (trivially) in result_oid */
848 /* Update default notes ref with new commit */
849 update_ref(msg.buf, default_notes_ref(), result_oid.hash, NULL,
850 0, UPDATE_REFS_DIE_ON_ERR);
notes-merge.c
+29 -29
@@ -533,17 +533,17 @@ static int merge_from_diffs(struct notes_merge_options *o,
533
534 int notes_merge(struct notes_merge_options *o,
535 struct notes_tree *local_tree,
536 - unsigned char *result_sha1)
536 + struct object_id *result_oid)
537 {
538 struct object_id local_oid, remote_oid;
539 struct commit *local, *remote;
540 struct commit_list *bases = NULL;
541 - const unsigned char *base_sha1, *base_tree_sha1;
541 + const struct object_id *base_oid, *base_tree_oid;
542 int result = 0;
543
544 assert(o->local_ref && o->remote_ref);
545 assert(!strcmp(o->local_ref, local_tree->ref));
546 - hashclr(result_sha1);
546 + oidclr(result_oid);
547
548 trace_printf("notes_merge(o->local_ref = %s, o->remote_ref = %s)\n",
549 o->local_ref, o->remote_ref);
@@ -553,16 +553,16 @@ int notes_merge(struct notes_merge_options *o,
553 die("Failed to resolve local notes ref '%s'", o->local_ref);
554 else if (!check_refname_format(o->local_ref, 0) &&
555 is_null_oid(&local_oid))
556 - local = NULL; /* local_sha1 == null_sha1 indicates unborn ref */
556 + local = NULL; /* local_oid == null_oid indicates unborn ref */
557 else if (!(local = lookup_commit_reference(&local_oid)))
558 die("Could not parse local commit %s (%s)",
559 oid_to_hex(&local_oid), o->local_ref);
560 trace_printf("\tlocal commit: %.7s\n", oid_to_hex(&local_oid));
561
562 - /* Dereference o->remote_ref into remote_sha1 */
562 + /* Dereference o->remote_ref into remote_oid */
563 if (get_oid(o->remote_ref, &remote_oid)) {
564 /*
565 - * Failed to get remote_sha1. If o->remote_ref looks like an
565 + * Failed to get remote_oid. If o->remote_ref looks like an
566 * unborn ref, perform the merge using an empty notes tree.
567 */
568 if (!check_refname_format(o->remote_ref, 0)) {
@@ -583,12 +583,12 @@ int notes_merge(struct notes_merge_options *o,
583 "(%s)", o->remote_ref, o->local_ref);
584 if (!local) {
585 /* result == remote commit */
586 - hashcpy(result_sha1, remote_oid.hash);
586 + oidcpy(result_oid, &remote_oid);
587 goto found_result;
588 }
589 if (!remote) {
590 /* result == local commit */
591 - hashcpy(result_sha1, local_oid.hash);
591 + oidcpy(result_oid, &local_oid);
592 goto found_result;
593 }
594 assert(local && remote);
@@ -596,47 +596,47 @@ int notes_merge(struct notes_merge_options *o,
596 /* Find merge bases */
597 bases = get_merge_bases(local, remote);
598 if (!bases) {
599 - base_sha1 = null_sha1;
600 - base_tree_sha1 = EMPTY_TREE_SHA1_BIN;
599 + base_oid = &null_oid;
600 + base_tree_oid = &empty_tree_oid;
601 if (o->verbosity >= 4)
602 printf("No merge base found; doing history-less merge\n");
603 } else if (!bases->next) {
604 - base_sha1 = bases->item->object.oid.hash;
605 - base_tree_sha1 = bases->item->tree->object.oid.hash;
604 + base_oid = &bases->item->object.oid;
605 + base_tree_oid = &bases->item->tree->object.oid;
606 if (o->verbosity >= 4)
607 printf("One merge base found (%.7s)\n",
608 - sha1_to_hex(base_sha1));
608 + oid_to_hex(base_oid));
609 } else {
610 /* TODO: How to handle multiple merge-bases? */
611 - base_sha1 = bases->item->object.oid.hash;
612 - base_tree_sha1 = bases->item->tree->object.oid.hash;
611 + base_oid = &bases->item->object.oid;
612 + base_tree_oid = &bases->item->tree->object.oid;
613 if (o->verbosity >= 3)
614 printf("Multiple merge bases found. Using the first "
615 - "(%.7s)\n", sha1_to_hex(base_sha1));
615 + "(%.7s)\n", oid_to_hex(base_oid));
616 }
617
618 if (o->verbosity >= 4)
619 printf("Merging remote commit %.7s into local commit %.7s with "
620 "merge-base %.7s\n", oid_to_hex(&remote->object.oid),
621 oid_to_hex(&local->object.oid),
622 - sha1_to_hex(base_sha1));
622 + oid_to_hex(base_oid));
623
624 - if (!hashcmp(remote->object.oid.hash, base_sha1)) {
624 + if (!oidcmp(&remote->object.oid, base_oid)) {
625 /* Already merged; result == local commit */
626 if (o->verbosity >= 2)
627 printf("Already up-to-date!\n");
628 - hashcpy(result_sha1, local->object.oid.hash);
628 + oidcpy(result_oid, &local->object.oid);
629 goto found_result;
630 }
631 - if (!hashcmp(local->object.oid.hash, base_sha1)) {
631 + if (!oidcmp(&local->object.oid, base_oid)) {
632 /* Fast-forward; result == remote commit */
633 if (o->verbosity >= 2)
634 printf("Fast-forward\n");
635 - hashcpy(result_sha1, remote->object.oid.hash);
635 + oidcpy(result_oid, &remote->object.oid);
636 goto found_result;
637 }
638
639 - result = merge_from_diffs(o, base_tree_sha1, local->tree->object.oid.hash,
639 + result = merge_from_diffs(o, base_tree_oid->hash, local->tree->object.oid.hash,
640 remote->tree->object.oid.hash, local_tree);
641
642 if (result != 0) { /* non-trivial merge (with or without conflicts) */
@@ -646,28 +646,28 @@ int notes_merge(struct notes_merge_options *o,
646 commit_list_insert(local, &parents);
647 create_notes_commit(local_tree, parents,
648 o->commit_msg.buf, o->commit_msg.len,
649 - result_sha1);
649 + result_oid->hash);
650 }
651
652 found_result:
653 free_commit_list(bases);
654 strbuf_release(&(o->commit_msg));
655 - trace_printf("notes_merge(): result = %i, result_sha1 = %.7s\n",
656 - result, sha1_to_hex(result_sha1));
655 + trace_printf("notes_merge(): result = %i, result_oid = %.7s\n",
656 + result, oid_to_hex(result_oid));
657 return result;
658 }
659
660 int notes_merge_commit(struct notes_merge_options *o,
661 struct notes_tree *partial_tree,
662 struct commit *partial_commit,
663 - unsigned char *result_sha1)
663 + struct object_id *result_oid)
664 {
665 /*
666 * Iterate through files in .git/NOTES_MERGE_WORKTREE and add all
667 * found notes to 'partial_tree'. Write the updated notes tree to
668 * the DB, and commit the resulting tree object while reusing the
669 * commit message and parents from 'partial_commit'.
670 - * Finally store the new commit object SHA1 into 'result_sha1'.
670 + * Finally store the new commit object OID into 'result_oid'.
671 */
672 DIR *dir;
673 struct dirent *e;
@@ -721,11 +721,11 @@ int notes_merge_commit(struct notes_merge_options *o,
721 }
722
723 create_notes_commit(partial_tree, partial_commit->parents,
724 - msg, strlen(msg), result_sha1);
724 + msg, strlen(msg), result_oid->hash);
725 unuse_commit_buffer(partial_commit, buffer);
726 if (o->verbosity >= 4)
727 printf("Finalized notes merge commit: %s\n",
728 - sha1_to_hex(result_sha1));
728 + oid_to_hex(result_oid));
729 strbuf_release(&path);
730 closedir(dir);
731 return 0;
notes-merge.h
+10 -10
@@ -32,16 +32,16 @@ void init_notes_merge_options(struct notes_merge_options *o);
32 * outcomes:
33 *
34 * 1. The merge trivially results in an existing commit (e.g. fast-forward or
35 - * already-up-to-date). 'local_tree' is untouched, the SHA1 of the result
36 - * is written into 'result_sha1' and 0 is returned.
35 + * already-up-to-date). 'local_tree' is untouched, the OID of the result
36 + * is written into 'result_oid' and 0 is returned.
37 * 2. The merge successfully completes, producing a merge commit. local_tree
38 - * contains the updated notes tree, the SHA1 of the resulting commit is
39 - * written into 'result_sha1', and 1 is returned.
38 + * contains the updated notes tree, the OID of the resulting commit is
39 + * written into 'result_oid', and 1 is returned.
40 * 3. The merge results in conflicts. This is similar to #2 in that the
41 * partial merge result (i.e. merge result minus the unmerged entries)
42 - * are stored in 'local_tree', and the SHA1 or the resulting commit
42 + * are stored in 'local_tree', and the OID or the resulting commit
43 * (to be amended when the conflicts have been resolved) is written into
44 - * 'result_sha1'. The unmerged entries are written into the
44 + * 'result_oid'. The unmerged entries are written into the
45 * .git/NOTES_MERGE_WORKTREE directory with conflict markers.
46 * -1 is returned.
47 *
@@ -52,7 +52,7 @@ void init_notes_merge_options(struct notes_merge_options *o);
52 */
53 int notes_merge(struct notes_merge_options *o,
54 struct notes_tree *local_tree,
55 - unsigned char *result_sha1);
55 + struct object_id *result_oid);
56
57 /*
58 * Finalize conflict resolution from an earlier notes_merge()
@@ -62,13 +62,13 @@ int notes_merge(struct notes_merge_options *o,
62 * call to notes_merge().
63 *
64 * This function will add the (now resolved) notes in .git/NOTES_MERGE_WORKTREE
65 - * to 'partial_tree', and create a final notes merge commit, the SHA1 of which
66 - * will be stored in 'result_sha1'.
65 + * to 'partial_tree', and create a final notes merge commit, the OID of which
66 + * will be stored in 'result_oid'.
67 */
68 int notes_merge_commit(struct notes_merge_options *o,
69 struct notes_tree *partial_tree,
70 struct commit *partial_commit,
71 - unsigned char *result_sha1);
71 + struct object_id *result_oid);
72
73 /*
74 * Abort conflict resolution from an earlier notes_merge()