]> xenbits.xensource.com Git - people/gdunlap/xsatool/commitdiff
Fix "backport needed" detection
authorGeorge Dunlap <george.dunlap@citrix.com>
Tue, 13 Mar 2018 17:59:51 +0000 (17:59 +0000)
committerGeorge Dunlap <george.dunlap@citrix.com>
Tue, 13 Mar 2018 17:59:51 +0000 (17:59 +0000)
VersionsFromArgs() and MainBackport() were both using
xsa.RepoHasPatches() for slightly different things neither of them
quite correct.

xsa.RepoHasPatches() was checking to see that 1) a recipe existed, and
2) a "patch branch" existed.  At some point these basically became
identical, and so this test stopped behaving as expected.

VersionsFromArgs() wants to know what versions it should use if
nothing (or "all") is specified.  So a add new method, "HasRecipe()",
which simply checks to see if a recipe exists (even if it's empty).

MainBackport() wants to know if we need to perform a backport for a
particular version.  Add a new method, NeedsBackport() which answers
this question directly.  Return true if:

* A recipe exists and it's empty

* MakePatches() wouldn't make any patches given the current tree state
-- that is, xsa/NNN-baseline == xsa/NNN.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
main.go
meta.go
recipe.go
xsa.go

diff --git a/main.go b/main.go
index 5230e4129a1c95d0971576a73aa9e53d1fc2b362..c7890fe4735ecd9b117ce887bac211d56847aacf 100644 (file)
--- a/main.go
+++ b/main.go
@@ -56,7 +56,7 @@ func VersionsFromArgs(xsa *XSAMeta, args []string, hasPatches bool) (vers []XenV
        if len(args) == 0 || (len(args) == 1 && args[0] == "all") {
                for _, v := range xsa.SupportedVersions {
                        // Check to see if the branch exists
-                       if hasPatches && !xsa.RepoHasPatches(v) {
+                       if hasPatches && !xsa.HasRecipe(v) {
                                // FIXME: Should this be "break" instead?
                                continue
                        }
diff --git a/meta.go b/meta.go
index 1073052a128d650dad7afc1cfbdd7a58940eb3cd..e94e735526dfe78a7159f9b804081a2311867846 100644 (file)
--- a/meta.go
+++ b/meta.go
@@ -291,14 +291,22 @@ func (m *XSAMeta) NewRecipe(v XenVersion) *Recipe {
        return &r
 }
 
-func (m *XSAMeta) RepoHasPatches(v XenVersion) bool {
+// Return 'true' if there's a recipe (even empty)
+func (m *XSAMeta) HasRecipe(v XenVersion) bool {
+       return m.GetRecipe(v) != nil 
+}
+
+// Return 'true' if:
+// * There's a recipe for this version and it's empty
+// * There are no patches in the target branch
+func (m *XSAMeta) NeedsBackport(v XenVersion) bool {
        r := m.GetRecipe(v)
 
-       if r == nil {
+       if r == nil || r.HasPatches() {
                return false
        }
 
-       return r.HasPatchBranch("xsa") == nil
+       return !r.RepoHasPatches("xsa")
 }
 
 func getXSAPath(xsanum int) string {
index 71d12d3b99d76b96c27d139363f5d7a370bda626..e15e6347d924e4acadaf9ce18de80d65bfab6b13 100644 (file)
--- a/recipe.go
+++ b/recipe.go
@@ -114,6 +114,37 @@ func (r *Recipe) HasPatches() (has bool) {
        return
 }
 
+// Return 'true' if all repo branches are valid, and contain patches
+func (r *Recipe) RepoHasPatches(prefix string) (bool) {
+       _, baseline, branch := r.branchName(prefix)
+
+       err := r.ForEachTree(func(tree Tree) error {
+               xr := G.repos.GetRepoNC(tree)
+
+               branchHash, err := xr.ParseRef(branch)
+               if err != nil {
+                       return err
+               }
+
+               baseHash, err := xr.ParseRef(baseline)
+               if err != nil {
+                       return err
+               }
+
+               if branchHash == "" || baseHash == "" {
+                       return fmt.Errorf("Branch missing")
+               }
+
+               if branchHash == baseHash {
+                       return fmt.Errorf("No patches between base and branch")
+               }
+
+               return nil
+       })
+       
+       return err == nil
+}
+
 func (r *Recipe) MakePatches(prefix string, sync bool) (count int, err error) {
        _, baseline, branch := r.branchName(prefix)
 
diff --git a/xsa.go b/xsa.go
index e222efd2946f23b512421edae29ec4daf3abfa5b..0392143f8687ddf81178b5c13da03061fcac94dc 100644 (file)
--- a/xsa.go
+++ b/xsa.go
@@ -204,8 +204,8 @@ func MainBackport(xsa *XSAMeta, args []string) (ret int) {
        for _, to := range xsa.SupportedVersions {
                fmt.Printf("Checking version %v...", to)
                if to == XenVersionMaster ||
-                       xsa.RepoHasPatches(to) {
-                       fmt.Printf("already done\n", to)
+                       !xsa.NeedsBackport(to) {
+                       fmt.Printf("already done\n")
                        from = to
                        continue
                }