You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2024/02/28 06:51:09 UTC

(mynewt-newt) branch master updated: newt: Upgrade repos specified in project and package once

This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git


The following commit(s) were added to refs/heads/master by this push:
     new efe37ed2 newt: Upgrade repos specified in project and package once
efe37ed2 is described below

commit efe37ed246cf9dc4b165598cd192b4d6958d7f6d
Author: Michal Gorecki <mi...@codecoup.pl>
AuthorDate: Fri Feb 23 13:58:17 2024 +0100

    newt: Upgrade repos specified in project and package once
    
    Now repos that are specified in both project.yml and pkg.yml
    will be upgraded only once - to the version specified in
    project.yml
---
 newt/install/install.go |  7 +++++++
 newt/project/project.go | 20 ++++++++++++++++----
 newt/repo/repo.go       | 24 ++++++++++++++++++++++++
 3 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/newt/install/install.go b/newt/install/install.go
index f3380e01..8eebff09 100644
--- a/newt/install/install.go
+++ b/newt/install/install.go
@@ -241,6 +241,10 @@ func (inst *Installer) shouldUpgradeRepo(
 		return true, nil
 	}
 
+	if r.IsUpgradedFromProjectYml() {
+		return false, nil
+	}
+
 	if !r.VersionsEqual(*curVer, destVer) {
 		return true, nil
 	}
@@ -590,6 +594,9 @@ func (inst *Installer) Upgrade(candidates []*repo.Repo, force bool,
 		if err := r.Upgrade(destVer); err != nil {
 			return err
 		}
+		if r.IsFromProjectYml() {
+			r.SetIsUpgradedFromProjectYml()
+		}
 		util.StatusMessage(util.VERBOSITY_DEFAULT,
 			"%s successfully upgraded to version %s\n",
 			r.Name(), destVer.String())
diff --git a/newt/project/project.go b/newt/project/project.go
index 754206e7..78651f57 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -172,6 +172,15 @@ func NewProject(dir string, download bool) (*Project, error) {
 	return proj, nil
 }
 
+func (proj *Project) isRepoAdded(r *repo.Repo) bool {
+	for _, pr := range proj.repos {
+		if pr.Name() == r.Name() {
+			return true
+		}
+	}
+	return false
+}
+
 func (proj *Project) GetPkgRepos() error {
 
 	for _, pkgList := range proj.packages {
@@ -199,10 +208,13 @@ func (proj *Project) GetPkgRepos() error {
 								repoName, fields["vers"], err.Error())
 						}
 						r.SetPkgName(pkg.Name())
-						if err := proj.addRepo(r, true); err != nil {
-							return err
+
+						if !proj.isRepoAdded(r) {
+							if err := proj.addRepo(r, true); err != nil {
+								return err
+							}
+							proj.rootRepoReqs[repoName] = verReq
 						}
-						proj.rootRepoReqs[repoName] = verReq
 					}
 				}
 			}
@@ -623,7 +635,7 @@ func (proj *Project) loadConfig(download bool) error {
 						"%s (%s)",
 					repoName, fields["vers"], err.Error())
 			}
-
+			r.SetIsFromProjectYml()
 			if err := proj.addRepo(r, download); err != nil {
 				return err
 			}
diff --git a/newt/repo/repo.go b/newt/repo/repo.go
index 9e624b73..e1b5e6e0 100644
--- a/newt/repo/repo.go
+++ b/newt/repo/repo.go
@@ -66,6 +66,14 @@ type Repo struct {
 	// version => commit
 	vers map[newtutil.RepoVersion]string
 
+	// Since we are calling upgrade twice - first time for repos from project.yml
+	// and second time for repos from packages, we need to keep track on status
+	// of each repo. If repo is defined in project.yml we want to upgrade it only
+	// once so the version from project.yml stays valid. These flags are used for
+	// this purpose.
+	isFromProjectYml         bool
+	isUpgradedFromProjectYml bool
+
 	hasSubmodules bool
 	submodules    []string
 }
@@ -201,6 +209,22 @@ func (r *Repo) patchesFilePath() string {
 		"/.patches/"
 }
 
+func (r *Repo) IsUpgradedFromProjectYml() bool {
+	return r.isUpgradedFromProjectYml
+}
+
+func (r *Repo) SetIsUpgradedFromProjectYml() {
+	r.isUpgradedFromProjectYml = true
+}
+
+func (r *Repo) IsFromProjectYml() bool {
+	return r.isFromProjectYml
+}
+
+func (r *Repo) SetIsFromProjectYml() {
+	r.isFromProjectYml = true
+}
+
 // Checks for repository.yml file presence in specified repo folder.
 // If there is no such file, the repo in specified folder is external.
 func (r *Repo) IsExternal(dir string) bool {