Commit 784788ba authored by Caine Tighe's avatar Caine Tighe Committed by Andrew Gerrand

goinstall/download.go: Add checkout concept and helper functions to clean and...

goinstall/download.go: Add checkout concept and helper functions to clean and fix implementation (Issue 1265)

R=rsc, niemeyer, adg
CC=golang-dev
https://golang.org/cl/3536041
parent fc325c4d
...@@ -88,6 +88,7 @@ func download(pkg string) (string, os.Error) { ...@@ -88,6 +88,7 @@ func download(pkg string) (string, os.Error) {
type vcs struct { type vcs struct {
cmd string cmd string
metadir string metadir string
checkout string
clone string clone string
update string update string
updateReleaseFlag string updateReleaseFlag string
...@@ -101,6 +102,7 @@ type vcs struct { ...@@ -101,6 +102,7 @@ type vcs struct {
var hg = vcs{ var hg = vcs{
cmd: "hg", cmd: "hg",
metadir: ".hg", metadir: ".hg",
checkout: "checkout",
clone: "clone", clone: "clone",
update: "update", update: "update",
updateReleaseFlag: "release", updateReleaseFlag: "release",
...@@ -113,18 +115,20 @@ var hg = vcs{ ...@@ -113,18 +115,20 @@ var hg = vcs{
var git = vcs{ var git = vcs{
cmd: "git", cmd: "git",
metadir: ".git", metadir: ".git",
checkout: "checkout",
clone: "clone", clone: "clone",
update: "pull", update: "pull",
updateReleaseFlag: "release", updateReleaseFlag: "release",
pull: "fetch", pull: "fetch",
log: "log", log: "show-ref",
logLimitFlag: "-n1", logLimitFlag: "",
logReleaseFlag: "release", logReleaseFlag: "release",
} }
var svn = vcs{ var svn = vcs{
cmd: "svn", cmd: "svn",
metadir: ".svn", metadir: ".svn",
checkout: "checkout",
clone: "checkout", clone: "checkout",
update: "update", update: "update",
updateReleaseFlag: "release", updateReleaseFlag: "release",
...@@ -136,6 +140,7 @@ var svn = vcs{ ...@@ -136,6 +140,7 @@ var svn = vcs{
var bzr = vcs{ var bzr = vcs{
cmd: "bzr", cmd: "bzr",
metadir: ".bzr", metadir: ".bzr",
checkout: "checkout",
clone: "branch", clone: "branch",
update: "update", update: "update",
updateReleaseFlag: "-rrelease", updateReleaseFlag: "-rrelease",
...@@ -146,6 +151,22 @@ var bzr = vcs{ ...@@ -146,6 +151,22 @@ var bzr = vcs{
logReleaseFlag: "-rrelease", 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. // vcsCheckout checks out repo into dst using vcs.
// It tries to check out (or update, if the dst already // It tries to check out (or update, if the dst already
// exists and -u was specified on the command line) // exists and -u was specified on the command line)
...@@ -164,8 +185,9 @@ func vcsCheckout(vcs *vcs, dst, repo, dashpath string) os.Error { ...@@ -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 { if err := run("/", nil, vcs.cmd, vcs.clone, repo, dst); err != nil {
return err 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 // success on first installation - report
maybeReportToDashboard(dashpath) maybeReportToDashboard(dashpath)
} else if *update { } else if *update {
...@@ -181,19 +203,8 @@ func vcsCheckout(vcs *vcs, dst, repo, dashpath string) os.Error { ...@@ -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 // Update to release or latest revision
// to the tagged version. If no tag is found, then update to the if err := vcs.updateRepo(dst); err != nil {
// 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 {
return err return err
} }
} }
......
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