]> xenbits.xensource.com Git - people/gdunlap/xsatool.git/commitdiff
Add stable branch reference to TreeRecipe
authorGeorge Dunlap <george.dunlap@citrix.com>
Wed, 7 Jun 2017 16:25:46 +0000 (17:25 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Wed, 7 Jun 2017 16:25:46 +0000 (17:25 +0100)
Add XenRepo.MakeStableBranch() and XenRepo.GetRefVersion(), which will
make a "stable branch" and get the ref for the appropriate version.

Check out the 'stable' branch for each version when creating a new
repo, and take a reference.

Also update the testing infrastructure to set up the tree such that
the stable branches reflect the appropriate branches at the time.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
git.go
recipe.go
systemtest.go
xen.go
xsa.go

diff --git a/git.go b/git.go
index fa6827a5f9688d1b1c290d8dae6f20b70beb0138..32f640dda432372c8c4acbe9ed56c4e3b409b8f7 100644 (file)
--- a/git.go
+++ b/git.go
@@ -134,6 +134,13 @@ func (r Repo) ParseRef(ref string) (string, error) {
        return lines[0], nil
 }
 
+// This wants SetRefSafe, which uses the "compare exchange" provided by git
+func (r Repo) SetRef(ref string, value string) (out []byte, err error) {
+       out, err = r.gitCmd("update-ref", ref, value)
+
+       return
+}
+
 func (r Repo) DeleteBranch(branch string) (out []byte, err error) {
        out, err = r.gitCmd("branch", "-D", branch)
 
index f48e1c94940a346ce215f0b0fbcfd72140ef751f..c5d278c4498b1153ba4b7816633c547b4b92fc08 100644 (file)
--- a/recipe.go
+++ b/recipe.go
@@ -12,6 +12,7 @@ import (
 )
 
 type TreeRecipe struct {
+       StableRef string
        Prereqs []int
        Patches []string
 }
index a8a16791ff9a147e39a6f3fe398a04a54e54a110..9e23d0449be2cde7879bd3cf3b9d09ed0da30a85 100644 (file)
@@ -19,6 +19,37 @@ func (st *SystemTest) Errorf(s string, args ...interface{}) {
 // if it exists (and leave clones for future callers)?
 var FullClone = false
 
+type InitialTreeState map[Tree]*map[string]string
+
+// Reset to a known state:
+// (Want to be able to apply XSA-206 (backports) , XSA-211 (qemu), XSA-212-15 (xen)
+// ~ March 27th
+// Xen master    : ac9ff74
+// qemu-upstream : acde9f3
+// qemu-trad     : 8b4834e
+// xsa           : bff3883
+
+var its = InitialTreeState{
+       "xen":   &map[string]string{
+               "master":"ac9ff74",
+               "stable-4.8": "e0354e6",
+               "stable-4.7": "b5c7dea",
+               "stable-4.6": "bb92bb7",
+               "stable-4.5": "cde86fc",
+               "stable-4.4": "89bd1cf",
+       },
+       "qemuu":   &map[string]string{
+               "master":"acde9f3",
+       },
+       "qemut":   &map[string]string{
+               "master":"8b4834e",
+       },
+       "xsa":   &map[string]string{
+               "master":"bff3883",
+       },
+}
+
+
 // Set up the repo in a known state.
 func InitRepo(st *SystemTest) bool {
        callRepoInit := true
@@ -70,21 +101,7 @@ func InitRepo(st *SystemTest) bool {
                }
        }
 
-       // Reset to a known state:
-       // (Want to be able to apply XSA-206 (backports) , XSA-211 (qemu), XSA-212-15 (xen)
-       // ~ March 27th
-       // Xen master    : ac9ff74
-       // qemu-upstream : acde9f3
-       // qemu-trad     : 8b4834e
-       // xsa           : bff3883
-       master := map[Tree]string{
-               "xen":   "ac9ff74",
-               "qemuu": "acde9f3",
-               "qemut": "8b4834e",
-               "xsa":   "bff3883",
-       }
-
-       updateMaster := func(t Tree) (err error) {
+       updateBranches := func(t Tree) (err error) {
                var r *Repo
                if t == TreeXSA {
                        r = &G.repos.xsa
@@ -97,11 +114,29 @@ func InitRepo(st *SystemTest) bool {
                        r = &xr.Repo
                }
 
-               _, err = r.ResetBranch("master", master[t])
+               for branch := range *its[t] {
+                       shortRef := (*its[t])[branch]
+                       var fullRef string
+                       if fullRef, err = r.ParseRef(shortRef); err != nil {
+                               return err
+                       }
+                       
+                       originRef := "refs/remotes/origin/"+branch
+                       if _, err = r.SetRef(originRef, fullRef); err != nil {
+                               return
+                       }
+
+                       // Only update the local branch if it already exists
+                       if _, tErr := r.ParseRef(branch); tErr == nil {
+                               if _, err = r.ResetBranch(branch, fullRef); err != nil {
+                                       return
+                               }
+                       }
+               }
                return
        }
 
-       if err := ForEachTree(updateMaster); err != nil {
+       if err := ForEachTree(updateBranches); err != nil {
                st.Errorf("Tree update failed: %v\n", err)
                return false
        }
@@ -265,10 +300,30 @@ func Story206Init(st *SystemTest) (pass bool) {
                                        if !prs {
                                                st.Errorf("Missing expected recipe for Xen\n")
                                                pass = false
-                                       } else if len(tr.Prereqs) != 0 || len(tr.Patches) != 0 {
+                                               return nil
+                                       }
+
+                                       if len(tr.Prereqs) != 0 || len(tr.Patches) != 0 {
                                                st.Errorf("Unexpected recipe for tree Xen\n")
                                                pass = false
                                        }
+
+                                       expectedRef, prs := (*its[tree])[XenStableBranch(v)]
+                                       if !prs {
+                                               st.Errorf("Missing expected reference: v %v tree %v\n",
+                                                       v, tree)
+                                               pass = false
+                                               return nil
+                                       }
+
+                                       stableRef := tr.StableRef[0:7]
+
+                                       if stableRef != expectedRef {
+                                               st.Errorf("Unexpected StableRef: wanted %v got %v\n",
+                                                       expectedRef, stableRef)
+                                               pass = false
+                                       }
+                                       
                                } else {
                                        if prs {
                                                st.Errorf("Unexpected tree: %v\n", tree)
@@ -389,6 +444,8 @@ func Story206(st *SystemTest) bool {
                return false
        }
 
+       return true
+
        // Test only 'master' patches
        if !Story206TestMaster(st) {
                return false
diff --git a/xen.go b/xen.go
index 7735a00783329c723fb6529401b375c08b818616..05aed1e222039f8fff12252967dbc07fe235e657 100644 (file)
--- a/xen.go
+++ b/xen.go
@@ -168,6 +168,14 @@ func (xr *XenRepo) releaseTagPrefix() (s string) {
        return
 }
 
+func XenStableBranch(v XenVersion) string {
+       if v == XenVersionMaster {
+               return "master"
+       } else {
+               return "stable-" + v.String()
+       }
+}
+
 func (xr *XenRepo) GetTag(ver XenVersionFull) (tag string) {
        if ver.XenVersion() == XenVersionMaster {
                tag = "master"
@@ -177,6 +185,31 @@ func (xr *XenRepo) GetTag(ver XenVersionFull) (tag string) {
        return
 }
 
+func (xr *XenRepo) GetRefVersion(v XenVersion) (ref string, err error) {
+       ref, err = xr.ParseRef(XenStableBranch(v))
+       return
+}
+
+func (xr *XenRepo) MakeStableBranch(v XenVersion) (err error) {
+       stableBranch := XenStableBranch(v)
+       
+       branches, err := xr.Branches(stableBranch)
+       if err != nil {
+               return
+       }
+
+       if len(branches) > 0 {
+               fmt.Printf("Stable branch for version %v (%v) already exists\n",
+                       v, stableBranch)
+               return
+       }
+       
+       // This should automatically set things up correctly from origin
+       _, err = xr.Checkout(stableBranch)
+
+       return
+}
+
 func (xr *XenRepo) CheckoutVersion(ver XenVersionFull, branchName string) (err error) {
        tag := xr.GetTag(ver)
        fmt.Printf("Creating branch %s based on tag %s\n",
diff --git a/xsa.go b/xsa.go
index 36ec47746804b093a24a949648d17584f4e84f29..a08d038195bf16eba1c88281646f09817db9ed6e 100644 (file)
--- a/xsa.go
+++ b/xsa.go
@@ -75,14 +75,6 @@ func MainInit(xsa *XSAMeta, args []string) (ret int) {
                return 1
        }
 
-       // FIXME parse multiple trees
-       tree, err := TreeFromString(args[0])
-       if err != nil {
-               fmt.Printf("Getting tree: %v\n", err)
-               return 1
-       }
-       args = args[1:]
-
        sm := &G.config.Security
 
        // FIXME -- deal with multiple components
@@ -96,7 +88,17 @@ func MainInit(xsa *XSAMeta, args []string) (ret int) {
        }
 
        // Initialize a new xsa
-       xsa.Trees = []Tree{tree}
+       xsa.Trees = []Tree{}
+
+       for _, s := range args {
+               tree, err := TreeFromString(s)
+               if err != nil {
+                       fmt.Printf("Getting tree: %v\n", err)
+                       return 1
+               }
+               xsa.Trees = append(xsa.Trees, tree)
+       }
+       
        xsa.Recipes = make(map[XenVersion]*Recipe)
 
        for v := range sm.Versions {
@@ -107,7 +109,23 @@ func MainInit(xsa *XSAMeta, args []string) (ret int) {
                r := xsa.NewRecipe(vm.Latest)
 
                for _, t := range xsa.Trees {
+                       var err error
+                       
+                       xr := G.repos.XenRepos[t]
+                       
+                       if err = xr.MakeStableBranch(v); err != nil {
+                               fmt.Printf("Checking out stable branch for version %v: %v\n",
+                                       v, err)
+                               return 1
+                       }
+
                        tr := &TreeRecipe{}
+                       tr.StableRef, err = xr.GetRefVersion(v)
+
+                       if err != nil {
+                               fmt.Printf("Getting ref for stable version %v: %v\n",
+                                       v, err)
+                       }
                        tr.Prereqs = append([]int{}, vm.XSAs[t]...)
                        tr.Patches = []string{}
 
@@ -115,8 +133,7 @@ func MainInit(xsa *XSAMeta, args []string) (ret int) {
 
                }
 
-               err = r.Apply("xsa")
-               if err != nil {
+               if err := r.Apply("xsa"); err != nil {
                        fmt.Printf("Applying initial recipe for version %v\n", v)
                        return 1
                }
@@ -125,7 +142,7 @@ func MainInit(xsa *XSAMeta, args []string) (ret int) {
        // Check out "xsa/NNN/master" on all relevant trees
        branch, _ := BranchName("xsa", xsa.XSA, XenVersion("master"))
        for _, t := range xsa.Trees {
-               _, err = G.repos.XenRepos[t].Checkout(branch)
+               _, err := G.repos.XenRepos[t].Checkout(branch)
                if err != nil {
                        fmt.Printf("Checkout out branch %s\n", branch)
                        return 1
@@ -136,16 +153,14 @@ func MainInit(xsa *XSAMeta, args []string) (ret int) {
                "  Create fix and run sync-patches.\n", branch)
 
        // Save 'empty' recipe
-       err = xsa.Save()
-       if err != nil {
+       if err := xsa.Save(); err != nil {
                fmt.Printf("Saving xsa: %v\n", err)
                return 1
        }
 
        sm.AddXSA(xsa)
 
-       err = sm.Save()
-       if err != nil {
+       if err := sm.Save(); err != nil {
                fmt.Printf("Error saving global metadata: %v\n", err)
                return 1
        }