You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2018/10/29 20:14:19 UTC

[mynewt-newt] branch master updated (6cde323 -> 070430f)

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

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


    from 6cde323  sysdown: generate package shutdown function
     new 40ab38e  Ensure warnings only displayed once
     new 0c3c856  Remove redundant version detection warning
     new 070430f  Allow branches with no default upstream

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 newt/downloader/downloader.go | 16 +++++++++++-----
 newt/install/install.go       | 26 +++++++++++++-------------
 newt/newtutil/newtutil.go     | 14 ++++++++++++++
 newt/project/project.go       |  8 ++------
 newt/repo/version.go          | 13 ++++++-------
 newt/syscfg/restrict.go       |  6 +++---
 6 files changed, 49 insertions(+), 34 deletions(-)


[mynewt-newt] 01/03: Ensure warnings only displayed once

Posted by cc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 40ab38e7998b536eb47837e188ae08b8d510c4ba
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Fri Oct 19 11:43:57 2018 -0700

    Ensure warnings only displayed once
    
    Some warnings were displayed repeatedly.  Only display each warnings
    once.
---
 newt/downloader/downloader.go |  7 ++++---
 newt/install/install.go       | 18 +++++++++---------
 newt/newtutil/newtutil.go     | 14 ++++++++++++++
 newt/project/project.go       |  4 ++--
 newt/repo/version.go          | 13 ++++++-------
 newt/syscfg/restrict.go       |  6 +++---
 6 files changed, 38 insertions(+), 24 deletions(-)

diff --git a/newt/downloader/downloader.go b/newt/downloader/downloader.go
index 58d8cda..ac0f113 100644
--- a/newt/downloader/downloader.go
+++ b/newt/downloader/downloader.go
@@ -30,6 +30,7 @@ import (
 
 	log "github.com/Sirupsen/logrus"
 
+	"mynewt.apache.org/newt/newt/newtutil"
 	"mynewt.apache.org/newt/newt/settings"
 	"mynewt.apache.org/newt/util"
 )
