submodule: store OIDs in changed_submodule_names
'calculate_changed_submodule_paths' uses a local list to compute the changed submodules, and then produces the result by copying appropriate items into the result list. Instead use the result list directly and prune items afterwards using string_list_remove_empty_items. By doing so we'll have access to the util pointer for longer that contains the commits that we need to fetch, which will be useful in a later patch. Signed-off-by: Stefan Beller <sbeller@google.com> Reviewed-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Nov 28, 2018 at 16:27 UTC
bcd7337243f4f20091d478c71682d68dd2100207
1 file changed
+10
-9
submodule.c
+10
-9
@@ -1139,8 +1139,7 @@ static void calculate_changed_submodule_paths(struct repository *r,
1139
struct string_list *changed_submodule_names)
1140
{
1141
struct argv_array argv = ARGV_ARRAY_INIT;
1142
- struct string_list changed_submodules = STRING_LIST_INIT_DUP;
1143
- const struct string_list_item *name;
1142
+ struct string_list_item *name;
1143
1144
/* No need to check if there are no submodules configured */
1145
if (!submodule_from_path(r, NULL, NULL))
@@ -1157,9 +1156,9 @@ static void calculate_changed_submodule_paths(struct repository *r,
1156
* Collect all submodules (whether checked out or not) for which new
1157
* commits have been recorded upstream in "changed_submodule_names".
1158
*/
1160
- collect_changed_submodules(r, &changed_submodules, &argv);
1159
+ collect_changed_submodules(r, changed_submodule_names, &argv);
1160
1162
- for_each_string_list_item(name, &changed_submodules) {
1161
+ for_each_string_list_item(name, changed_submodule_names) {
1162
struct oid_array *commits = name->util;
1163
const struct submodule *submodule;
1164
const char *path = NULL;
@@ -1173,12 +1172,14 @@ static void calculate_changed_submodule_paths(struct repository *r,
1172
if (!path)
1173
continue;
1174
1176
- if (!submodule_has_commits(r, path, commits))
1177
- string_list_append(changed_submodule_names,
1178
- name->string);
1175
+ if (submodule_has_commits(r, path, commits)) {
1176
+ oid_array_clear(commits);
1177
+ *name->string = '\0';
1178
+ }
1179
}
1180
1181
- free_submodules_oids(&changed_submodules);
1181
+ string_list_remove_empty_items(changed_submodule_names, 1);
1182
+
1183
argv_array_clear(&argv);
1184
oid_array_clear(&ref_tips_before_fetch);
1185
oid_array_clear(&ref_tips_after_fetch);
@@ -1389,7 +1390,7 @@ int fetch_populated_submodules(struct repository *r,
1390
1391
argv_array_clear(&spf.args);
1392
out:
1392
- string_list_clear(&spf.changed_submodule_names, 1);
1393
+ free_submodules_oids(&spf.changed_submodule_names);
1394
return spf.result;
1395
}
1396