@@ -70,7 +70,12 @@ type Project struct {
7070 // read.
7171 repos deprepo.RepoMap
7272
73- // Contains names of repositories that will not be upgraded/downloaded.
73+ // Contains names of repositories that will be upgraded.
74+ // If it's empty all repos are allowed.
75+ reposAllowed []string
76+
77+ // Contains names of repositories that will be excluded from upgrade.
78+ // Can override repositories from reposAllowed.
7479 reposIgnored []string
7580
7681 // The local repository at the top-level of the project. This repo is
@@ -176,9 +181,16 @@ func NewProject(dir string, download bool) (*Project, error) {
176181 return proj , nil
177182}
178183
179- func (proj * Project ) isRepoAdded (r * repo.Repo ) bool {
184+ func (proj * Project ) isRepoAllowed (repoName string ) bool {
185+ if (len (proj .reposAllowed ) == 0 ) || (util .SliceContains (proj .reposAllowed , repoName )) {
186+ return ! util .SliceContains (proj .reposIgnored , repoName )
187+ }
188+ return false
189+ }
190+
191+ func (proj * Project ) isRepoAdded (repoName string ) bool {
180192 for _ , pr := range proj .repos {
181- if pr .Name () == r . Name () {
193+ if pr .Name () == repoName {
182194 return true
183195 }
184196 }
@@ -191,7 +203,7 @@ func (proj *Project) GetPkgRepos() error {
191203 if pkg .PkgConfig ().HasKey ("repository" ) {
192204 for k , _ := range pkg .PkgConfig ().AllSettings () {
193205 repoName := strings .TrimPrefix (k , "repository." )
194- if repoName != k && ! util . SliceContains ( proj . reposIgnored , repoName ) {
206+ if repoName != k {
195207 fields , err := pkg .PkgConfig ().GetValStringMapString (k , nil )
196208 util .OneTimeWarningError (err )
197209
@@ -203,6 +215,10 @@ func (proj *Project) GetPkgRepos() error {
203215 return err
204216 }
205217 }
218+ if r == nil {
219+ continue
220+ }
221+
206222 verReq , err := newtutil .ParseRepoVersion (fields ["vers" ])
207223 if err != nil {
208224 return util .FmtNewtError (
@@ -212,7 +228,7 @@ func (proj *Project) GetPkgRepos() error {
212228 }
213229 r .SetPkgName (pkg .Name ())
214230
215- if ! proj .isRepoAdded (r ) {
231+ if ! proj .isRepoAdded (r . Name () ) {
216232 if err := proj .addRepo (r , true ); err != nil {
217233 return err
218234 }
@@ -405,7 +421,7 @@ func (proj *Project) InfoIf(predicate func(r *repo.Repo) bool,
405421// @param name The name of the repo to read.
406422// @param fields Fields containing the basic repo description.
407423//
408- // @return *Repo The fully-read repo on success; nil on failure.
424+ // @return *Repo The fully-read repo on success; nil on failure or when repo is not allowed
409425// @return error Error on failure.
410426func (proj * Project ) loadRepo (name string , fields map [string ]string ) (
411427 * repo.Repo , error ) {
@@ -427,12 +443,16 @@ func (proj *Project) loadRepo(name string, fields map[string]string) (
427443 return nil , err
428444 }
429445
446+ if ! proj .isRepoAllowed (r .Name ()) {
447+ return nil , nil
448+ }
449+
430450 for _ , ignDir := range ignoreSearchDirs {
431451 r .AddIgnoreDir (ignDir )
432452 }
433453
434454 // Read the full repo definition from its `repository.yml` file.
435- if err := r .Read (proj . reposIgnored ); err != nil {
455+ if err := r .Read (); err != nil {
436456 return r , err
437457 }
438458
@@ -500,14 +520,17 @@ func (proj *Project) loadRepoDeps(download bool) error {
500520 return nil , err
501521 }
502522 }
523+ if depRepo == nil {
524+ continue
525+ }
503526 if err := proj .addRepo (depRepo , download ); err != nil {
504527 return nil , err
505528 }
506529 }
507530 newRepos = append (newRepos , depRepo )
508531
509532 if download {
510- if _ , err := depRepo .UpdateDesc (proj . reposIgnored ); err != nil {
533+ if _ , err := depRepo .UpdateDesc (); err != nil {
511534 return nil , err
512535 }
513536 }
@@ -542,7 +565,7 @@ func (proj *Project) downloadRepositoryYmlFiles() error {
542565 // specified in the `project.yml` file).
543566 for _ , r := range proj .repos .Sorted () {
544567 if ! r .IsLocal () && ! r .IsExternal (r .Path ()) {
545- if _ , err := r .UpdateDesc (proj . reposIgnored ); err != nil {
568+ if _ , err := r .UpdateDesc (); err != nil {
546569 return err
547570 }
548571 }
@@ -631,14 +654,18 @@ func (proj *Project) loadConfig(download bool) error {
631654 proj .name , err = yc .GetValString ("project.name" , nil )
632655 util .OneTimeWarningError (err )
633656
657+ proj .reposAllowed = make ([]string , 0 )
658+ proj .reposAllowed , err = yc .GetValStringSlice ("project.repositories.allowed" , nil )
659+ util .OneTimeWarningError (err )
660+
634661 proj .reposIgnored = make ([]string , 0 )
635662 proj .reposIgnored , err = yc .GetValStringSlice ("project.repositories.ignored" , nil )
636663 util .OneTimeWarningError (err )
637664 proj .reposIgnored = append (proj .reposIgnored , newtutil .NewtIgnore ... )
638665
639- if util . SliceContains ( proj .reposIgnored , "apache-mynewt-core" ) {
640- return util .NewNewtError ("apache-mynewt-core repository can't be ignored . " +
641- "Please remove it from the ignored repositories list." )
666+ if ! proj .isRepoAllowed ( "apache-mynewt-core" ) {
667+ return util .NewNewtError ("apache-mynewt-core repository must be allowed . " +
668+ "Please add it to the allowed list and/or remove it from the ignored list." )
642669 }
643670
644671 // Local repository always included in initialization
@@ -669,6 +696,10 @@ func (proj *Project) loadConfig(download bool) error {
669696 return err
670697 }
671698 }
699+ if r == nil {
700+ continue
701+ }
702+
672703 verReq , err := newtutil .ParseRepoVersion (fields ["vers" ])
673704 if err != nil {
674705 return util .FmtNewtError (
0 commit comments