@@ -806,6 +806,20 @@ static const char *default_name_or_path(const char *path_or_name)
806806 return path_or_name ;
807807}
808808
809+ /*
810+ * Holds relevant information for a changed submodule. Used as the .util
811+ * member of the changed submodule string_list_item.
812+ */
813+ struct changed_submodule_data {
814+ /* The submodule commits that have changed in the rev walk. */
815+ struct oid_array new_commits ;
816+ };
817+
818+ static void changed_submodule_data_clear (struct changed_submodule_data * cs_data )
819+ {
820+ oid_array_clear (& cs_data -> new_commits );
821+ }
822+
809823static void collect_changed_submodules_cb (struct diff_queue_struct * q ,
810824 struct diff_options * options ,
811825 void * data )
@@ -820,6 +834,7 @@ static void collect_changed_submodules_cb(struct diff_queue_struct *q,
820834 const struct submodule * submodule ;
821835 const char * name ;
822836 struct string_list_item * item ;
837+ struct changed_submodule_data * cs_data ;
823838
824839 if (!S_ISGITLINK (p -> two -> mode ))
825840 continue ;
@@ -848,9 +863,9 @@ static void collect_changed_submodules_cb(struct diff_queue_struct *q,
848863
849864 item = string_list_insert (changed , name );
850865 if (!item -> util )
851- /* NEEDSWORK: should we have oid_array_init()? */
852- item -> util = xcalloc ( 1 , sizeof ( struct oid_array )) ;
853- oid_array_append (item -> util , & p -> two -> oid );
866+ item -> util = xcalloc ( 1 , sizeof ( struct changed_submodule_data ));
867+ cs_data = item -> util ;
868+ oid_array_append (& cs_data -> new_commits , & p -> two -> oid );
854869 }
855870}
856871
@@ -897,11 +912,12 @@ static void collect_changed_submodules(struct repository *r,
897912 reset_revision_walk ();
898913}
899914
900- static void free_submodules_oids (struct string_list * submodules )
915+ static void free_submodules_data (struct string_list * submodules )
901916{
902917 struct string_list_item * item ;
903918 for_each_string_list_item (item , submodules )
904- oid_array_clear ((struct oid_array * ) item -> util );
919+ changed_submodule_data_clear (item -> util );
920+
905921 string_list_clear (submodules , 1 );
906922}
907923
@@ -1074,7 +1090,7 @@ int find_unpushed_submodules(struct repository *r,
10741090 collect_changed_submodules (r , & submodules , & argv );
10751091
10761092 for_each_string_list_item (name , & submodules ) {
1077- struct oid_array * commits = name -> util ;
1093+ struct changed_submodule_data * cs_data = name -> util ;
10781094 const struct submodule * submodule ;
10791095 const char * path = NULL ;
10801096
@@ -1087,11 +1103,11 @@ int find_unpushed_submodules(struct repository *r,
10871103 if (!path )
10881104 continue ;
10891105
1090- if (submodule_needs_pushing (r , path , commits ))
1106+ if (submodule_needs_pushing (r , path , & cs_data -> new_commits ))
10911107 string_list_insert (needs_pushing , path );
10921108 }
10931109
1094- free_submodules_oids (& submodules );
1110+ free_submodules_data (& submodules );
10951111 strvec_clear (& argv );
10961112
10971113 return needs_pushing -> nr ;
@@ -1261,7 +1277,7 @@ static void calculate_changed_submodule_paths(struct repository *r,
12611277 collect_changed_submodules (r , changed_submodule_names , & argv );
12621278
12631279 for_each_string_list_item (name , changed_submodule_names ) {
1264- struct oid_array * commits = name -> util ;
1280+ struct changed_submodule_data * cs_data = name -> util ;
12651281 const struct submodule * submodule ;
12661282 const char * path = NULL ;
12671283
@@ -1274,8 +1290,8 @@ static void calculate_changed_submodule_paths(struct repository *r,
12741290 if (!path )
12751291 continue ;
12761292
1277- if (submodule_has_commits (r , path , null_oid (), commits )) {
1278- oid_array_clear ( commits );
1293+ if (submodule_has_commits (r , path , null_oid (), & cs_data -> new_commits )) {
1294+ changed_submodule_data_clear ( cs_data );
12791295 * name -> string = '\0' ;
12801296 }
12811297 }
@@ -1312,7 +1328,7 @@ int submodule_touches_in_range(struct repository *r,
13121328
13131329 strvec_clear (& args );
13141330
1315- free_submodules_oids (& subs );
1331+ free_submodules_data (& subs );
13161332 return ret ;
13171333}
13181334
@@ -1596,7 +1612,7 @@ static int fetch_finish(int retvalue, struct strbuf *err,
15961612 struct fetch_task * task = task_cb ;
15971613
15981614 struct string_list_item * it ;
1599- struct oid_array * commits ;
1615+ struct changed_submodule_data * cs_data ;
16001616
16011617 if (!task || !task -> sub )
16021618 BUG ("callback cookie bogus" );
@@ -1624,14 +1640,14 @@ static int fetch_finish(int retvalue, struct strbuf *err,
16241640 /* Could be an unchanged submodule, not contained in the list */
16251641 goto out ;
16261642
1627- commits = it -> util ;
1628- oid_array_filter (commits ,
1643+ cs_data = it -> util ;
1644+ oid_array_filter (& cs_data -> new_commits ,
16291645 commit_missing_in_sub ,
16301646 task -> repo );
16311647
16321648 /* Are there commits we want, but do not exist? */
1633- if (commits -> nr ) {
1634- task -> commits = commits ;
1649+ if (cs_data -> new_commits . nr ) {
1650+ task -> commits = & cs_data -> new_commits ;
16351651 ALLOC_GROW (spf -> oid_fetch_tasks ,
16361652 spf -> oid_fetch_tasks_nr + 1 ,
16371653 spf -> oid_fetch_tasks_alloc );
@@ -1689,7 +1705,7 @@ int fetch_populated_submodules(struct repository *r,
16891705
16901706 strvec_clear (& spf .args );
16911707out :
1692- free_submodules_oids (& spf .changed_submodule_names );
1708+ free_submodules_data (& spf .changed_submodule_names );
16931709 return spf .result ;
16941710}
16951711
0 commit comments