Exemple #1
0
func main() {

	fmt.Println(`
  Assumes the following:
  - $GOPATH is set to a single directory (not the godepsified path)
  - "godeps save ./..." has not yet been run on origin
  - The desired level of kubernetes is checked out
`)
	var self, other string
	flag.StringVar(&self, "self", filepath.Join(gopath, "src/github.com/openshift/origin/Godeps/Godeps.json"), "The first file to compare")
	flag.StringVar(&other, "other", filepath.Join(gopath, "src/k8s.io/kubernetes/Godeps/Godeps.json"), "The other file to compare")
	flag.Parse()

	// List packages imported by origin Godeps
	originGodeps, err := loadGodeps(self)
	if err != nil {
		exit(fmt.Sprintf("Error loading %s:", self), err)
	}

	// List packages imported by kubernetes Godeps
	k8sGodeps, err := loadGodeps(other)
	if err != nil {
		exit(fmt.Sprintf("Error loading %s:", other), err)
	}

	// List packages imported by origin
	_, errs := loadImports(".")
	if len(errs) > 0 {
		exit("Error loading imports:", errs...)
	}

	mine := []string{}
	yours := []string{}
	ours := []string{}
	for k := range originGodeps {
		if _, exists := k8sGodeps[k]; exists {
			ours = append(ours, k)
		} else {
			mine = append(mine, k)
		}
	}
	for k := range k8sGodeps {
		if _, exists := originGodeps[k]; !exists {
			yours = append(yours, k)
		}
	}

	sort.Strings(mine)
	sort.Strings(yours)
	sort.Strings(ours)

	// Check for missing k8s deps
	if len(yours) > 0 {
		fmt.Println("k8s-only godep imports (may need adding to origin):")
		for _, k := range yours {
			fmt.Println(k)
		}
		fmt.Printf("\n\n\n")
	}

	// Check `mine` for unused local deps (might be used transitively by other Godeps)

	// Check `ours` for different levels
	for _, k := range ours {
		if oRev, kRev := originGodeps[k].Rev, k8sGodeps[k].Rev; oRev != kRev {
			fmt.Printf("Mismatch on %s:\n", k)
			if older, err := util.IsAncestor(oRev, kRev, filepath.Join(gopath, "src", k)); older && err == nil {
				fmt.Printf("    Origin: %s (older)\n", oRev)
				fmt.Printf("    K8s:    %s (newer)\n", kRev)
			} else if newer, err := util.IsAncestor(kRev, oRev, filepath.Join(gopath, "src", k)); newer && err == nil {
				fmt.Printf("    Origin: %s (newer)\n", oRev)
				fmt.Printf("    K8s:    %s (older)\n", kRev)
			} else {
				fmt.Printf("    Origin: %s (unknown)\n", oRev)
				fmt.Printf("    K8s:    %s (unknown)\n", kRev)
				fmt.Printf("    %s\n", err)
			}
		}
	}
}
Exemple #2
0
func main() {

	fmt.Println(`
  Assumes the following:
  - $GOPATH is set to a single directory (not the godepsified path)
  - "godeps save ./..." has not yet been run on origin
  - The desired level of kubernetes is checked out
`)
	var self, other string
	var checkoutNewer bool
	flag.StringVar(&self, "self", filepath.Join(gopath, "src/github.com/openshift/origin/Godeps/Godeps.json"), "The first file to compare")
	flag.StringVar(&other, "other", filepath.Join(gopath, "src/k8s.io/kubernetes/Godeps/Godeps.json"), "The other file to compare")
	flag.BoolVar(&checkoutNewer, "checkout", checkoutNewer, "Check out the newer commit when there is a mismatch between the Godeps")
	flag.Parse()

	// List packages imported by origin Godeps
	originGodeps, err := loadGodeps(self)
	if err != nil {
		exit(fmt.Sprintf("Error loading %s:", self), err)
	}

	// List packages imported by kubernetes Godeps
	k8sGodeps, err := loadGodeps(other)
	if err != nil {
		exit(fmt.Sprintf("Error loading %s:", other), err)
	}

	// List packages imported by origin
	_, errs := loadImports(".")
	if len(errs) > 0 {
		exit("Error loading imports:", errs...)
	}

	mine := []string{}
	yours := []string{}
	ours := []string{}
	for k := range originGodeps {
		if _, exists := k8sGodeps[k]; exists {
			ours = append(ours, k)
		} else {
			mine = append(mine, k)
		}
	}
	for k := range k8sGodeps {
		if _, exists := originGodeps[k]; !exists {
			yours = append(yours, k)
		}
	}

	sort.Strings(mine)
	sort.Strings(yours)
	sort.Strings(ours)

	// Check for missing k8s deps
	if len(yours) > 0 {
		fmt.Println("k8s-only godep imports (may need adding to origin):")
		for _, k := range yours {
			fmt.Println(k)
		}
		fmt.Printf("\n\n\n")
	}

	// Check `mine` for unused local deps (might be used transitively by other Godeps)

	// Check `ours` for different levels
	for _, k := range ours {
		if oRev, kRev := originGodeps[k].Rev, k8sGodeps[k].Rev; oRev != kRev {
			fmt.Printf("Mismatch on %s:\n", k)
			newerCommit := ""
			repoPath := filepath.Join(gopath, "src", k)

			oDecorator := ""
			kDecorator := ""
			currentRev, err := util.CurrentRev(repoPath)
			if err == nil {
				if currentRev == oRev {
					kDecorator = " "
					oDecorator = "*"
				}
				if currentRev == kRev {
					kDecorator = "*"
					oDecorator = " "
				}
			}

			oDate, oDateErr := util.CommitDate(oRev, repoPath)
			if oDateErr != nil {
				oDate = "unknown"
			}
			kDate, kDateErr := util.CommitDate(kRev, repoPath)
			if kDateErr != nil {
				kDate = "unknown"
			}

			if older, err := util.IsAncestor(oRev, kRev, repoPath); older && err == nil {
				fmt.Printf("    Origin: %s%s (%s)\n", oDecorator, oRev, oDate)
				fmt.Printf("    K8s:    %s%s (%s, fast-forward)\n", kDecorator, kRev, kDate)
				newerCommit = kRev
			} else if newer, err := util.IsAncestor(kRev, oRev, repoPath); newer && err == nil {
				fmt.Printf("    Origin: %s%s (%s, fast-forward)\n", oDecorator, oRev, oDate)
				fmt.Printf("    K8s:    %s%s (%s)\n", kDecorator, kRev, kDate)
				newerCommit = oRev
			} else if oDateErr == nil && kDateErr == nil {
				fmt.Printf("    Origin: %s%s (%s, discontinuous)\n", oDecorator, oRev, oDate)
				fmt.Printf("    K8s:    %s%s (%s, discontinuous)\n", kDecorator, kRev, kDate)
				if oDate > kDate {
					newerCommit = oRev
				} else {
					newerCommit = kRev
				}
			} else {
				fmt.Printf("    Origin: %s%s (%s)\n", oDecorator, oRev, oDate)
				fmt.Printf("    K8s:    %s%s (%s)\n", kDecorator, kRev, kDate)
				if oDateErr != nil {
					fmt.Printf("    %s\n", oDateErr)
				}
				if kDateErr != nil {
					fmt.Printf("    %s\n", kDateErr)
				}
			}

			if len(newerCommit) > 0 && newerCommit != currentRev {
				if checkoutNewer {
					fmt.Printf("    Checking out:\n")
					fmt.Printf("    cd %s && git checkout %s\n", repoPath, newerCommit)
					if err := util.Checkout(newerCommit, repoPath); err != nil {
						fmt.Printf("    %s\n", err)
					}
				} else {
					fmt.Printf("    To check out newest:\n")
					fmt.Printf("    cd %s && git checkout %s\n", repoPath, newerCommit)
				}
			}
		}
	}
}