Example #1
0
func (this *goPackagesFromGodeps) Update() {
	// TODO: Have a source?

	g, err := readGodeps(this.path)
	if err != nil {
		log.Fatalln("readGodeps:", err)
	}

	this.Entries = nil
	for _, dependency := range g.Deps {
		goPackage := gist7480523.GoPackageFromImportPath(dependency.ImportPath)
		if goPackage == nil {
			log.Printf("warning: Godeps dependency %q not found in your GOPATH, skipping\n", dependency.ImportPath)
			continue
		}

		// TODO: Can try to optimize by not blocking on UpdateVcs() here...
		gist7802150.MakeUpdatedLock.Unlock() // HACK: Needed because UpdateVcs() calls MakeUpdated().
		goPackage.UpdateVcs()
		gist7802150.MakeUpdatedLock.Lock() // HACK
		if goPackage.Dir.Repo == nil {
			continue
		}
		goPackage.Dir.Repo.Vcs = &fixedLocalRevVcs{LocalRev: dependency.Rev, Vcs: goPackage.Dir.Repo.Vcs}

		this.Entries = append(this.Entries, goPackage)
	}
}
Example #2
0
// RemoveRepo removes go-gettable repo with no local changes (by moving it into trash).
// importPathPattern must match exactly with the repo root.
// For example, "github.com/user/repo/...".
func RemoveRepo(importPathPattern string) error {
	// TODO: Use an official Go package for `go list` functionality whenever possible.
	importPaths := gotool.ImportPaths([]string{importPathPattern})
	if len(importPaths) == 0 {
		return errors.New("no packages to remove")
	}

	var firstGoPackage *gist7480523.GoPackage
	for i, importPath := range importPaths {
		goPackage := gist7480523.GoPackageFromImportPath(importPath)
		if goPackage == nil {
			return errors.New("Import Path not found: " + importPath)
		}

		if goPackage.Bpkg.Goroot {
			return errors.New("can't remove packages from GOROOT")
		}

		goPackage.UpdateVcs()

		if goPackage.Dir.Repo == nil {
			return errors.New("can't get repo status")
		}

		if i == 0 {
			firstGoPackage = goPackage
		} else if firstGoPackage.Dir.Repo != goPackage.Dir.Repo {
			return errors.New("matched Go Packages span more than 1 repo: " + firstGoPackage.Dir.Repo.Vcs.RootPath() + " != " + goPackage.Dir.Repo.Vcs.RootPath())
		} else if !strings.HasPrefix(goPackage.Bpkg.Dir, firstGoPackage.Dir.Repo.Vcs.RootPath()) { // TODO: This is probably not neccessary...
			return errors.New("Go Package not inside repo: " + goPackage.Bpkg.Dir + " doesn't have prefix " + firstGoPackage.Dir.Repo.Vcs.RootPath())
		}
	}

	if repoImportPathPattern := gist7480523.GetRepoImportPathPattern(firstGoPackage.Dir.Repo.Vcs.RootPath(), firstGoPackage.Bpkg.SrcRoot); repoImportPathPattern != importPathPattern {
		return errors.New("importPathPattern not exact repo root match: " + importPathPattern + " != " + repoImportPathPattern)
	}

	firstGoPackage.UpdateVcsFields()

	cleanStatus := func(goPackage *gist7480523.GoPackage) bool {
		packageStatus := presenter(goPackage)[:4]
		return packageStatus == "    " || packageStatus == "  + " // Updates are okay to ignore.
	}

	if !cleanStatus(firstGoPackage) {
		return errors.New("non-clean status: " + presenter(firstGoPackage))
	}

	err := trash.MoveTo(firstGoPackage.Dir.Repo.Vcs.RootPath())
	return err

	// TODO: Clean up /pkg folder contents, if any, etc.
}
Example #3
0
func (this *GoPackagesFromReader) Update() {
	reduceFunc := func(importPath string) interface{} {
		if goPackage := gist7480523.GoPackageFromImportPath(importPath); goPackage != nil {
			return goPackage
		}
		return nil
	}

	goPackages := gist7651991.GoReduceLinesFromReader(this.Reader, 8, reduceFunc)

	this.Entries = nil
	for {
		if goPackage, ok := <-goPackages; ok {
			this.Entries = append(this.Entries, goPackage.(*gist7480523.GoPackage))
		} else {
			break
		}
	}
}