]> xenbits.xensource.com Git - people/gdunlap/xsatool/commitdiff
Implement backport
authorGeorge Dunlap <george.dunlap@citrix.com>
Wed, 14 Jun 2017 10:06:12 +0000 (11:06 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Fri, 16 Jun 2017 13:29:03 +0000 (14:29 +0100)
Implement Repo.Rebase() (with full head / base / onto)

Use this to implement Recipe.Backport()

Finally, implement xsatool [nnn] backport:
 - Look for the latest xenversion that doens't have a "patch" branch
 - Rebase next version from that onto it with 'git rebase'.

Always only do one, so that the caller has a chance to test the build
and look it over before continuing the backport process.

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

diff --git a/git.go b/git.go
index 32f640dda432372c8c4acbe9ed56c4e3b409b8f7..ba214a07986644cde3cfc811655a37b79b595ac1 100644 (file)
--- a/git.go
+++ b/git.go
@@ -261,6 +261,11 @@ func (r Repo) AmClean(amglob string) (out []byte, err error) {
        return
 }
 
+func (r Repo) Rebase(head string, base string, onto string) (out []byte, err error) {
+       out, err = r.gitCmd("rebase", "--onto="+onto, base, head)
+       return
+}
+
 func (r Repo) DisablePush() (err error) {
        node := "config.origin.pushurl"
        _, err = r.gitCmd("config", node, "http://localhost/fail")
diff --git a/main.go b/main.go
index bb116b76790612bcb7b2d633c33371ecd33b6707..2e204a384e6e644dbc976e70ffe1c79b48dbc104 100644 (file)
--- a/main.go
+++ b/main.go
@@ -107,11 +107,14 @@ func XsaMain(args []string) int {
                        main = MainSyncPatches
                        loadConfig = true
                        loadXSA = true
+               case "backport":
+                       main = MainBackport
+                       loadConfig = true
+                       loadXSA = true
                case "sync-branch":
                        main = MainSyncBranch
                        loadConfig = true
                        loadXSA = true
-
                case "test-apply":
                        main = MainTestApply
                        loadConfig = true
index 59be8fd8175e3e0bddf188e1404991d371dae175..5e615ac2dfd75e5673aa294b62dffaabaa760985 100644 (file)
--- a/recipe.go
+++ b/recipe.go
@@ -452,6 +452,35 @@ func (r *Recipe) GetTreeRecipe(tree Tree) (tr *TreeRecipe, err error) {
        return
 }
 
+func (r *Recipe) Backport(prefix string, to XenVersion) (err error) {
+
+       _, fromBase, fromBranch := BranchName(prefix, r.xsa, r.XenVersion)
+       _, toBase, toBranch := BranchName(prefix, r.xsa, to)
+       
+       backport := func(tree Tree) (err error) {
+               xr := G.repos.XenRepos[tree]
+
+               
+               // git checkout -b xsa/NNN/$to xsa/NNN/$from
+               if err = xr.MakeBranch(toBranch, fromBranch); err != nil {
+                       return fmt.Errorf("Making branch %v based on branch %v\n",
+                               toBranch, fromBranch)
+               }
+
+               // git rebase --onto=xsa/NNN/$to-baseline $from-baseline $to-baseline
+               if _, err = xr.Rebase(toBranch, fromBase, toBase); err != nil {
+                       return fmt.Errorf("Rebase failed.  Finish rebase for %v and continue.", to)
+               }
+               
+               return
+       }
+
+       err = r.ForEachTree(backport)
+       return
+}
+
+
+
 func (r *Recipe) Build(prefix string) (err error) {
        _, _, branch := r.branchName(prefix)
 
index ef6c26568afb2692e7385cad7cd038c1a9fd89dc..ac0b686f8ef74a78adaf2d930f7f9f7f53d86c6e 100644 (file)
@@ -437,6 +437,25 @@ func Story206TestMaster(st *SystemTest) bool {
        return true
 }
 
+func Story206Backport(st *SystemTest) bool {
+       fmt.Print(" xsatool 206 backport [master to 4.8] [should fail]\n")
+       if MainHarness("206", "backport") == 0 {
+               st.Errorf("Expected master->4.8 backport to fail, but succeeded!")
+               return false
+       }
+
+       // Check to see that the partial bits we expect were actually done
+       // - .git/rebase-apply exists
+       // - How many patches had been applied?  (0)
+
+       // Fake things up:
+       // - git rebase --abort
+       // - git checkout -B xsa/NNN/4.8 xsa/NNN/4.8-baseline
+       // - git am 4.8 patch series
+
+       return true
+}
+
 func Story206(st *SystemTest) bool {
        fmt.Print("Starting XSA-206 'story'\n")
        // xsatool 206 init xen
@@ -454,14 +473,15 @@ func Story206(st *SystemTest) bool {
                return false
        }
 
-       return true
-
        // Test only 'master' patches
-       if !Story206TestMaster(st) {
+       if false && !Story206TestMaster(st) {
                return false
        }
        
        // 206 Backport (should fail at 4.8. 4.7, and 4.6; NOT 4.5)
+       if !Story206Backport(st) {
+               return false
+       }
 
        // 206 sync-patches
 
diff --git a/xsa.go b/xsa.go
index 5ea8b5e27d052e6a298a189e1e4b9b13d3bf6e7b..c97941b09d3af20e2f7c9356aab4a7269630c7cf 100644 (file)
--- a/xsa.go
+++ b/xsa.go
@@ -2,6 +2,7 @@ package main
 
 import (
        "fmt"
+       "sort"
 )
 
 func sync(xsa *XSAMeta, args []string, sync bool) (ret int) {
@@ -184,3 +185,44 @@ func MainInit(xsa *XSAMeta, args []string) (ret int) {
 
        return
 }
+
+// xsatool NNN backport
+func MainBackport(xsa *XSAMeta, args []string) (ret int) {
+       // Starting with master - 1, look for branches that don't have patches
+
+       if !sort.IsSorted(xsa.SupportedVersions) {
+               fmt.Print("Internal error: SupportedVersions not sorted!\n")
+               return 1
+       }
+
+       var from XenVersion
+       for _, to := range xsa.SupportedVersions {
+               if to == XenVersionMaster ||
+                       xsa.RepoHasPatches(to) {
+                       from = to
+                       continue
+               }
+
+               fmt.Printf("Backporting from %v to %v\n", from, to)
+
+               r := xsa.GetRecipe(from)
+
+               if err := r.Backport("xsa", to); err != nil {
+                       fmt.Printf("Backporting from %v to %v: %v\n",
+                               from, to, err)
+                       return 1
+               }
+
+               fmt.Printf("Successfully rebased from %v to %v.  Please check it over.\n",
+                       from, to)
+               return 0
+
+               // For if we ever add an "automatic build test option" instead
+               // from = to
+       }
+       
+       fmt.Printf("Not implemented\n")
+       return 1
+}
+
+// xsatool NNN backport-fixup [version]