Skip to content

Commit bcd7337

Browse files
stefanbellergitster
authored andcommitted
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>
1 parent 16dd6fe commit bcd7337

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

submodule.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,8 +1139,7 @@ static void calculate_changed_submodule_paths(struct repository *r,
11391139
struct string_list *changed_submodule_names)
11401140
{
11411141
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;
11441143

11451144
/* No need to check if there are no submodules configured */
11461145
if (!submodule_from_path(r, NULL, NULL))
@@ -1157,9 +1156,9 @@ static void calculate_changed_submodule_paths(struct repository *r,
11571156
* Collect all submodules (whether checked out or not) for which new
11581157
* commits have been recorded upstream in "changed_submodule_names".
11591158
*/
1160-
collect_changed_submodules(r, &changed_submodules, &argv);
1159+
collect_changed_submodules(r, changed_submodule_names, &argv);
11611160

1162-
for_each_string_list_item(name, &changed_submodules) {
1161+
for_each_string_list_item(name, changed_submodule_names) {
11631162
struct oid_array *commits = name->util;
11641163
const struct submodule *submodule;
11651164
const char *path = NULL;
@@ -1173,12 +1172,14 @@ static void calculate_changed_submodule_paths(struct repository *r,
11731172
if (!path)
11741173
continue;
11751174

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+
}
11791179
}
11801180

1181-
free_submodules_oids(&changed_submodules);
1181+
string_list_remove_empty_items(changed_submodule_names, 1);
1182+
11821183
argv_array_clear(&argv);
11831184
oid_array_clear(&ref_tips_before_fetch);
11841185
oid_array_clear(&ref_tips_after_fetch);
@@ -1389,7 +1390,7 @@ int fetch_populated_submodules(struct repository *r,
13891390

13901391
argv_array_clear(&spf.args);
13911392
out:
1392-
string_list_clear(&spf.changed_submodule_names, 1);
1393+
free_submodules_oids(&spf.changed_submodule_names);
13931394
return spf.result;
13941395
}
13951396

0 commit comments

Comments
 (0)