]> xenbits.xensource.com Git - people/gdunlap/xsatool.git/commitdiff
Recipe: Allow MakePatches to detect and tolerate "empty" trees
authorGeorge Dunlap <george.dunlap@citrix.com>
Wed, 17 May 2017 16:49:02 +0000 (17:49 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Wed, 17 May 2017 16:52:04 +0000 (17:52 +0100)
In order to move to a world where all supported branches are created
automatically, with prerequisites applied, as "empty" when the XSA is
created, allow Recipe.MakePatches() to detect and tolerate "empty"
versions:

- Have MakePatches() return the number of trees which contained
  patches

- Instead of verifying the reference, get the hashes for base and
  branch and compare them; simply return 0 if they are the same

- Don't bother copying patches if none are to be created.

Modify xsa.go:sync() to handle this case as well.

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

index 91e9f16012d8f6c96e0d8cbb4b07c363a15b2b19..c92ccc029c6891cf859f5e862eea8c9412a03594 100644 (file)
--- a/recipe.go
+++ b/recipe.go
@@ -66,8 +66,7 @@ func (r *Recipe) ForEachTree(f func(Tree) error) (err error) {
        return
 }
 
-func (r *Recipe) MakePatches(prefix string, sync bool) (err error) {
-       count := 0
+func (r *Recipe) MakePatches(prefix string, sync bool) (count int, err error) {
        branch, baseline := r.branchName(prefix)
 
        // rm -rf /tmp/xsa
@@ -85,16 +84,31 @@ func (r *Recipe) MakePatches(prefix string, sync bool) (err error) {
        makePatches := func(tree Tree) (err error) {
                xr := G.repos.XenRepos[tree]
 
-               if !xr.VerifyRef(branch) {
+               branchHash, err := xr.ParseRef(branch)
+               if err != nil {
+                       return err
+               }
+
+               baseHash, err := xr.ParseRef(baseline)
+               if err != nil {
+                       return err
+               }
+
+               if branchHash == "" {
                        return
                }
 
-               if !xr.VerifyRef(baseline) {
+               if baseHash == "" {
                        fmt.Printf("WARNING: Repo %s has branch %s but no branch %s, skipping\n",
                                tree, branch, baseline)
                        return
                }
 
+               if branchHash == baseHash {
+                       fmt.Printf("base and branch are identical, skipping\n")
+                       return
+               }
+
                count++
 
                path := FPPath + "/" + tree.String()
@@ -118,7 +132,6 @@ func (r *Recipe) MakePatches(prefix string, sync bool) (err error) {
        }
 
        if count == 0 {
-               err = fmt.Errorf("No patches created")
                return
        }
 
diff --git a/xsa.go b/xsa.go
index 9a7bdffdb7c09b035bb4a85fe7f3ba4b2480ca0d..3d1b48792418f8904706d7c5056bf320faf92011 100644 (file)
--- a/xsa.go
+++ b/xsa.go
@@ -20,12 +20,15 @@ func sync(xsa *XSAMeta, args []string, sync bool) (ret int) {
                        return 1
                }
 
-               if err := r.MakePatches("xsa", sync); err != nil {
+               count, err := r.MakePatches("xsa", sync)
+               if err != nil {
                        fmt.Printf("Making patches: %v\n", err)
                        return 1
                }
 
-               xsa.dirty = true
+               if count > 0 {
+                       xsa.dirty = true
+               }
        }
 
        if xsa.dirty {