submodule.c: remove some of the_repository references

Commit 174d131fc9 (submodule.c: remove implicit dependency on the_index - 2018-09-21) makes collect_changed_submodules() take a "struct index_state *" as argument even if it's not really used. My bad. Instead of deleting this argument and fixing up all call sites. Let's take this opportunity to remove some the_repository instead because there's one or two in this function (and two more in its callback). The callers can also get rid of some the_repository. Noticed-by: Jeff King <peff@peff.net> 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 Oct 19, 2018 at 19:34 UTC 6245b98b0e4e6c59b24794fa63f29b65d851569e
4 files changed +38 -31
builtin/pull.c
+1 -1
@@ -945,7 +945,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
945 int ret = 0;
946 if ((recurse_submodules == RECURSE_SUBMODULES_ON ||
947 recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) &&
948 - submodule_touches_in_range(&the_index, &rebase_fork_point, &curr_head))
948 + submodule_touches_in_range(the_repository, &rebase_fork_point, &curr_head))
949 die(_("cannot rebase with locally recorded submodule modifications"));
950 if (!autostash) {
951 struct commit_list *list = NULL;
submodule.c
+32 -25
@@ -694,6 +694,7 @@ static struct oid_array *submodule_commits(struct string_list *submodules,
694 }
695
696 struct collect_changed_submodules_cb_data {
697 + struct repository *repo;
698 struct string_list *changed;
699 const struct object_id *commit_oid;
700 };
@@ -733,7 +734,7 @@ static void collect_changed_submodules_cb(struct diff_queue_struct *q,
734 if (!S_ISGITLINK(p->two->mode))
735 continue;
736
736 - submodule = submodule_from_path(the_repository,
737 + submodule = submodule_from_path(me->repo,
738 commit_oid, p->two->path);
739 if (submodule)
740 name = submodule->name;
@@ -741,7 +742,7 @@ static void collect_changed_submodules_cb(struct diff_queue_struct *q,
742 name = default_name_or_path(p->two->path);
743 /* make sure name does not collide with existing one */
744 if (name)
744 - submodule = submodule_from_name(the_repository,
745 + submodule = submodule_from_name(me->repo,
746 commit_oid, name);
747 if (submodule) {
748 warning("Submodule in commit %s at path: "
@@ -766,14 +767,14 @@ static void collect_changed_submodules_cb(struct diff_queue_struct *q,
767 * have a corresponding 'struct oid_array' (in the 'util' field) which lists
768 * what the submodule pointers were updated to during the change.
769 */
769 -static void collect_changed_submodules(struct index_state *istate,
770 +static void collect_changed_submodules(struct repository *r,
771 struct string_list *changed,
772 struct argv_array *argv)
773 {
774 struct rev_info rev;
775 const struct commit *commit;
776
776 - repo_init_revisions(the_repository, &rev, NULL);
777 + repo_init_revisions(r, &rev, NULL);
778 setup_revisions(argv->argc, argv->argv, &rev, NULL);
779 if (prepare_revision_walk(&rev))
780 die("revision walk setup failed");
@@ -781,10 +782,11 @@ static void collect_changed_submodules(struct index_state *istate,
782 while ((commit = get_revision(&rev))) {
783 struct rev_info diff_rev;
784 struct collect_changed_submodules_cb_data data;
785 + data.repo = r;
786 data.changed = changed;
787 data.commit_oid = &commit->object.oid;
788
787 - repo_init_revisions(the_repository, &diff_rev, NULL);
789 + repo_init_revisions(r, &diff_rev, NULL);
790 diff_rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
791 diff_rev.diffopt.format_callback = collect_changed_submodules_cb;
792 diff_rev.diffopt.format_callback_data = &data;
@@ -816,6 +818,7 @@ static int append_oid_to_argv(const struct object_id *oid, void *data)
818 }
819
820 struct has_commit_data {
821 + struct repository *repo;
822 int result;
823 const char *path;
824 };
@@ -824,7 +827,7 @@ static int check_has_commit(const struct object_id *oid, void *data)
827 {
828 struct has_commit_data *cb = data;
829
827 - enum object_type type = oid_object_info(the_repository, oid, NULL);
830 + enum object_type type = oid_object_info(cb->repo, oid, NULL);
831
832 switch (type) {
833 case OBJ_COMMIT:
@@ -842,9 +845,11 @@ static int check_has_commit(const struct object_id *oid, void *data)
845 }
846 }
847
845 -static int submodule_has_commits(const char *path, struct oid_array *commits)
848 +static int submodule_has_commits(struct repository *r,
849 + const char *path,
850 + struct oid_array *commits)
851 {
847 - struct has_commit_data has_commit = { 1, path };
852 + struct has_commit_data has_commit = { r, 1, path };
853
854 /*
855 * Perform a cheap, but incorrect check for the existence of 'commits'.
@@ -887,9 +892,11 @@ static int submodule_has_commits(const char *path, struct oid_array *commits)
892 return has_commit.result;
893 }
894
890 -static int submodule_needs_pushing(const char *path, struct oid_array *commits)
895 +static int submodule_needs_pushing(struct repository *r,
896 + const char *path,
897 + struct oid_array *commits)
898 {
892 - if (!submodule_has_commits(path, commits))
899 + if (!submodule_has_commits(r, path, commits))
900 /*
901 * NOTE: We do consider it safe to return "no" here. The
902 * correct answer would be "We do not know" instead of
@@ -931,7 +938,7 @@ static int submodule_needs_pushing(const char *path, struct oid_array *commits)
938 return 0;
939 }
940
934 -int find_unpushed_submodules(struct index_state *istate,
941 +int find_unpushed_submodules(struct repository *r,
942 struct oid_array *commits,
943 const char *remotes_name,
944 struct string_list *needs_pushing)
@@ -946,14 +953,14 @@ int find_unpushed_submodules(struct index_state *istate,
953 argv_array_push(&argv, "--not");
954 argv_array_pushf(&argv, "--remotes=%s", remotes_name);
955
949 - collect_changed_submodules(istate, &submodules, &argv);
956 + collect_changed_submodules(r, &submodules, &argv);
957
958 for_each_string_list_item(name, &submodules) {
959 struct oid_array *commits = name->util;
960 const struct submodule *submodule;
961 const char *path = NULL;
962
956 - submodule = submodule_from_name(the_repository, &null_oid, name->string);
963 + submodule = submodule_from_name(r, &null_oid, name->string);
964 if (submodule)
965 path = submodule->path;
966 else
@@ -962,7 +969,7 @@ int find_unpushed_submodules(struct index_state *istate,
969 if (!path)
970 continue;
971
965 - if (submodule_needs_pushing(path, commits))
972 + if (submodule_needs_pushing(r, path, commits))
973 string_list_insert(needs_pushing, path);
974 }
975
@@ -1047,7 +1054,7 @@ static void submodule_push_check(const char *path, const char *head,
1054 die("process for submodule '%s' failed", path);
1055 }
1056
1050 -int push_unpushed_submodules(struct index_state *istate,
1057 +int push_unpushed_submodules(struct repository *r,
1058 struct oid_array *commits,
1059 const struct remote *remote,
1060 const struct refspec *rs,
@@ -1057,7 +1064,7 @@ int push_unpushed_submodules(struct index_state *istate,
1064 int i, ret = 1;
1065 struct string_list needs_pushing = STRING_LIST_INIT_DUP;
1066
1060 - if (!find_unpushed_submodules(istate, commits,
1067 + if (!find_unpushed_submodules(r, commits,
1068 remote->name, &needs_pushing))
1069 return 1;
1070
@@ -1115,14 +1122,14 @@ void check_for_new_submodule_commits(struct object_id *oid)
1122 oid_array_append(&ref_tips_after_fetch, oid);
1123 }
1124
1118 -static void calculate_changed_submodule_paths(struct index_state *istate)
1125 +static void calculate_changed_submodule_paths(struct repository *r)
1126 {
1127 struct argv_array argv = ARGV_ARRAY_INIT;
1128 struct string_list changed_submodules = STRING_LIST_INIT_DUP;
1129 const struct string_list_item *name;
1130
1131 /* No need to check if there are no submodules configured */
1125 - if (!submodule_from_path(the_repository, NULL, NULL))
1132 + if (!submodule_from_path(r, NULL, NULL))
1133 return;
1134
1135 argv_array_push(&argv, "--"); /* argv[0] program name */
@@ -1136,14 +1143,14 @@ static void calculate_changed_submodule_paths(struct index_state *istate)
1143 * Collect all submodules (whether checked out or not) for which new
1144 * commits have been recorded upstream in "changed_submodule_names".
1145 */
1139 - collect_changed_submodules(istate, &changed_submodules, &argv);
1146 + collect_changed_submodules(r, &changed_submodules, &argv);
1147
1148 for_each_string_list_item(name, &changed_submodules) {
1149 struct oid_array *commits = name->util;
1150 const struct submodule *submodule;
1151 const char *path = NULL;
1152
1146 - submodule = submodule_from_name(the_repository, &null_oid, name->string);
1153 + submodule = submodule_from_name(r, &null_oid, name->string);
1154 if (submodule)
1155 path = submodule->path;
1156 else
@@ -1152,7 +1159,7 @@ static void calculate_changed_submodule_paths(struct index_state *istate)
1159 if (!path)
1160 continue;
1161
1155 - if (!submodule_has_commits(path, commits))
1162 + if (!submodule_has_commits(r, path, commits))
1163 string_list_append(&changed_submodule_names, name->string);
1164 }
1165
@@ -1163,7 +1170,7 @@ static void calculate_changed_submodule_paths(struct index_state *istate)
1170 initialized_fetch_ref_tips = 0;
1171 }
1172
1166 -int submodule_touches_in_range(struct index_state *istate,
1173 +int submodule_touches_in_range(struct repository *r,
1174 struct object_id *excl_oid,
1175 struct object_id *incl_oid)
1176 {
@@ -1172,7 +1179,7 @@ int submodule_touches_in_range(struct index_state *istate,
1179 int ret;
1180
1181 /* No need to check if there are no submodules configured */
1175 - if (!submodule_from_path(the_repository, NULL, NULL))
1182 + if (!submodule_from_path(r, NULL, NULL))
1183 return 0;
1184
1185 argv_array_push(&args, "--"); /* args[0] program name */
@@ -1182,7 +1189,7 @@ int submodule_touches_in_range(struct index_state *istate,
1189 argv_array_push(&args, oid_to_hex(excl_oid));
1190 }
1191
1185 - collect_changed_submodules(istate, &subs, &args);
1192 + collect_changed_submodules(r, &subs, &args);
1193 ret = subs.nr;
1194
1195 argv_array_clear(&args);
@@ -1352,7 +1359,7 @@ int fetch_populated_submodules(struct repository *r,
1359 argv_array_push(&spf.args, "--recurse-submodules-default");
1360 /* default value, "--submodule-prefix" and its value are added later */
1361
1355 - calculate_changed_submodule_paths(r->index);
1362 + calculate_changed_submodule_paths(r);
1363 run_processes_parallel(max_parallel_jobs,
1364 get_next_submodule,
1365 fetch_start_failure,
submodule.h
+3 -3
@@ -102,15 +102,15 @@ int add_submodule_odb(const char *path);
102 * Checks if there are submodule changes in a..b. If a is the null OID,
103 * checks b and all its ancestors instead.
104 */
105 -int submodule_touches_in_range(struct index_state *istate,
105 +int submodule_touches_in_range(struct repository *r,
106 struct object_id *a,
107 struct object_id *b);
108 -int find_unpushed_submodules(struct index_state *istate,
108 +int find_unpushed_submodules(struct repository *r,
109 struct oid_array *commits,
110 const char *remotes_name,
111 struct string_list *needs_pushing);
112 struct refspec;
113 -int push_unpushed_submodules(struct index_state *istate,
113 +int push_unpushed_submodules(struct repository *r,
114 struct oid_array *commits,
115 const struct remote *remote,
116 const struct refspec *rs,
transport.c
+2 -2
@@ -1172,7 +1172,7 @@ int transport_push(struct transport *transport,
1172 oid_array_append(&commits,
1173 &ref->new_oid);
1174
1175 - if (!push_unpushed_submodules(&the_index,
1175 + if (!push_unpushed_submodules(the_repository,
1176 &commits,
1177 transport->remote,
1178 rs,
@@ -1197,7 +1197,7 @@ int transport_push(struct transport *transport,
1197 oid_array_append(&commits,
1198 &ref->new_oid);
1199
1200 - if (find_unpushed_submodules(&the_index,
1200 + if (find_unpushed_submodules(the_repository,
1201 &commits,
1202 transport->remote->name,
1203 &needs_pushing)) {