Path string
}
+
+
func GitOpen(gpath string) (r Repo, err error) {
- if ! path.IsAbs(gpath) {
+ if !path.IsAbs(gpath) {
cwd, err := os.Getwd()
if err != nil {
+ fmt.Printf("Getwd failed?\n")
return r, err
}
- gpath = cwd+"/"+gpath
+ gpath = cwd + "/" + gpath
gpath = path.Clean(gpath)
}
+ fmt.Printf("Path: %s\n", gpath)
r.Path = gpath
- if ! r.Check() {
+ if !r.Check() {
err = fmt.Errorf("Status failed!")
}
return
}
func (r Repo) gitCmd(args ...string) (out []byte, err error) {
- out, err = exec.Command("git", append([]string{"-C", r.Path}, args...)...).Output()
+ x := append([]string{"-C", r.Path}, args...)
+ fmt.Println(x)
+ out, err = exec.Command("git", x...).CombinedOutput()
+ fmt.Println(string(out))
return
}
return err == nil
}
+
+func (r Repo) Fetch() (out []byte, err error) {
+ out, err = r.gitCmd("fetch")
+
+ fmt.Printf("%s", string(out))
+
+ return
+}
+
+func (r Repo) Checkout(ref string, branch string) (err error) {
+ _, err = r.gitCmd("checkout", "-B", branch, ref)
+
+ return
+}
import (
"fmt"
+ "os"
)
func main() {
-
- xenRepo, err := GitOpen("../xen.git")
+
+ err := InitRepos()
if err != nil {
- fmt.Printf("Unexpected: %v\n", err)
+ fmt.Printf("Error initializing repos: %v\n", err)
+ os.Exit(1)
+ }
+
+ for i := XenVersion44; i <= XenVersionMaster; i++ {
+ fmt.Printf("%d: %v\n", int(i), i)
}
- fmt.Printf("%v\n", xenRepo.Check())
- fakeRepo, err := GitOpen("blah.git")
- if err == nil {
- fmt.Printf("Unexpected success!\n")
+ meta := Metadata{
+ XSA: 209,
+ SupportedVersions: []XenVersion{XenVersion48},
+ Recipes: []Recipe{
+ Recipe{
+ XenVersionFull: XenVersionFull{XenVersion48,0},
+ QemuUpstreamPatches: "xsa209-qemuu/*.patch",
+ },
+ },
}
- fmt.Printf("%v\n", fakeRepo.Check())
-
+ meta.Normalize()
+
+ err = meta.Recipes[0].Apply()
+ if err != nil {
+ fmt.Printf("Applying recipe: %v\n", err)
+ }
+ defer meta.Recipes[0].Cleanup()
}
--- /dev/null
+package main
+
+import (
+ // "encoding/json"
+)
+
+type Metadata struct {
+ XSA int
+ SupportedVersions []XenVersion
+ Recipes []Recipe
+}
+
+func (m *Metadata) Normalize() {
+ for i := range m.Recipes {
+ m.Recipes[i].xsa = m.XSA
+ }
+}
--- /dev/null
+package main
+
+import (
+ "fmt"
+ "strconv"
+)
+
+type XenVersion int
+
+const (
+ XenVersion44 XenVersion = iota
+ XenVersion45
+ XenVersion46
+ XenVersion47
+ XenVersion48
+ XenVersionMaster
+)
+
+func (v XenVersion) String() (s string) {
+ if v == XenVersionMaster {
+ return "master"
+ }
+
+ s = "4."
+ s += strconv.Itoa(int(v - XenVersion44 + 4))
+
+ return
+}
+
+type XenVersionFull struct {
+ XenVersion
+ Point int
+}
+
+func (v XenVersionFull) String() (s string) {
+ if v.XenVersion == XenVersionMaster {
+ return "master"
+ }
+
+ s += v.XenVersion.String() + "." + strconv.Itoa(v.Point)
+
+ return
+}
+
+
+type Recipe struct {
+ XenVersionFull
+ XenPatches string
+ QemuUpstreamPatches string
+ QemuTraditionalPatches string
+ RequiredXSAs []int
+ tempBranch string // Not serialized
+ xsa int
+}
+
+func (r *Recipe) Apply() (err error) {
+ // Construct branchname
+ r.tempBranch = "test/" + strconv.Itoa(r.xsa) + "/" + r.XenVersion.String()
+ fmt.Printf("Test tag: %s\n", r.tempBranch)
+
+ if r.QemuUpstreamPatches != "" {
+ // Checkout appropriate version
+ err = qemuu.CheckoutVersion(r.XenVersionFull, r.tempBranch)
+ if err != nil {
+ return
+ }
+ // Apply prerequisite XSAs
+ // git am
+ }
+ return
+}
+
+func (r *Recipe) Cleanup() (err error) {
+ return
+
+}
--- /dev/null
+package main
+
+import (
+ "fmt"
+)
+
+type XRType int
+
+const (
+ XRXen XRType = iota
+ XRQemuu
+ XRQemut
+)
+
+type XenRepo struct {
+ Repo
+ XRType
+}
+
+var xen, qemuu, qemut XenRepo
+
+func XenRepoOpen(path string, t XRType) (xr XenRepo, err error) {
+ fmt.Printf("Opening %s\n", path)
+ xr.Repo, err = GitOpen(path)
+ if err != nil {
+ return
+ }
+ fmt.Printf("Fetching\n")
+ out, err := xr.Fetch()
+ if err != nil {
+ return
+ }
+ xr.XRType = t
+ fmt.Print(string(out))
+
+ return
+}
+
+func InitRepos() (err error) {
+ xen, err = XenRepoOpen("../xen.git", XRXen)
+ if err != nil {
+ return
+ }
+
+ qemuu, err = XenRepoOpen("../qemu-xen.git", XRQemuu)
+ if err != nil {
+ return
+ }
+
+ qemut, err = XenRepoOpen("../qemu-xen-traditional.git", XRQemut)
+ if err != nil {
+ return
+ }
+
+ return
+}
+
+func (xr *XenRepo) releaseTagPrefix() (s string) {
+ switch xr.XRType {
+ case XRXen:
+ return "RELEASE-"
+ case XRQemuu:
+ return "qemu-xen-"
+ case XRQemut:
+ return "xen-"
+ }
+
+ return
+}
+
+func (xr *XenRepo) CheckoutVersion(ver XenVersionFull, branchName string) (err error) {
+ tag := xr.releaseTagPrefix()+ver.String()
+ fmt.Printf("Creating branch %s based on tag %s\n",
+ branchName, tag)
+ err = xr.Checkout(tag, branchName)
+ return
+}