builtin/pull: convert to struct object_id
Convert virtually all uses of unsigned char [20] to struct object_id. Leave all the arguments that come from struct sha1_array, as these will be converted in a later patch. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Mar 26, 2017 at 16:01 UTC
f9b11147e00f066d24d9eaf9783beaa173fdd5e0
1 file changed
+36
-36
builtin/pull.c
+36
-36
@@ -515,7 +515,7 @@ static int run_fetch(const char *repo, const char **refspecs)
515
* "Pulls into void" by branching off merge_head.
516
*/
517
static int pull_into_void(const unsigned char *merge_head,
518
- const unsigned char *curr_head)
518
+ const struct object_id *curr_head)
519
{
520
/*
521
* Two-way merge: we treat the index as based on an empty tree,
@@ -526,7 +526,7 @@ static int pull_into_void(const unsigned char *merge_head,
526
if (checkout_fast_forward(EMPTY_TREE_SHA1_BIN, merge_head, 0))
527
return 1;
528
529
- if (update_ref("initial pull", "HEAD", merge_head, curr_head, 0, UPDATE_REFS_DIE_ON_ERR))
529
+ if (update_ref("initial pull", "HEAD", merge_head, curr_head->hash, 0, UPDATE_REFS_DIE_ON_ERR))
530
return 1;
531
532
return 0;
@@ -647,7 +647,7 @@ static const char *get_tracking_branch(const char *remote, const char *refspec)
647
* current branch forked from its remote tracking branch. Returns 0 on success,
648
* -1 on failure.
649
*/
650
-static int get_rebase_fork_point(unsigned char *fork_point, const char *repo,
650
+static int get_rebase_fork_point(struct object_id *fork_point, const char *repo,
651
const char *refspec)
652
{
653
int ret;
@@ -678,7 +678,7 @@ static int get_rebase_fork_point(unsigned char *fork_point, const char *repo,
678
if (ret)
679
goto cleanup;
680
681
- ret = get_sha1_hex(sb.buf, fork_point);
681
+ ret = get_oid_hex(sb.buf, fork_point);
682
if (ret)
683
goto cleanup;
684
@@ -691,24 +691,24 @@ cleanup:
691
* Sets merge_base to the octopus merge base of curr_head, merge_head and
692
* fork_point. Returns 0 if a merge base is found, 1 otherwise.
693
*/
694
-static int get_octopus_merge_base(unsigned char *merge_base,
695
- const unsigned char *curr_head,
694
+static int get_octopus_merge_base(struct object_id *merge_base,
695
+ const struct object_id *curr_head,
696
const unsigned char *merge_head,
697
- const unsigned char *fork_point)
697
+ const struct object_id *fork_point)
698
{
699
struct commit_list *revs = NULL, *result;
700
701
- commit_list_insert(lookup_commit_reference(curr_head), &revs);
701
+ commit_list_insert(lookup_commit_reference(curr_head->hash), &revs);
702
commit_list_insert(lookup_commit_reference(merge_head), &revs);
703
- if (!is_null_sha1(fork_point))
704
- commit_list_insert(lookup_commit_reference(fork_point), &revs);
703
+ if (!is_null_oid(fork_point))
704
+ commit_list_insert(lookup_commit_reference(fork_point->hash), &revs);
705
706
result = reduce_heads(get_octopus_merge_bases(revs));
707
free_commit_list(revs);
708
if (!result)
709
return 1;
710
711
- hashcpy(merge_base, result->item->object.oid.hash);
711
+ oidcpy(merge_base, &result->item->object.oid);
712
return 0;
713
}
714
@@ -717,16 +717,16 @@ static int get_octopus_merge_base(unsigned char *merge_base,
717
* fork point calculated by get_rebase_fork_point(), runs git-rebase with the
718
* appropriate arguments and returns its exit status.
719
*/
720
-static int run_rebase(const unsigned char *curr_head,
720
+static int run_rebase(const struct object_id *curr_head,
721
const unsigned char *merge_head,
722
- const unsigned char *fork_point)
722
+ const struct object_id *fork_point)
723
{
724
int ret;
725
- unsigned char oct_merge_base[GIT_SHA1_RAWSZ];
725
+ struct object_id oct_merge_base;
726
struct argv_array args = ARGV_ARRAY_INIT;
727
728
- if (!get_octopus_merge_base(oct_merge_base, curr_head, merge_head, fork_point))
729
- if (!is_null_sha1(fork_point) && !hashcmp(oct_merge_base, fork_point))
728
+ if (!get_octopus_merge_base(&oct_merge_base, curr_head, merge_head, fork_point))
729
+ if (!is_null_oid(fork_point) && !oidcmp(&oct_merge_base, fork_point))
730
fork_point = NULL;
731
732
argv_array_push(&args, "rebase");
@@ -756,8 +756,8 @@ static int run_rebase(const unsigned char *curr_head,
756
argv_array_push(&args, "--onto");
757
argv_array_push(&args, sha1_to_hex(merge_head));
758
759
- if (fork_point && !is_null_sha1(fork_point))
760
- argv_array_push(&args, sha1_to_hex(fork_point));
759
+ if (fork_point && !is_null_oid(fork_point))
760
+ argv_array_push(&args, oid_to_hex(fork_point));
761
else
762
argv_array_push(&args, sha1_to_hex(merge_head));
763
@@ -770,8 +770,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
770
{
771
const char *repo, **refspecs;
772
struct sha1_array merge_heads = SHA1_ARRAY_INIT;
773
- unsigned char orig_head[GIT_SHA1_RAWSZ], curr_head[GIT_SHA1_RAWSZ];
774
- unsigned char rebase_fork_point[GIT_SHA1_RAWSZ];
773
+ struct object_id orig_head, curr_head;
774
+ struct object_id rebase_fork_point;
775
776
if (!getenv("GIT_REFLOG_ACTION"))
777
set_reflog_message(argc, argv);
@@ -794,8 +794,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
794
if (file_exists(git_path("MERGE_HEAD")))
795
die_conclude_merge();
796
797
- if (get_sha1("HEAD", orig_head))
798
- hashclr(orig_head);
797
+ if (get_oid("HEAD", &orig_head))
798
+ oidclr(&orig_head);
799
800
if (!opt_rebase && opt_autostash != -1)
801
die(_("--[no-]autostash option is only valid with --rebase."));
@@ -805,15 +805,15 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
805
if (opt_autostash != -1)
806
autostash = opt_autostash;
807
808
- if (is_null_sha1(orig_head) && !is_cache_unborn())
808
+ if (is_null_oid(&orig_head) && !is_cache_unborn())
809
die(_("Updating an unborn branch with changes added to the index."));
810
811
if (!autostash)
812
require_clean_work_tree(N_("pull with rebase"),
813
_("please commit or stash them."), 1, 0);
814
815
- if (get_rebase_fork_point(rebase_fork_point, repo, *refspecs))
816
- hashclr(rebase_fork_point);
815
+ if (get_rebase_fork_point(&rebase_fork_point, repo, *refspecs))
816
+ oidclr(&rebase_fork_point);
817
}
818
819
if (run_fetch(repo, refspecs))
@@ -822,11 +822,11 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
822
if (opt_dry_run)
823
return 0;
824
825
- if (get_sha1("HEAD", curr_head))
826
- hashclr(curr_head);
825
+ if (get_oid("HEAD", &curr_head))
826
+ oidclr(&curr_head);
827
828
- if (!is_null_sha1(orig_head) && !is_null_sha1(curr_head) &&
829
- hashcmp(orig_head, curr_head)) {
828
+ if (!is_null_oid(&orig_head) && !is_null_oid(&curr_head) &&
829
+ oidcmp(&orig_head, &curr_head)) {
830
/*
831
* The fetch involved updating the current branch.
832
*
@@ -837,15 +837,15 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
837
838
warning(_("fetch updated the current branch head.\n"
839
"fast-forwarding your working tree from\n"
840
- "commit %s."), sha1_to_hex(orig_head));
840
+ "commit %s."), oid_to_hex(&orig_head));
841
842
- if (checkout_fast_forward(orig_head, curr_head, 0))
842
+ if (checkout_fast_forward(orig_head.hash, curr_head.hash, 0))
843
die(_("Cannot fast-forward your working tree.\n"
844
"After making sure that you saved anything precious from\n"
845
"$ git diff %s\n"
846
"output, run\n"
847
"$ git reset --hard\n"
848
- "to recover."), sha1_to_hex(orig_head));
848
+ "to recover."), oid_to_hex(&orig_head));
849
}
850
851
get_merge_heads(&merge_heads);
@@ -853,10 +853,10 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
853
if (!merge_heads.nr)
854
die_no_merge_candidates(repo, refspecs);
855
856
- if (is_null_sha1(orig_head)) {
856
+ if (is_null_oid(&orig_head)) {
857
if (merge_heads.nr > 1)
858
die(_("Cannot merge multiple branches into empty head."));
859
- return pull_into_void(*merge_heads.sha1, curr_head);
859
+ return pull_into_void(*merge_heads.sha1, &curr_head);
860
}
861
if (opt_rebase && merge_heads.nr > 1)
862
die(_("Cannot rebase onto multiple branches."));
@@ -865,7 +865,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
865
struct commit_list *list = NULL;
866
struct commit *merge_head, *head;
867
868
- head = lookup_commit_reference(orig_head);
868
+ head = lookup_commit_reference(orig_head.hash);
869
commit_list_insert(head, &list);
870
merge_head = lookup_commit_reference(merge_heads.sha1[0]);
871
if (is_descendant_of(merge_head, list)) {
@@ -873,7 +873,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
873
opt_ff = "--ff-only";
874
return run_merge();
875
}
876
- return run_rebase(curr_head, *merge_heads.sha1, rebase_fork_point);
876
+ return run_rebase(&curr_head, *merge_heads.sha1, &rebase_fork_point);
877
} else {
878
return run_merge();
879
}