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 ...@@ -41,17 +41,9 @@ Another common idiom is to use
to update, recompile, and reinstall all goinstalled packages. to update, recompile, and reinstall all goinstalled packages.
The source code for a package with import path foo/bar is expected 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/. to be in the directory $GOROOT/src/pkg/foo/bar/. If the import
(See the discussion of GOPATH below for more detail.) path refers to a code hosting site, goinstall will download the code
if necessary. The recognized code hosting sites are:
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:
BitBucket (Mercurial) BitBucket (Mercurial)
......
...@@ -7,14 +7,11 @@ ...@@ -7,14 +7,11 @@
package main package main
import ( import (
"exec"
"http" "http"
"os" "os"
"path"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strings" "strings"
"sync"
) )
const dashboardURL = "http://godashboard.appspot.com/package" const dashboardURL = "http://godashboard.appspot.com/package"
...@@ -57,11 +54,7 @@ type vcs struct { ...@@ -57,11 +54,7 @@ type vcs struct {
check string check string
protocols []string protocols []string
suffix string suffix string
tryPrefixes bool
defaultHosts []host defaultHosts []host
// Is this tool present? (set by findTools)
available bool
} }
type vcsMatch struct { type vcsMatch struct {
...@@ -83,7 +76,6 @@ var hg = vcs{ ...@@ -83,7 +76,6 @@ var hg = vcs{
logReleaseFlag: "-rrelease", logReleaseFlag: "-rrelease",
check: "identify", check: "identify",
protocols: []string{"http"}, protocols: []string{"http"},
tryPrefixes: true,
defaultHosts: []host{ defaultHosts: []host{
{regexp.MustCompile(`^([a-z0-9\-]+\.googlecode\.com/hg)(/[a-z0-9A-Z_.\-/]*)?$`), "https"}, {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"}, {regexp.MustCompile(`^(bitbucket\.org/[a-z0-9A-Z_.\-]+/[a-z0-9A-Z_.\-]+)(/[a-z0-9A-Z_.\-/]*)?$`), "http"},
...@@ -105,7 +97,6 @@ var git = vcs{ ...@@ -105,7 +97,6 @@ var git = vcs{
check: "peek-remote", check: "peek-remote",
protocols: []string{"git", "http"}, protocols: []string{"git", "http"},
suffix: ".git", suffix: ".git",
tryPrefixes: true,
defaultHosts: []host{ defaultHosts: []host{
{regexp.MustCompile(`^(github\.com/[a-z0-9A-Z_.\-]+/[a-z0-9A-Z_.\-]+)(/[a-z0-9A-Z_.\-/]*)?$`), "http"}, {regexp.MustCompile(`^(github\.com/[a-z0-9A-Z_.\-]+/[a-z0-9A-Z_.\-]+)(/[a-z0-9A-Z_.\-/]*)?$`), "http"},
}, },
...@@ -124,7 +115,6 @@ var svn = vcs{ ...@@ -124,7 +115,6 @@ var svn = vcs{
logReleaseFlag: "release", logReleaseFlag: "release",
check: "info", check: "info",
protocols: []string{"http", "svn"}, protocols: []string{"http", "svn"},
tryPrefixes: false,
defaultHosts: []host{ defaultHosts: []host{
{regexp.MustCompile(`^([a-z0-9\-]+\.googlecode\.com/svn)(/[a-z0-9A-Z_.\-/]*)?$`), "https"}, {regexp.MustCompile(`^([a-z0-9\-]+\.googlecode\.com/svn)(/[a-z0-9A-Z_.\-/]*)?$`), "https"},
}, },
...@@ -145,7 +135,6 @@ var bzr = vcs{ ...@@ -145,7 +135,6 @@ var bzr = vcs{
logReleaseFlag: "-rrelease", logReleaseFlag: "-rrelease",
check: "info", check: "info",
protocols: []string{"http", "bzr"}, protocols: []string{"http", "bzr"},
tryPrefixes: true,
defaultHosts: []host{ 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"}, {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{ ...@@ -153,84 +142,6 @@ var bzr = vcs{
var vcsList = []*vcs{&git, &hg, &bzr, &svn} 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 // 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 // hostname - i.e. contains at least one '.' and the last part is at least 2
// characters. // characters.
...@@ -263,9 +174,6 @@ func download(pkg, srcDir string) os.Error { ...@@ -263,9 +174,6 @@ func download(pkg, srcDir string) os.Error {
} }
} }
} }
if m == nil {
m = findVcs(pkg)
}
if m == nil { if m == nil {
return os.ErrorString("cannot download: " + pkg) 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