summaryrefslogtreecommitdiff
path: root/src/cmd/goinstall/download.go
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2011-01-17 12:40:45 +0100
committerOndřej Surý <ondrej@sury.org>2011-01-17 12:40:45 +0100
commit3e45412327a2654a77944249962b3652e6142299 (patch)
treebc3bf69452afa055423cbe0c5cfa8ca357df6ccf /src/cmd/goinstall/download.go
parentc533680039762cacbc37db8dc7eed074c3e497be (diff)
downloadgolang-upstream/2011.01.12.tar.gz
Imported Upstream version 2011.01.12upstream/2011.01.12
Diffstat (limited to 'src/cmd/goinstall/download.go')
-rw-r--r--src/cmd/goinstall/download.go57
1 files changed, 34 insertions, 23 deletions
diff --git a/src/cmd/goinstall/download.go b/src/cmd/goinstall/download.go
index 3422e8186..889f9d857 100644
--- a/src/cmd/goinstall/download.go
+++ b/src/cmd/goinstall/download.go
@@ -38,16 +38,16 @@ var launchpad = regexp.MustCompile(`^(launchpad\.net/([a-z0-9A-Z_.\-]+(/[a-z0-9A
// download checks out or updates pkg from the remote server.
func download(pkg string) (string, os.Error) {
- if strings.Index(pkg, "..") >= 0 {
+ if strings.Contains(pkg, "..") {
return "", os.ErrorString("invalid path (contains ..)")
}
- if m := bitbucket.MatchStrings(pkg); m != nil {
+ if m := bitbucket.FindStringSubmatch(pkg); m != nil {
if err := vcsCheckout(&hg, root+m[1], "http://"+m[1], m[1]); err != nil {
return "", err
}
return root + pkg, nil
}
- if m := googlecode.MatchStrings(pkg); m != nil {
+ if m := googlecode.FindStringSubmatch(pkg); m != nil {
var v *vcs
switch m[2] {
case "hg":
@@ -58,12 +58,12 @@ func download(pkg string) (string, os.Error) {
// regexp only allows hg, svn to get through
panic("missing case in download: " + pkg)
}
- if err := vcsCheckout(v, root+m[1], "http://"+m[1], m[1]); err != nil {
+ if err := vcsCheckout(v, root+m[1], "https://"+m[1], m[1]); err != nil {
return "", err
}
return root + pkg, nil
}
- if m := github.MatchStrings(pkg); m != nil {
+ if m := github.FindStringSubmatch(pkg); m != nil {
if strings.HasSuffix(m[1], ".git") {
return "", os.ErrorString("repository " + pkg + " should not have .git suffix")
}
@@ -72,7 +72,7 @@ func download(pkg string) (string, os.Error) {
}
return root + pkg, nil
}
- if m := launchpad.MatchStrings(pkg); m != nil {
+ if m := launchpad.FindStringSubmatch(pkg); m != nil {
// Either lp.net/<project>[/<series>[/<path>]]
// or lp.net/~<user or team>/<project>/<branch>[/<path>]
if err := vcsCheckout(&bzr, root+m[1], "https://"+m[1], m[1]); err != nil {
@@ -88,6 +88,7 @@ func download(pkg string) (string, os.Error) {
type vcs struct {
cmd string
metadir string
+ checkout string
clone string
update string
updateReleaseFlag string
@@ -101,6 +102,7 @@ type vcs struct {
var hg = vcs{
cmd: "hg",
metadir: ".hg",
+ checkout: "checkout",
clone: "clone",
update: "update",
updateReleaseFlag: "release",
@@ -113,18 +115,20 @@ var hg = vcs{
var git = vcs{
cmd: "git",
metadir: ".git",
+ checkout: "checkout",
clone: "clone",
update: "pull",
updateReleaseFlag: "release",
pull: "fetch",
- log: "log",
- logLimitFlag: "-n1",
+ log: "show-ref",
+ logLimitFlag: "",
logReleaseFlag: "release",
}
var svn = vcs{
cmd: "svn",
metadir: ".svn",
+ checkout: "checkout",
clone: "checkout",
update: "update",
updateReleaseFlag: "release",
@@ -136,6 +140,7 @@ var svn = vcs{
var bzr = vcs{
cmd: "bzr",
metadir: ".bzr",
+ checkout: "update",
clone: "branch",
update: "update",
updateReleaseFlag: "-rrelease",
@@ -146,6 +151,22 @@ var bzr = vcs{
logReleaseFlag: "-rrelease",
}
+// Try to detect if a "release" tag exists. If it does, update
+// to the tagged version, otherwise just update the current branch.
+// NOTE(_nil): svn will always fail because it is trying to get
+// the revision history of a file named "release" instead of
+// looking for a commit with a release tag
+func (v *vcs) updateRepo(dst string) os.Error {
+ if err := quietRun(dst, nil, v.cmd, v.log, v.logLimitFlag, v.logReleaseFlag); err == nil {
+ if err := run(dst, nil, v.cmd, v.checkout, v.updateReleaseFlag); err != nil {
+ return err
+ }
+ } else if err := run(dst, nil, v.cmd, v.update); err != nil {
+ return err
+ }
+ return nil
+}
+
// vcsCheckout checks out repo into dst using vcs.
// It tries to check out (or update, if the dst already
// exists and -u was specified on the command line)
@@ -164,8 +185,9 @@ func vcsCheckout(vcs *vcs, dst, repo, dashpath string) os.Error {
if err := run("/", nil, vcs.cmd, vcs.clone, repo, dst); err != nil {
return err
}
- quietRun(dst, nil, vcs.cmd, vcs.update, vcs.updateReleaseFlag)
-
+ if err := vcs.updateRepo(dst); err != nil {
+ return err
+ }
// success on first installation - report
maybeReportToDashboard(dashpath)
} else if *update {
@@ -181,19 +203,8 @@ func vcsCheckout(vcs *vcs, dst, repo, dashpath string) os.Error {
}
}
- // Try to detect if a "release" tag exists. If it does, update
- // to the tagged version. If no tag is found, then update to the
- // tip afterwards.
- // NOTE(gustavo@niemeyer.net): What is the expected behavior with
- // svn here? "svn log -l1 release" doesn't make sense in this
- // context and will probably fail.
- if err := quietRun(dst, nil, vcs.cmd, vcs.log, vcs.logLimitFlag, vcs.logReleaseFlag); err == nil {
- if err := run(dst, nil, vcs.cmd, vcs.update, vcs.updateReleaseFlag); err != nil {
- // The VCS supports tagging, has the "release" tag, but
- // something else went wrong. Report.
- return err
- }
- } else if err := run(dst, nil, vcs.cmd, vcs.update); err != nil {
+ // Update to release or latest revision
+ if err := vcs.updateRepo(dst); err != nil {
return err
}
}