bisect.c: convert leaf functions to use struct object_id

Convert some constants to GIT_SHA1_HEXSZ. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Mar 13, 2015 at 23:39 UTC 3c5ff9956c017e1737fdc350dbec160277be4fc1
1 file changed +20 -20
bisect.c
+20 -20
@@ -15,7 +15,7 @@
15 static struct sha1_array good_revs;
16 static struct sha1_array skipped_revs;
17
18 -static unsigned char *current_bad_sha1;
18 +static struct object_id *current_bad_oid;
19
20 static const char *argv_checkout[] = {"checkout", "-q", NULL, "--", NULL};
21 static const char *argv_show_branch[] = {"show-branch", NULL, NULL};
@@ -404,8 +404,8 @@ static int register_ref(const char *refname, const unsigned char *sha1,
404 int flags, void *cb_data)
405 {
406 if (!strcmp(refname, "bad")) {
407 - current_bad_sha1 = xmalloc(20);
408 - hashcpy(current_bad_sha1, sha1);
407 + current_bad_oid = xmalloc(sizeof(*current_bad_oid));
408 + hashcpy(current_bad_oid->hash, sha1);
409 } else if (starts_with(refname, "good-")) {
410 sha1_array_append(&good_revs, sha1);
411 } else if (starts_with(refname, "skip-")) {
@@ -564,7 +564,7 @@ static struct commit_list *skip_away(struct commit_list *list, int count)
564
565 for (i = 0; cur; cur = cur->next, i++) {
566 if (i == index) {
567 - if (hashcmp(cur->item->object.sha1, current_bad_sha1))
567 + if (hashcmp(cur->item->object.sha1, current_bad_oid->hash))
568 return cur;
569 if (previous)
570 return previous;
@@ -607,7 +607,7 @@ static void bisect_rev_setup(struct rev_info *revs, const char *prefix,
607
608 /* rev_argv.argv[0] will be ignored by setup_revisions */
609 argv_array_push(&rev_argv, "bisect_rev_setup");
610 - argv_array_pushf(&rev_argv, bad_format, sha1_to_hex(current_bad_sha1));
610 + argv_array_pushf(&rev_argv, bad_format, oid_to_hex(current_bad_oid));
611 for (i = 0; i < good_revs.nr; i++)
612 argv_array_pushf(&rev_argv, good_format,
613 sha1_to_hex(good_revs.sha1[i]));
@@ -628,7 +628,7 @@ static void bisect_common(struct rev_info *revs)
628 }
629
630 static void exit_if_skipped_commits(struct commit_list *tried,
631 - const unsigned char *bad)
631 + const struct object_id *bad)
632 {
633 if (!tried)
634 return;
@@ -637,12 +637,12 @@ static void exit_if_skipped_commits(struct commit_list *tried,
637 "The first bad commit could be any of:\n");
638 print_commit_list(tried, "%s\n", "%s\n");
639 if (bad)
640 - printf("%s\n", sha1_to_hex(bad));
640 + printf("%s\n", oid_to_hex(bad));
641 printf("We cannot bisect more!\n");
642 exit(2);
643 }
644
645 -static int is_expected_rev(const unsigned char *sha1)
645 +static int is_expected_rev(const struct object_id *oid)
646 {
647 const char *filename = git_path("BISECT_EXPECTED_REV");
648 struct stat st;
@@ -658,7 +658,7 @@ static int is_expected_rev(const unsigned char *sha1)
658 return 0;
659
660 if (strbuf_getline(&str, fp, '\n') != EOF)
661 - res = !strcmp(str.buf, sha1_to_hex(sha1));
661 + res = !strcmp(str.buf, oid_to_hex(oid));
662
663 strbuf_release(&str);
664 fclose(fp);
@@ -719,7 +719,7 @@ static struct commit **get_bad_and_good_commits(int *rev_nr)
719 struct commit **rev = xmalloc(len * sizeof(*rev));
720 int i, n = 0;
721
722 - rev[n++] = get_commit_reference(current_bad_sha1);
722 + rev[n++] = get_commit_reference(current_bad_oid->hash);
723 for (i = 0; i < good_revs.nr; i++)
724 rev[n++] = get_commit_reference(good_revs.sha1[i]);
725 *rev_nr = n;
@@ -729,8 +729,8 @@ static struct commit **get_bad_and_good_commits(int *rev_nr)
729
730 static void handle_bad_merge_base(void)
731 {
732 - if (is_expected_rev(current_bad_sha1)) {
733 - char *bad_hex = sha1_to_hex(current_bad_sha1);
732 + if (is_expected_rev(current_bad_oid)) {
733 + char *bad_hex = oid_to_hex(current_bad_oid);
734 char *good_hex = join_sha1_array_hex(&good_revs, ' ');
735
736 fprintf(stderr, "The merge base %s is bad.\n"
@@ -750,7 +750,7 @@ static void handle_bad_merge_base(void)
750 static void handle_skipped_merge_base(const unsigned char *mb)
751 {
752 char *mb_hex = sha1_to_hex(mb);
753 - char *bad_hex = sha1_to_hex(current_bad_sha1);
753 + char *bad_hex = sha1_to_hex(current_bad_oid->hash);
754 char *good_hex = join_sha1_array_hex(&good_revs, ' ');
755
756 warning("the merge base between %s and [%s] "
@@ -781,7 +781,7 @@ static void check_merge_bases(int no_checkout)
781
782 for (; result; result = result->next) {
783 const unsigned char *mb = result->item->object.sha1;
784 - if (!hashcmp(mb, current_bad_sha1)) {
784 + if (!hashcmp(mb, current_bad_oid->hash)) {
785 handle_bad_merge_base();
786 } else if (0 <= sha1_array_lookup(&good_revs, mb)) {
787 continue;
@@ -838,7 +838,7 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
838 struct stat st;
839 int fd;
840
841 - if (!current_bad_sha1)
841 + if (!current_bad_oid)
842 die("a bad revision is needed");
843
844 /* Check if file BISECT_ANCESTORS_OK exists. */
@@ -903,7 +903,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
903 struct commit_list *tried;
904 int reaches = 0, all = 0, nr, steps;
905 const unsigned char *bisect_rev;
906 - char bisect_rev_hex[41];
906 + char bisect_rev_hex[GIT_SHA1_HEXSZ + 1];
907
908 if (read_bisect_refs())
909 die("reading bisect refs failed");
@@ -927,7 +927,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
927 exit_if_skipped_commits(tried, NULL);
928
929 printf("%s was both good and bad\n",
930 - sha1_to_hex(current_bad_sha1));
930 + oid_to_hex(current_bad_oid));
931 exit(1);
932 }
933
@@ -938,10 +938,10 @@ int bisect_next_all(const char *prefix, int no_checkout)
938 }
939
940 bisect_rev = revs.commits->item->object.sha1;
941 - memcpy(bisect_rev_hex, sha1_to_hex(bisect_rev), 41);
941 + memcpy(bisect_rev_hex, sha1_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1);
942
943 - if (!hashcmp(bisect_rev, current_bad_sha1)) {
944 - exit_if_skipped_commits(tried, current_bad_sha1);
943 + if (!hashcmp(bisect_rev, current_bad_oid->hash)) {
944 + exit_if_skipped_commits(tried, current_bad_oid);
945 printf("%s is the first bad commit\n", bisect_rev_hex);
946 show_diff_tree(prefix, revs.commits->item);
947 /* This means the bisection process succeeded. */