Skip to content

Commit 16b850e

Browse files
Improve newt upgrade
This improves newt upgrade by optimizing the way repos are checked for potential upgrade. Each repo is now checked only once i.e. if it was loaded from project.yml and updated it's not considered for update anymore. This also means no duplicate messages are printed.
1 parent 1462774 commit 16b850e

File tree

3 files changed

+61
-48
lines changed

3 files changed

+61
-48
lines changed

newt/install/install.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,6 @@ func (inst *Installer) shouldUpgradeRepo(
245245
return true, nil
246246
}
247247

248-
if r.IsUpgradedFromProjectYml() {
249-
return false, nil
250-
}
251-
252248
if !r.VersionsEqual(*curVer, destVer) {
253249
return true, nil
254250
}
@@ -269,6 +265,13 @@ func (inst *Installer) filterUpgradeList(
269265
filtered := deprepo.VersionMap{}
270266

271267
for _, name := range vm.SortedNames() {
268+
r := inst.repos[name]
269+
if r.IsCheckedForUpgrade() {
270+
continue
271+
}
272+
273+
inst.repos[name].SetCheckedForUpgrade()
274+
272275
ver := vm[name]
273276
doUpgrade, err := inst.shouldUpgradeRepo(name, ver)
274277
if err != nil {
@@ -570,9 +573,7 @@ func (inst *Installer) Upgrade(candidates []*repo.Repo, force bool,
570573
if err := r.Upgrade(destVer); err != nil {
571574
return err
572575
}
573-
if r.IsFromProjectYml() {
574-
r.SetIsUpgradedFromProjectYml()
575-
}
576+
576577
util.StatusMessage(util.VERBOSITY_DEFAULT,
577578
"%s successfully upgraded to version %s\n",
578579
r.Name(), destVer.String())

newt/project/project.go

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ func (proj *Project) InfoIf(predicate func(r *repo.Repo) bool,
438438
func (proj *Project) loadRepo(name string, fields map[string]string) (
439439
*repo.Repo, error) {
440440

441+
if !proj.isRepoAllowed(name) {
442+
return nil, nil
443+
}
441444
// First, read the repo description from the supplied fields.
442445
if fields["type"] == "" {
443446
return nil,
@@ -455,10 +458,6 @@ func (proj *Project) loadRepo(name string, fields map[string]string) (
455458
return nil, err
456459
}
457460

458-
if !proj.isRepoAllowed(r.Name()) {
459-
return nil, nil
460-
}
461-
462461
for _, ignDir := range ignoreSearchDirs {
463462
r.AddIgnoreDir(ignDir)
464463
}
@@ -576,13 +575,28 @@ func (proj *Project) downloadRepositoryYmlFiles() error {
576575
// Download the `repository.yml` file for each root-level repo (those
577576
// specified in the `project.yml` file).
578577
for _, r := range proj.repos.Sorted() {
579-
if !r.IsLocal() && !r.IsExternal(r.Path()) {
580-
if _, err := r.UpdateDesc(); err != nil {
581-
return err
582-
}
578+
if r.IsUpdated() {
579+
continue
583580
}
581+
582+
if r.IsLocal() {
583+
continue
584+
}
585+
584586
if r.IsExternal(r.Path()) {
585-
r.Downloader().Fetch(r.Path())
587+
ver := proj.rootRepoReqs[r.Name()]
588+
589+
// External repositories can only use commit stability since they do
590+
// not have repository.yml
591+
if len(ver.Commit) == 0 {
592+
return util.FmtNewtError(
593+
"External repository \"%s\" does not specify valid commit version (%s)",
594+
r.Name(), ver.String())
595+
}
596+
}
597+
598+
if _, err := r.UpdateDesc(); err != nil {
599+
return err
586600
}
587601
}
588602

@@ -754,7 +768,7 @@ func (proj *Project) loadConfig(download bool) error {
754768
"%s (%s)",
755769
repoName, fields["vers"], err.Error())
756770
}
757-
r.SetIsFromProjectYml()
771+
758772
if err := proj.addRepo(r, download); err != nil {
759773
return err
760774
}

newt/repo/repo.go

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ type Repo struct {
5555
local bool
5656
ncMap compat.NewtCompatMap
5757

58+
// Indicates if repo was checked for potential upgrade. This avoids checking
59+
// the same repo multiple times in different phases
60+
upgradeChecked bool
61+
5862
// If repo was added from package (not from project.yml), this variable stores name of this package
5963
pkgName string
6064

@@ -67,14 +71,6 @@ type Repo struct {
6771
// version => commit
6872
vers map[newtutil.RepoVersion]string
6973

70-
// Since we are calling upgrade twice - first time for repos from project.yml
71-
// and second time for repos from packages, we need to keep track on status
72-
// of each repo. If repo is defined in project.yml we want to upgrade it only
73-
// once so the version from project.yml stays valid. These flags are used for
74-
// this purpose.
75-
isFromProjectYml bool
76-
isUpgradedFromProjectYml bool
77-
7874
hasSubmodules bool
7975
submodules []string
8076

@@ -227,22 +223,6 @@ func (r *Repo) patchesFilePath() string {
227223
"/.patches/"
228224
}
229225

230-
func (r *Repo) IsUpgradedFromProjectYml() bool {
231-
return r.isUpgradedFromProjectYml
232-
}
233-
234-
func (r *Repo) SetIsUpgradedFromProjectYml() {
235-
r.isUpgradedFromProjectYml = true
236-
}
237-
238-
func (r *Repo) IsFromProjectYml() bool {
239-
return r.isFromProjectYml
240-
}
241-
242-
func (r *Repo) SetIsFromProjectYml() {
243-
r.isFromProjectYml = true
244-
}
245-
246226
// Checks for repository.yml file presence in specified repo folder.
247227
// If there is no such file, the repo in specified folder is external.
248228
func (r *Repo) IsExternal(dir string) bool {
@@ -411,21 +391,39 @@ func (r *Repo) UpdateDesc() (bool, error) {
411391
return false, err
412392
}
413393

414-
// Download `repository.yml`.
415-
if err := r.DownloadDesc(); err != nil {
416-
return false, err
417-
}
394+
if r.IsExternal(r.Path()) {
395+
if err := r.downloader.Fetch(r.Path()); err != nil {
396+
return false, err
397+
}
398+
} else {
399+
// Download `repository.yml`.
400+
if err := r.DownloadDesc(); err != nil {
401+
return false, err
402+
}
418403

419-
// Read `repository.yml` and populate this repo object.
420-
if err := r.Read(); err != nil {
421-
return false, err
404+
// Read `repository.yml` and populate this repo object.
405+
if err := r.Read(); err != nil {
406+
return false, err
407+
}
422408
}
423409

424410
r.updated = true
425411

426412
return true, nil
427413
}
428414

415+
func (r *Repo) IsUpdated() bool {
416+
return r.updated
417+
}
418+
419+
func (r *Repo) SetCheckedForUpgrade() {
420+
r.upgradeChecked = true
421+
}
422+
423+
func (r *Repo) IsCheckedForUpgrade() bool {
424+
return r.upgradeChecked
425+
}
426+
429427
func (r *Repo) EnsureExists() error {
430428
// Clone the repo if it doesn't exist.
431429
if !r.CheckExists() {

0 commit comments

Comments
 (0)