bisect.c: remove the_repository reference

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Nov 10, 2018 at 06:48 UTC 69d2cfe6e84fbcd77872191b6f433d38362c23d6
3 files changed +33 -22
bisect.c
+28 -20
@@ -626,14 +626,15 @@ static struct commit_list *managed_skipped(struct commit_list *list,
626 return skip_away(list, count);
627 }
628
629 -static void bisect_rev_setup(struct rev_info *revs, const char *prefix,
629 +static void bisect_rev_setup(struct repository *r, struct rev_info *revs,
630 + const char *prefix,
631 const char *bad_format, const char *good_format,
632 int read_paths)
633 {
634 struct argv_array rev_argv = ARGV_ARRAY_INIT;
635 int i;
636
636 - repo_init_revisions(the_repository, revs, prefix);
637 + repo_init_revisions(r, revs, prefix);
638 revs->abbrev = 0;
639 revs->commit_format = CMIT_FMT_UNSPECIFIED;
640
@@ -723,23 +724,25 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)
724 return run_command_v_opt(argv_show_branch, RUN_GIT_CMD);
725 }
726
726 -static struct commit *get_commit_reference(const struct object_id *oid)
727 +static struct commit *get_commit_reference(struct repository *r,
728 + const struct object_id *oid)
729 {
728 - struct commit *r = lookup_commit_reference(the_repository, oid);
729 - if (!r)
730 + struct commit *c = lookup_commit_reference(r, oid);
731 + if (!c)
732 die(_("Not a valid commit name %s"), oid_to_hex(oid));
731 - return r;
733 + return c;
734 }
735
734 -static struct commit **get_bad_and_good_commits(int *rev_nr)
736 +static struct commit **get_bad_and_good_commits(struct repository *r,
737 + int *rev_nr)
738 {
739 struct commit **rev;
740 int i, n = 0;
741
742 ALLOC_ARRAY(rev, 1 + good_revs.nr);
740 - rev[n++] = get_commit_reference(current_bad_oid);
743 + rev[n++] = get_commit_reference(r, current_bad_oid);
744 for (i = 0; i < good_revs.nr; i++)
742 - rev[n++] = get_commit_reference(good_revs.oid + i);
745 + rev[n++] = get_commit_reference(r, good_revs.oid + i);
746 *rev_nr = n;
747
748 return rev;
@@ -823,12 +826,13 @@ static void check_merge_bases(int rev_nr, struct commit **rev, int no_checkout)
826 free_commit_list(result);
827 }
828
826 -static int check_ancestors(int rev_nr, struct commit **rev, const char *prefix)
829 +static int check_ancestors(struct repository *r, int rev_nr,
830 + struct commit **rev, const char *prefix)
831 {
832 struct rev_info revs;
833 int res;
834
831 - bisect_rev_setup(&revs, prefix, "^%s", "%s", 0);
835 + bisect_rev_setup(r, &revs, prefix, "^%s", "%s", 0);
836
837 bisect_common(&revs);
838 res = (revs.commits != NULL);
@@ -847,7 +851,9 @@ static int check_ancestors(int rev_nr, struct commit **rev, const char *prefix)
851 * If a merge base must be tested by the user, its source code will be
852 * checked out to be tested by the user and we will exit.
853 */
850 -static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
854 +static void check_good_are_ancestors_of_bad(struct repository *r,
855 + const char *prefix,
856 + int no_checkout)
857 {
858 char *filename = git_pathdup("BISECT_ANCESTORS_OK");
859 struct stat st;
@@ -866,8 +872,8 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
872 goto done;
873
874 /* Check if all good revs are ancestor of the bad rev. */
869 - rev = get_bad_and_good_commits(&rev_nr);
870 - if (check_ancestors(rev_nr, rev, prefix))
875 + rev = get_bad_and_good_commits(r, &rev_nr);
876 + if (check_ancestors(r, rev_nr, rev, prefix))
877 check_merge_bases(rev_nr, rev, no_checkout);
878 free(rev);
879
@@ -885,12 +891,14 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
891 /*
892 * This does "git diff-tree --pretty COMMIT" without one fork+exec.
893 */
888 -static void show_diff_tree(const char *prefix, struct commit *commit)
894 +static void show_diff_tree(struct repository *r,
895 + const char *prefix,
896 + struct commit *commit)
897 {
898 struct rev_info opt;
899
900 /* diff-tree init */
893 - repo_init_revisions(the_repository, &opt, prefix);
901 + repo_init_revisions(r, &opt, prefix);
902 git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
903 opt.abbrev = 0;
904 opt.diff = 1;
@@ -945,7 +953,7 @@ void read_bisect_terms(const char **read_bad, const char **read_good)
953 * If no_checkout is non-zero, the bisection process does not
954 * checkout the trial commit but instead simply updates BISECT_HEAD.
955 */
948 -int bisect_next_all(const char *prefix, int no_checkout)
956 +int bisect_next_all(struct repository *r, const char *prefix, int no_checkout)
957 {
958 struct rev_info revs;
959 struct commit_list *tried;
@@ -957,9 +965,9 @@ int bisect_next_all(const char *prefix, int no_checkout)
965 if (read_bisect_refs())
966 die(_("reading bisect refs failed"));
967
960 - check_good_are_ancestors_of_bad(prefix, no_checkout);
968 + check_good_are_ancestors_of_bad(r, prefix, no_checkout);
969
962 - bisect_rev_setup(&revs, prefix, "%s", "^%s", 1);
970 + bisect_rev_setup(r, &revs, prefix, "%s", "^%s", 1);
971 revs.limited = 1;
972
973 bisect_common(&revs);
@@ -993,7 +1001,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
1001 exit_if_skipped_commits(tried, current_bad_oid);
1002 printf("%s is the first %s commit\n", oid_to_hex(bisect_rev),
1003 term_bad);
996 - show_diff_tree(prefix, revs.commits->item);
1004 + show_diff_tree(r, prefix, revs.commits->item);
1005 /* This means the bisection process succeeded. */
1006 exit(10);
1007 }
bisect.h
+4 -1
@@ -2,6 +2,7 @@
2 #define BISECT_H
3
4 struct commit_list;
5 +struct repository;
6
7 /*
8 * Find bisection. If something is found, `reaches` will be the number of
@@ -30,7 +31,9 @@ struct rev_list_info {
31 const char *header_prefix;
32 };
33
33 -extern int bisect_next_all(const char *prefix, int no_checkout);
34 +extern int bisect_next_all(struct repository *r,
35 + const char *prefix,
36 + int no_checkout);
37
38 extern int estimate_bisect_steps(int all);
39
builtin/bisect--helper.c
+1 -1
@@ -137,7 +137,7 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
137
138 switch (cmdmode) {
139 case NEXT_ALL:
140 - return bisect_next_all(prefix, no_checkout);
140 + return bisect_next_all(the_repository, prefix, no_checkout);
141 case WRITE_TERMS:
142 if (argc != 2)
143 return error(_("--write-terms requires two arguments"));