Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

newt: Upgrade repos specified in project and package only once #544

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions newt/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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())
Expand Down
20 changes: 16 additions & 4 deletions newt/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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
}
Expand Down
24 changes: 24 additions & 0 deletions newt/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
Loading