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 ebb93f67fe7fadba49186df74fd9ade9e586405d
Author: Christopher Collins <ccoll...@apache.org>
AuthorDate: Thu Aug 1 15:45:40 2019 -0700

    Fix `newt upgrade <repo-list>`
    
    The `newt upgrade` command optionally takes a list of repos to upgrade.
    The intended behavior is: when specified, only these repos (and their
    dependencies) get upgraded rather than the entire project.
    
    This was broken by a recent commit
    (6a51e35565323ebe8feb8d1aa6e00960b6ce662e).  If a repo list is
    specified, newt reports repository conflicts for all repos in the
    project that were not specified.
    
    Now, newt correctly upgrades only the specified repos and their
    dependencies.  No conflicts are reported for other repos.
    
    (As always, if no repo list is specified, all repos in the project get
    upgraded.)
---
 newt/deprepo/deprepo.go | 18 ++++++++++++++++++
 newt/install/install.go |  4 ++++
 2 files changed, 22 insertions(+)

diff --git a/newt/deprepo/deprepo.go b/newt/deprepo/deprepo.go
index 70aee82..c6878dc 100644
--- a/newt/deprepo/deprepo.go
+++ b/newt/deprepo/deprepo.go
@@ -231,6 +231,24 @@ func PruneMatrix(m *Matrix, repos RepoMap, rootReqs 
RequirementMap) error {
        return nil
 }
 
+// PruneDepGraph removes all entries from a depgraph that aren't in the given
+// repo slice.  This is necessary when the user wants to upgrade only a subset
+// of repos in the project.
+func PruneDepGraph(dg DepGraph, keep []*repo.Repo) {
+       for k, _ := range dg {
+               found := false
+               for _, r := range keep {
+                       if r.Name() == k.Name {
+                               found = true
+                               break
+                       }
+               }
+               if !found {
+                       delete(dg, k)
+               }
+       }
+}
+
 // Produces an error describing the specified set of repo conflicts.
 func ConflictError(conflicts []Conflict) error {
        s := ""
diff --git a/newt/install/install.go b/newt/install/install.go
index 5244999..398cfc3 100644
--- a/newt/install/install.go
+++ b/newt/install/install.go
@@ -669,6 +669,10 @@ func (inst *Installer) calcVersionMap(candidates 
[]*repo.Repo) (
        log.Debugf("Repo dependency graph:\n%s\n", dg.String())
        log.Debugf("Repo reverse dependency graph:\n%s\n", 
dg.Reverse().String())
 
+       // Don't consider repos that the user excluded (if a repo list was
+       // specified).
+       deprepo.PruneDepGraph(dg, candidates)
+
        // Try to find a version set that satisfies the dependency graph.  If no
        // such set exists, report the conflicts and abort.
        vm, conflicts := deprepo.FindAcceptableVersions(m, dg)

Reply via email to