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 2019/11/21 02:49:15 UTC

[mynewt-newt] branch master updated: Allow project.yml to override commit versions

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


View the commit online:
https://github.com/apache/mynewt-newt/commit/fffae9bf8db884afa8c21d230b8bd3ee39287af3

The following commit(s) were added to refs/heads/master by this push:
     new fffae9b  Allow project.yml to override commit versions
fffae9b is described below

commit fffae9bf8db884afa8c21d230b8bd3ee39287af3
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Wed Nov 20 17:01:11 2019 -0800

    Allow project.yml to override commit versions
    
    (note: a "commit version" is a repo version that specifies a git commit,
    e.g., `f20a9d358f996979b047f1a947e3fd14e583d1fd-commit`).
    
    During upgrade, newt collects repo dependencies from project.yml and
    from each repository's dependency list.  If there are two dependencies
    on different commit versions of the same repo, newt reports a conflict.
    E.g., if
    
        project.yml depends on 0-commit of repo bar, and
           repo foo depends on 1-commit of repo bar
    
    newt complains and aborts the upgrade.
    
    This commit relaxes this behavior a bit by allowing dependencies in
    project.yml to override inter-repo dependencies.  In the above example,
    newt would checkout 0-commit of bar.
    
    Newt still reports an error if the conflict comes from two repo
    dependencies (as opposed to a project.yml dependency).
---
 newt/install/install.go | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/newt/install/install.go b/newt/install/install.go
index 00f7b42..756ce86 100644
--- a/newt/install/install.go
+++ b/newt/install/install.go
@@ -596,9 +596,10 @@ func (inst *Installer) versionMapRepos(
 
 // assignCommits applies commit hashes to the selected version of each repo in
 // a version map.  In other words, it propagates `<...>-commit` requirements
-// from `project.yml` and `repository.yml` files.
+// from `project.yml` and `repository.yml` files.  If override is false,
+// attempting to set a commit for the same repo twice results in an error.
 func (inst *Installer) assignCommits(vm deprepo.VersionMap, repoName string,
-	reqs []newtutil.RepoVersionReq) error {
+	reqs []newtutil.RepoVersionReq, override bool) error {
 
 	for _, req := range reqs {
 		curVer := vm[repoName]
@@ -609,7 +610,7 @@ func (inst *Installer) assignCommits(vm deprepo.VersionMap, repoName string,
 			}
 
 			if keep {
-				if vm[repoName].Commit != "" {
+				if !override && vm[repoName].Commit != "" {
 					return util.FmtNewtError(
 						"repo %s: multiple commits: %s, %s",
 						repoName, vm[repoName].Commit, req.Ver.Commit)
@@ -677,24 +678,25 @@ func (inst *Installer) calcVersionMap(candidates []*repo.Repo) (
 		return nil, deprepo.ConflictError(conflicts)
 	}
 
-	// If project.yml specified any specific git commits, ensure we get them.
-	for name, reqs := range inst.reqs {
-		if err := inst.assignCommits(vm, name, reqs); err != nil {
-			return nil, err
-		}
-	}
-
 	// If repos specify git commits in their repo-dependencies, ensure we get
 	// them.
 	rg := dg.Reverse()
 	for name, nodes := range rg {
 		for _, node := range nodes {
-			if err := inst.assignCommits(vm, name, node.VerReqs); err != nil {
+			if err := inst.assignCommits(vm, name, node.VerReqs, false); err != nil {
 				return nil, err
 			}
 		}
 	}
 
+	// If project.yml specified any specific git commits, ensure we get them.
+	// Commits specified in project.yml override those from repo-dependencies.
+	for name, reqs := range inst.reqs {
+		if err := inst.assignCommits(vm, name, reqs, true); err != nil {
+			return nil, err
+		}
+	}
+
 	// Now that we know which repo versions we want, we can eliminate some
 	// false-positives from the repo list.
 	repoList = inst.ensureDepsInList(candidates, vm)