}
func (r *Recipe) MakePatches(prefix string, sync bool) (count int, err error) {
- branch, baseline := r.branchName(prefix)
+ _, baseline, branch := r.branchName(prefix)
// rm -rf /tmp/xsa
if err = os.RemoveAll(FPPath); err != nil {
type ErrorMissingBranch string
+func IsMissingBranch(err error) (is bool) {
+ _, is = err.(ErrorMissingBranch)
+ return
+}
+
func (s ErrorMissingBranch) Error() string {
return fmt.Sprintf("Missing branch: %s", s)
}
// branch (which is aliased as a string which tells you the name of
// the missing branch); otherwise it returns whatever error it
// encountered when processing.
-func (r *Recipe) IsApplied(prefix string) (err error) {
- branch, baseline := r.branchName(prefix)
+func (r *Recipe) HasPatchBranch(prefix string) (err error) {
+ _, _, branch := r.branchName(prefix)
check := func(tree Tree) (err error) {
- tr, prs := r.Recipes[tree]
- if !prs || !tr.HasPatches() {
+ _, prs := r.Recipes[tree]
+ if !prs {
return
}
if !xr.VerifyRef(branch) {
return ErrorMissingBranch(branch)
}
- if !xr.VerifyRef(baseline) {
- return ErrorMissingBranch(baseline)
- }
-
- // FIXME: Actually check to see if something is applied
return
}
return
}
-func BranchName(prefix string, xsa int, v XenVersion) (branch, baseline string) {
+func BranchName(prefix string, xsa int, v XenVersion) (stable, baseline, branch string) {
// Construct branchname
branch = prefix + "/" + strconv.Itoa(xsa) + "/" + v.String()
+ stable = branch + "-stable"
baseline = branch + "-baseline"
return
}
-func (r *Recipe) branchName(prefix string) (branch, baseline string) {
- branch, baseline = BranchName(prefix, r.xsa, r.XenVersion)
+func (r *Recipe) branchName(prefix string) (stable, baseline, branch string) {
+ stable, baseline, branch = BranchName(prefix, r.xsa, r.XenVersion)
- fmt.Printf("Branchnames: %s %s\n", branch, baseline)
+ fmt.Printf("Branchnames: %s %s %s\n", stable, baseline, branch)
return
}
// Naming convention:
//
// XSA patches:
-// xsa/NNN/VV.v-baseline
-// xsa/NNN/VV.v
+// xsa/NNN/VV-stable
+// xsa/NNN/VV-baseline
+// xsa/NNN/VV
//
// Testing:
// test/NN/MM.m
-// Create branches and apply whatever patches exist.
-func (r *Recipe) apply(xr *XenRepo, tr *TreeRecipe, prefix string) (err error) {
- branch, baseline := r.branchName(prefix)
+// Create a "patch series" branch and apply it
+func (r *Recipe) ApplyPatches(prefix string) (err error) {
+ apply := func(tree Tree) (err error) {
+ tr, prs := r.Recipes[tree]
- // FIXME change this to tr.StableRef
- // Make "baseline" branch, based on XenVersion, with Prereq patches
- err = xr.MakeBranch(baseline, tr.StableRef)
- if err != nil {
- return fmt.Errorf("Making baseline %s for xenversion %v: %v\n",
- baseline, r.XenVersion)
- }
+ if !prs {
+ err = fmt.Errorf("Internal data error: no recipe for tree %s\n", tree)
+ return
+ }
- for _, xsanum := range tr.Prereqs {
- err = fmt.Errorf("%d: Don't know how to apply XSA prerequisites yet!", xsanum)
- return
- }
+ xr := G.repos.XenRepos[tree]
- // Make xsa branch based on "baseline" branch
- err = xr.MakeBranch(branch, baseline)
- if err != nil {
- return fmt.Errorf("Making tempbranch %s for xenversion %v: %v\n",
- branch, r.XenVersion)
- }
+ _, baseline, branch := r.branchName(prefix)
- for _, glob := range tr.Patches {
- // git am
- _, err = xr.AmClean(G.config.Tool.GetPath(TreeXSA) + "/" + glob)
+ // Make xsa branch based on "baseline" branch
+ err = xr.MakeBranch(branch, baseline)
if err != nil {
- return fmt.Errorf("Appling am %s: %v\n", glob, err)
+ return fmt.Errorf("Making tempbranch %s for xenversion %v: %v\n",
+ branch, r.XenVersion)
}
+
+ for _, glob := range tr.Patches {
+ // git am
+ _, err = xr.AmClean(G.config.Tool.GetPath(TreeXSA) + "/" + glob)
+ if err != nil {
+ return fmt.Errorf("Appling am %s: %v\n", glob, err)
+ }
+ }
+ return
}
+
+ err = r.ForEachTree(apply)
+
return
}
-func (r *Recipe) Apply(prefix string) (err error) {
+func (r *Recipe) ApplyBaselines(prefix string) (err error) {
apply := func(tree Tree) (err error) {
tr, prs := r.Recipes[tree]
xr := G.repos.XenRepos[tree]
- err = r.apply(xr, tr, prefix)
+ stable, baseline, _ := r.branchName(prefix)
+
+ // Create xsa/NNN/VV-stable based on tr.StableRef
+ if err = xr.MakeBranch(stable, tr.StableRef); err != nil {
+ return fmt.Errorf("Making stable baseline %s for xenversion %v: %v\n",
+ stable, r.XenVersion, err)
+ }
+
+ // Create xsa/NNN/VV-baseline based on -stable
+ if err = xr.MakeBranch(baseline, stable); err != nil {
+ return fmt.Errorf("Making patch baseline %s for xenversion %v: %v\n",
+ baseline, r.XenVersion, err)
+ }
+
+ // FIXME Apply previous patches
+ for _, xsanum := range tr.Prereqs {
+ err = fmt.Errorf("%d: Don't know how to apply XSA prerequisites yet!", xsanum)
+ return
+ }
+
return
}
err = r.ForEachTree(apply)
+
+ return
+}
+
+func (r *Recipe) ApplyAll(prefix string) (err error) {
+ if err = r.ApplyBaselines(prefix); err != nil {
+ return
+ }
+
+ err = r.ApplyPatches(prefix)
return
}
}
func (r *Recipe) Build(prefix string) (err error) {
- branch, _ := r.branchName(prefix)
+ _, _, branch := r.branchName(prefix)
xenrepo := G.repos.XenRepos[TreeXen]
)
func sync(xsa *XSAMeta, args []string, sync bool) (ret int) {
- vers := VersionsFromArgs(xsa, args)
+ vers := VersionsFromArgs(xsa, args, true)
if !sync && len(vers) > 1 {
fmt.Printf("Error: Doesn't make sense to make more than one version\n")
return 1
}
+ // Check to see if there's a branch. If not, throw an error.
+ if err := r.HasPatchBranch("xsa"); err != nil {
+ if IsMissingBranch(err) {
+ fmt.Printf("Error: No patch branch for version %v (missing branch %s)\n",
+ v, string(err.(ErrorMissingBranch)))
+ return 1
+ }
+ fmt.Printf("Error checking for patch branch: %v\n", err)
+ return 1
+ }
+
count, err := r.MakePatches("xsa", sync)
if err != nil {
fmt.Printf("Making patches: %v\n", err)
}
func MainSyncBranch(xsa *XSAMeta, args []string) (ret int) {
- vers := VersionsFromArgs(xsa, args)
+ vers := VersionsFromArgs(xsa, args, false)
for _, v := range vers {
prefix := "xsa"
return 1
}
- err := r.Apply(prefix)
+ err := r.ApplyAll(prefix)
if err != nil {
fmt.Printf("Applying recipe: %v\n", err)
fmt.Printf("FAILED: %v\n", r.XenVersion)
}
- if err := r.Apply("xsa"); err != nil {
- fmt.Printf("Applying initial recipe for version %v\n", v)
+ if err := r.ApplyBaselines("xsa"); err != nil {
+ fmt.Printf("Making recipe baseline for version %v\n", v)
return 1
}
+
+ if v == XenVersionMaster {
+ if err := r.ApplyPatches("xsa"); err != nil {
+ fmt.Printf("Applying recipe patches for version %v\n", v)
+ return 1
+ }
+ }
}
// Check out "xsa/NNN/master" on all relevant trees
- branch, _ := BranchName("xsa", xsa.XSA, XenVersion("master"))
+ _, _, branch := BranchName("xsa", xsa.XSA, XenVersion("master"))
for _, t := range xsa.Trees {
_, err := G.repos.XenRepos[t].Checkout(branch)
if err != nil {