@@ -420,9 +421,9 @@ func setRemoteUrl(path string, remote string, url string, logCmd bool) error {
 }
 
 func warnWrongOriginUrl(path string, curUrl string, goodUrl string) {
-	util.StatusMessage(util.VERBOSITY_QUIET,
-		"WARNING: Repo's \"origin\" remote points to unexpected URL: "+
-			"%s; correcting it to %s.  Repo contents may be incorrect.\n",
+	newtutil.OneTimeWarning(
+		"Repo's \"origin\" remote points to unexpected URL: "+
+			"%s; correcting it to %s.  Repo contents may be incorrect.",
 		curUrl, goodUrl)
 }
 
diff --git a/newt/install/install.go b/newt/install/install.go
index ce32349..e97eb0f 100644
--- a/newt/install/install.go
+++ b/newt/install/install.go
@@ -121,11 +121,11 @@ import (
 
 	log "github.com/Sirupsen/logrus"
 
+	"mynewt.apache.org/newt/newt/compat"
 	"mynewt.apache.org/newt/newt/deprepo"
 	"mynewt.apache.org/newt/newt/newtutil"
 	"mynewt.apache.org/newt/newt/repo"
 	"mynewt.apache.org/newt/util"
-	"mynewt.apache.org/newt/newt/compat"
 )
 
 type installOp int
@@ -157,9 +157,9 @@ func detectVersion(r *repo.Repo) (newtutil.RepoVersion, error) {
 			Commit: commit,
 		}
 
-		util.StatusMessage(util.VERBOSITY_QUIET,
-			"WARNING: Could not detect version of installed repo \"%s\"; "+
-				"assuming %s\n", r.Name(), ver.String())
+		newtutil.OneTimeWarning(
+			"Could not detect version of installed repo \"%s\"; assuming %s",
+			r.Name(), ver.String())
 	}
 
 	log.Debugf("currently installed version of repo \"%s\": %s",
@@ -292,9 +292,9 @@ func (inst *Installer) inferReqVers(repos []*repo.Repo) error {
 					}
 
 					if ver == nil {
-						util.StatusMessage(util.VERBOSITY_QUIET,
-							"WARNING: Could not detect version of "+
-								"requested repo %s:%s; assuming 0.0.0\n",
+						newtutil.OneTimeWarning(
+							"Could not detect version of requested repo "+
+								"%s:%s; assuming 0.0.0",
 							r.Name(), req.Ver.Commit)
 
 						ver = &req.Ver
@@ -732,7 +732,7 @@ func verifyRepoDirtyState(repos []*repo.Repo, force bool) error {
 			s += "Specify the `-f` (force) switch to attempt anyway"
 			return util.NewNewtError(s)
 		} else {
-			util.StatusMessage(util.VERBOSITY_QUIET, "WARNING: %s\n", s)
+			newtutil.OneTimeWarning("%s", s)
 		}
 	}
 
@@ -749,7 +749,7 @@ func verifyNewtCompat(repos []*repo.Repo, vm deprepo.VersionMap) error {
 
 		switch code {
 		case compat.NEWT_COMPAT_WARN:
-			util.StatusMessage(util.VERBOSITY_QUIET, "WARNING: %s\n", msg)
+			newtutil.OneTimeWarning("%s", msg)
 		case compat.NEWT_COMPAT_ERROR:
 			errors = append(errors, msg)
 		}
diff --git a/newt/newtutil/newtutil.go b/newt/newtutil/newtutil.go
index 5b83bc8..258afab 100644
--- a/newt/newtutil/newtutil.go
+++ b/newt/newtutil/newtutil.go
@@ -201,3 +201,17 @@ func ReadConfig(dir string, filename string) (ycfg.YCfg, error) {
 func YCfgToYaml(yc ycfg.YCfg) string {
 	return yaml.MapToYaml(yc.AllSettings())
 }
+
+// Keeps track of warnings that have already been reported.
+// [warning-text] => struct{}
+var warnings = map[string]struct{}{}
+
+// Displays the specified warning if it has not been displayed yet.
+func OneTimeWarning(text string, args ...interface{}) {
+	if _, ok := warnings[text]; !ok {
+		warnings[text] = struct{}{}
+
+		body := fmt.Sprintf(text, args...)
+		util.StatusMessage(util.VERBOSITY_QUIET, "WARNING: %s\n", body)
+	}
+}
diff --git a/newt/project/project.go b/newt/project/project.go
index e638d58..b7944e5 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -396,7 +396,7 @@ func (proj *Project) checkNewtVer() error {
 	case compat.NEWT_COMPAT_GOOD:
 		return nil
 	case compat.NEWT_COMPAT_WARN:
-		util.StatusMessage(util.VERBOSITY_QUIET, "WARNING: %s.\n", msg)
+		newtutil.OneTimeWarning("%s", msg)
 		return nil
 	case compat.NEWT_COMPAT_ERROR:
 		return util.NewNewtError(msg)
@@ -500,7 +500,7 @@ func (proj *Project) verifyNewtCompat() error {
 			switch code {
 			case compat.NEWT_COMPAT_GOOD:
 			case compat.NEWT_COMPAT_WARN:
-				util.StatusMessage(util.VERBOSITY_QUIET, "WARNING: %s.\n", msg)
+				newtutil.OneTimeWarning("%s", msg)
 			case compat.NEWT_COMPAT_ERROR:
 				errors = append(errors, msg)
 			}
diff --git a/newt/repo/version.go b/newt/repo/version.go
index ae00f7c..d8dbfa2 100644
--- a/newt/repo/version.go
+++ b/newt/repo/version.go
@@ -392,9 +392,8 @@ func (r *Repo) inferVersion(commit string, vyVer *newtutil.RepoVersion) (
 				}
 			}
 
-			util.StatusMessage(util.VERBOSITY_QUIET,
-				"WARNING: Version mismatch in %s:%s; "+
-					"repository.yml:%s, version.yml:%s\n",
+			newtutil.OneTimeWarning(
+				"Version mismatch in %s:%s; repository.yml:%s, version.yml:%s",
 				r.Name(), commit, versString(ryVers), vyVer.String())
 		} else {
 			// If the set of commits don't match a version from
@@ -464,12 +463,12 @@ func (r *Repo) NonInstalledVersion(
 
 	if ver == nil {
 		if versionYmlErr == versionYmlMissing {
-			util.StatusMessage(util.VERBOSITY_QUIET,
-				"WARNING: %s:%s does not contain a `version.yml` file.\n",
+			newtutil.OneTimeWarning(
+				"%s:%s does not contain a `version.yml` file.",
 				r.Name(), commit)
 		} else if versionYmlErr == versionYmlBad {
-			util.StatusMessage(util.VERBOSITY_QUIET,
-				"WARNING: %s:%s contains a malformed `version.yml` file.\n",
+			newtutil.OneTimeWarning(
+				"%s:%s contains a malformed `version.yml` file.",
 				r.Name(), commit)
 		}
 	}
diff --git a/newt/syscfg/restrict.go b/newt/syscfg/restrict.go
index c998fce..fe1ca83 100644
--- a/newt/syscfg/restrict.go
+++ b/newt/syscfg/restrict.go
@@ -59,8 +59,8 @@ import (
 
 	log "github.com/Sirupsen/logrus"
 
+	"mynewt.apache.org/newt/newt/newtutil"
 	"mynewt.apache.org/newt/newt/parse"
-	"mynewt.apache.org/newt/util"
 )
 
 type CfgRestrictionCode int
@@ -201,8 +201,8 @@ func (cfg *Cfg) restrictionMet(
 
 		val, err := parse.ParseAndEval(expr, settings)
 		if err != nil {
-			util.StatusMessage(util.VERBOSITY_QUIET,
-				"WARNING: ignoring illegal expression for setting \"%s\": "+
+			newtutil.OneTimeWarning(
+				"Ignoring illegal expression for setting \"%s\": "+
 					"`%s` %s\n", r.BaseSetting, r.Expr, err.Error())
 			return true
 		}


[mynewt-newt] 03/03: Allow branches with no default upstream

Posted by cc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 070430fc3c799bbc58f7a73b3fc50709c4a81cb7
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Fri Oct 19 11:50:45 2018 -0700

    Allow branches with no default upstream
    
    Some commands would fail when a repo had a branch with no default
    upstream checked out.  The failures were as follows:
    
    * `newt info`: Displayed a git "fatal" error instead of the correct
    version (inferred version if `version.yml` is not present).
    
    * `newt upgrade`: Aborted without performing the upgrade (displayed the
    same "fatal" git error).
---
 newt/downloader/downloader.go | 9 +++++++--
 newt/install/install.go       | 8 ++++----
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/newt/downloader/downloader.go b/newt/downloader/downloader.go
index ac0f113..02f54fa 100644
--- a/newt/downloader/downloader.go
+++ b/newt/downloader/downloader.go
@@ -557,13 +557,18 @@ func (gd *GenericDownloader) DirtyState(path string) (string, error) {
 		return "staged changes", nil
 	}
 
-	// If on a branch, check for unpushed commits.
+	// If on a branch with a configured upstream, check for unpushed commits.
 	branch, err := gd.CurrentBranch(path)
 	if err != nil {
 		return "", err
 	}
 
-	if branch != "" {
+	upstream, err := upstreamFor(path, "HEAD")
+	if err != nil {
+		return "", err
+	}
+
+	if upstream != "" && branch != "" {
 		cmd = []string{
 			"rev-list",
 			"@{u}..",
diff --git a/newt/install/install.go b/newt/install/install.go
index e97eb0f..7f3d0d5 100644
--- a/newt/install/install.go
+++ b/newt/install/install.go
@@ -935,7 +935,7 @@ func (inst *Installer) Sync(candidates []*repo.Repo,
 }
 
 type repoInfo struct {
-	installedVer *newtutil.RepoVersion
+	installedVer *newtutil.RepoVersion // nil if not installed.
 	errorText    string
 	dirtyState   string
 	needsUpgrade bool
@@ -953,12 +953,12 @@ func (inst *Installer) gatherInfo(r *repo.Repo,
 		return ri
 	}
 
-	ver, err := r.InstalledVersion()
+	ver, err := detectVersion(r)
 	if err != nil {
 		ri.errorText = strings.TrimSpace(err.Error())
 		return ri
 	}
-	ri.installedVer = ver
+	ri.installedVer = &ver
 
 	dirty, err := r.DirtyState()
 	if err != nil {
@@ -968,7 +968,7 @@ func (inst *Installer) gatherInfo(r *repo.Repo,
 	ri.dirtyState = dirty
 
 	if vm != nil {
-		if ver == nil || *ver != (*vm)[r.Name()] {
+		if ver != (*vm)[r.Name()] {
 			ri.needsUpgrade = true
 		}
 	}


[mynewt-newt] 02/03: Remove redundant version detection warning

Posted by cc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0c3c8563f80d4839f88efda353433a535ee6e8da
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Fri Oct 19 11:44:22 2018 -0700

    Remove redundant version detection warning
    
    This particular "Could not detect version of installed repo" warning was
    reported in two places in the code.  Eliminate one of these redundant
    instances.
---
 newt/project/project.go | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/newt/project/project.go b/newt/project/project.go
index b7944e5..34adc7b 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -210,10 +210,6 @@ func (proj *Project) GetRepoVersion(
 
 		if _, ok := proj.unknownRepoVers[rname]; !ok {
 			proj.unknownRepoVers[rname] = struct{}{}
-
-			util.StatusMessage(util.VERBOSITY_QUIET,
-				"WARNING: Could not detect version of installed repo \"%s\"; "+
-					"assuming 0.0.0/%s\n", r.Name(), commit)
 		}
 		ver = &newtutil.RepoVersion{
 			Commit: commit,