Commit ceae2c93 authored by Andrew Gerrand's avatar Andrew Gerrand

goinstall: undo repo peeking code

Keeping the Julian's good refactoring work.

R=rsc
CC=golang-dev
https://golang.org/cl/4638049
parent 6be0bdf7
......@@ -41,17 +41,9 @@ Another common idiom is to use
to update, recompile, and reinstall all goinstalled packages.
The source code for a package with import path foo/bar is expected
to be in the directory $GOPATH/src/foo/bar/ or $GOROOT/src/pkg/foo/bar/.
(See the discussion of GOPATH below for more detail.)
If the package source is not found locally and the import path begins
with a domain name, goinstall attempts to detect a remote source repository
(Bazaar, Git, Mercurial, or Subversion). If a supported repository is found,
goinstall uses the appropriate tool to download the source code.
If the import path refers to a known code hosting site, goinstall skips the
repository detection and downloads the code directly.
The recognized code hosting sites are:
to be in the directory $GOROOT/src/pkg/foo/bar/. If the import
path refers to a code hosting site, goinstall will download the code
if necessary. The recognized code hosting sites are:
BitBucket (Mercurial)
......
......@@ -7,14 +7,11 @@
package main
import (
"exec"
"http"
"os"
"path"
"path/filepath"
"regexp"
"strings"
"sync"
)
const dashboardURL = "http://godashboard.appspot.com/package"
......@@ -57,11 +54,7 @@ type vcs struct {
check string
protocols []string
suffix string
tryPrefixes bool
defaultHosts []host
// Is this tool present? (set by findTools)
available bool
}
type vcsMatch struct {
......@@ -83,7 +76,6 @@ var hg = vcs{
logReleaseFlag: "-rrelease",
check: "identify",
protocols: []string{"http"},
tryPrefixes: true,
defaultHosts: []host{
{regexp.MustCompile(`^([a-z0-9\-]+\.googlecode\.com/hg)(/[a-z0-9A-Z_.\-/]*)?$`), "https"},
{regexp.MustCompile(`^(bitbucket\.org/[a-z0-9A-Z_.\-]+/[a-z0-9A-Z_.\-]+)(/[a-z0-9A-Z_.\-/]*)?$`), "http"},
......@@ -105,7 +97,6 @@ var git = vcs{
check: "peek-remote",
protocols: []string{"git", "http"},
suffix: ".git",
tryPrefixes: true,
defaultHosts: []host{
{regexp.MustCompile(`^(github\.com/[a-z0-9A-Z_.\-]+/[a-z0-9A-Z_.\-]+)(/[a-z0-9A-Z_.\-/]*)?$`), "http"},
},
......@@ -124,7 +115,6 @@ var svn = vcs{
logReleaseFlag: "release",
check: "info",
protocols: []string{"http", "svn"},
tryPrefixes: false,
defaultHosts: []host{
{regexp.MustCompile(`^([a-z0-9\-]+\.googlecode\.com/svn)(/[a-z0-9A-Z_.\-/]*)?$`), "https"},
},
......@@ -145,7 +135,6 @@ var bzr = vcs{
logReleaseFlag: "-rrelease",
check: "info",
protocols: []string{"http", "bzr"},
tryPrefixes: true,
defaultHosts: []host{
{regexp.MustCompile(`^(launchpad\.net/([a-z0-9A-Z_.\-]+(/[a-z0-9A-Z_.\-]+)?|~[a-z0-9A-Z_.\-]+/(\+junk|[a-z0-9A-Z_.\-]+)/[a-z0-9A-Z_.\-]+))(/[a-z0-9A-Z_.\-/]+)?$`), "https"},
},
......@@ -153,84 +142,6 @@ var bzr = vcs{
var vcsList = []*vcs{&git, &hg, &bzr, &svn}
func potentialPrefixes(pkg string) (prefixes []string) {
parts := strings.Split(pkg, "/", -1)
elem := parts[0]
for _, part := range parts[1:] {
elem = path.Join(elem, part)
prefixes = append(prefixes, elem)
}
return
}
func tryCommand(c chan *vcsMatch, v *vcs, prefixes []string) {
// try empty suffix and v.suffix if non-empty
suffixes := []string{""}
if v.suffix != "" {
suffixes = append(suffixes, v.suffix)
}
for _, proto := range v.protocols {
for _, prefix := range prefixes {
for _, suffix := range suffixes {
repo := proto + "://" + prefix + suffix
printf("try: %s %s %s\n", v.cmd, v.check, repo)
if exec.Command(v.cmd, v.check, repo).Run() == nil {
c <- &vcsMatch{v, prefix, repo}
return
}
}
}
}
c <- nil
}
var findToolsOnce sync.Once
func findTools() {
for _, v := range vcsList {
v.available = exec.Command(v.cmd, "help").Run() == nil
}
}
var logMissingToolsOnce sync.Once
func logMissingTools() {
for _, v := range vcsList {
if !v.available {
logf("%s not found; %s packages will be ignored\n", v.cmd, v.name)
}
}
}
func findVcs(pkg string) *vcsMatch {
findToolsOnce.Do(findTools)
// we don't know how much of the name constitutes the repository prefix
// so build a list of possibilities
prefixes := potentialPrefixes(pkg)
c := make(chan *vcsMatch, len(vcsList))
for _, v := range vcsList {
if !v.available {
c <- nil
continue
}
if v.tryPrefixes {
go tryCommand(c, v, prefixes)
} else {
go tryCommand(c, v, []string{pkg})
}
}
for _ = range vcsList {
if m := <-c; m != nil {
return m
}
}
logMissingToolsOnce.Do(logMissingTools)
return nil
}
// isRemote returns true if the first part of the package name looks like a
// hostname - i.e. contains at least one '.' and the last part is at least 2
// characters.
......@@ -263,9 +174,6 @@ func download(pkg, srcDir string) os.Error {
}
}
}
if m == nil {
m = findVcs(pkg)
}
if m == nil {
return os.ErrorString("cannot download: " + pkg)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment