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 2020/03/25 20:47:11 UTC

[mynewt-newt] 01/02: downloader: Return base commit if no rc tag

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 2faa8ca9b2670b724d396d7affd3b88d71d2b089
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Tue Mar 24 16:54:46 2020 -0700

    downloader: Return base commit if no rc tag
    
    downloader.LatestRc() infers the latest "rc" tag given a base string
    (e.g., "mynewt_1_8_0_tag" might resolve to "mynewt_1_8_0_rc3_tag").
    
    If there are no rc tags for the given base, this function used to return
    "".  This is error prone and it requires the caller to stash the base
    string until he has inspected the return value.
    
    This commit changes this function so that it returns the base string
    unmodified if there are no rc tags.
---
 newt/downloader/downloader.go | 11 ++++++-----
 newt/repo/repo.go             |  2 +-
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/newt/downloader/downloader.go b/newt/downloader/downloader.go
index 506b798..2230db1 100644
--- a/newt/downloader/downloader.go
+++ b/newt/downloader/downloader.go
@@ -728,14 +728,11 @@ func (gd *GenericDownloader) LatestRc(path string,
 
 	notag := strings.TrimSuffix(base, "_tag")
 	if notag == base {
-		return "", nil
+		return base, nil
 	}
 
 	restr := fmt.Sprintf("^%s_rc(\\d+)_tag$", regexp.QuoteMeta(notag))
-	re, err := regexp.Compile(restr)
-	if err != nil {
-		return "", util.FmtNewtError("internal error: %s", err.Error())
-	}
+	re := regexp.MustCompile(restr)
 
 	bestNum := -1
 	bestStr := ""
@@ -750,6 +747,10 @@ func (gd *GenericDownloader) LatestRc(path string,
 		}
 	}
 
+	if bestStr == "" {
+		bestStr = base
+	}
+
 	return bestStr, nil
 }
 
diff --git a/newt/repo/repo.go b/newt/repo/repo.go
index 0770c90..5f1ccce 100644
--- a/newt/repo/repo.go
+++ b/newt/repo/repo.go
@@ -291,7 +291,7 @@ func (r *Repo) updateRepo(commit string) error {
 				"Error updating \"%s\": %s", r.Name(), err.Error())
 		}
 
-		if newCommit != "" {
+		if newCommit != commit {
 			util.StatusMessage(util.VERBOSITY_DEFAULT,
 				"in repo \"%s\": commit \"%s\" does not exist; "+
 					"using \"%s\" instead\n",