Left: | ||
Right: |
OLD | NEW |
---|---|
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Download remote packages. | 5 // Download remote packages. |
6 | 6 |
7 package main | 7 package main |
8 | 8 |
9 import ( | 9 import ( |
10 "http" | 10 "http" |
(...skipping 16 matching lines...) Expand all Loading... | |
27 // otherwise lob url to dashboard | 27 // otherwise lob url to dashboard |
28 r, _ := http.Post(dashboardURL, "application/x-www-form-urlencoded", str ings.NewReader("path="+path)) | 28 r, _ := http.Post(dashboardURL, "application/x-www-form-urlencoded", str ings.NewReader("path="+path)) |
29 if r != nil && r.Body != nil { | 29 if r != nil && r.Body != nil { |
30 r.Body.Close() | 30 r.Body.Close() |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 var googlecode = regexp.MustCompile(`^([a-z0-9\-]+\.googlecode\.com/(svn|hg))(/[ a-z0-9A-Z_.\-/]*)?$`) | 34 var googlecode = regexp.MustCompile(`^([a-z0-9\-]+\.googlecode\.com/(svn|hg))(/[ a-z0-9A-Z_.\-/]*)?$`) |
35 var github = regexp.MustCompile(`^(github\.com/[a-z0-9A-Z_.\-]+/[a-z0-9A-Z_.\-]+ )(/[a-z0-9A-Z_.\-/]*)?$`) | 35 var github = regexp.MustCompile(`^(github\.com/[a-z0-9A-Z_.\-]+/[a-z0-9A-Z_.\-]+ )(/[a-z0-9A-Z_.\-/]*)?$`) |
36 var bitbucket = regexp.MustCompile(`^(bitbucket\.org/[a-z0-9A-Z_.\-]+/[a-z0-9A-Z _.\-]+)(/[a-z0-9A-Z_.\-/]*)?$`) | 36 var bitbucket = regexp.MustCompile(`^(bitbucket\.org/[a-z0-9A-Z_.\-]+/[a-z0-9A-Z _.\-]+)(/[a-z0-9A-Z_.\-/]*)?$`) |
37 var launchpad = 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_.\-/]+)?$`) | |
rsc1
2010/06/28 21:17:44
Really? +junk ?
niemeyer
2010/06/28 21:46:30
Yeah, I know it sounds weird. The background of t
| |
37 | 38 |
38 // download checks out or updates pkg from the remote server. | 39 // download checks out or updates pkg from the remote server. |
39 func download(pkg string) (string, os.Error) { | 40 func download(pkg string) (string, os.Error) { |
40 if strings.Index(pkg, "..") >= 0 { | 41 if strings.Index(pkg, "..") >= 0 { |
41 return "", os.ErrorString("invalid path (contains ..)") | 42 return "", os.ErrorString("invalid path (contains ..)") |
42 } | 43 } |
43 if m := bitbucket.MatchStrings(pkg); m != nil { | 44 if m := bitbucket.MatchStrings(pkg); m != nil { |
44 if err := vcsCheckout(&hg, root+m[1], "http://"+m[1], m[1]); err != nil { | 45 if err := vcsCheckout(&hg, root+m[1], "http://"+m[1], m[1]); err != nil { |
45 return "", err | 46 return "", err |
46 } | 47 } |
(...skipping 17 matching lines...) Expand all Loading... | |
64 } | 65 } |
65 if m := github.MatchStrings(pkg); m != nil { | 66 if m := github.MatchStrings(pkg); m != nil { |
66 if strings.HasSuffix(m[1], ".git") { | 67 if strings.HasSuffix(m[1], ".git") { |
67 return "", os.ErrorString("repository " + pkg + " should not have .git suffix") | 68 return "", os.ErrorString("repository " + pkg + " should not have .git suffix") |
68 } | 69 } |
69 if err := vcsCheckout(&git, root+m[1], "http://"+m[1]+".git", m[ 1]); err != nil { | 70 if err := vcsCheckout(&git, root+m[1], "http://"+m[1]+".git", m[ 1]); err != nil { |
70 return "", err | 71 return "", err |
71 } | 72 } |
72 return root + pkg, nil | 73 return root + pkg, nil |
73 } | 74 } |
75 if m := launchpad.MatchStrings(pkg); m != nil { | |
76 // Either lp.net/<project>[/<series>[/<path>]] | |
77 // or lp.net/~<user or team>/<project>/<branch>[/<path>] | |
78 if err := vcsCheckout(&bzr, root+m[1], "https://"+m[1], m[1]); e rr != nil { | |
79 return "", err | |
80 } | |
81 return root + pkg, nil | |
82 } | |
74 return "", os.ErrorString("unknown repository: " + pkg) | 83 return "", os.ErrorString("unknown repository: " + pkg) |
75 } | 84 } |
76 | 85 |
77 // a vcs represents a version control system | 86 // a vcs represents a version control system |
78 // like Mercurial, Git, or Subversion. | 87 // like Mercurial, Git, or Subversion. |
79 type vcs struct { | 88 type vcs struct { |
80 » cmd string | 89 » cmd string |
81 » metadir string | 90 » metadir string |
82 » clone string | 91 » clone string |
83 » update string | 92 » update» » » string |
84 » pull string | 93 » updateReleaseFlag string |
85 » log string | 94 » pull string |
86 » logLimitFlag string | 95 » pullForceFlag string |
87 » logReleaseFlag string | 96 » log string |
97 » logLimitFlag string | |
98 » logReleaseFlag string | |
88 } | 99 } |
89 | 100 |
90 var hg = vcs{ | 101 var hg = vcs{ |
91 » cmd: "hg", | 102 » cmd: "hg", |
92 » metadir: ".hg", | 103 » metadir: ".hg", |
93 » clone: "clone", | 104 » clone: "clone", |
94 » update: "update", | 105 » update: "update", |
95 » pull: "pull", | 106 » updateReleaseFlag: "release", |
96 » log: "log", | 107 » pull: "pull", |
97 » logLimitFlag: "-l1", | 108 » log: "log", |
98 » logReleaseFlag: "-rrelease", | 109 » logLimitFlag: "-l1", |
110 » logReleaseFlag: "-rrelease", | |
99 } | 111 } |
100 | 112 |
101 var git = vcs{ | 113 var git = vcs{ |
102 » cmd: "git", | 114 » cmd: "git", |
103 » metadir: ".git", | 115 » metadir: ".git", |
104 » clone: "clone", | 116 » clone: "clone", |
105 » update: "pull", | 117 » update: "pull", |
106 » pull: "fetch", | 118 » updateReleaseFlag: "release", |
107 » log: "log", | 119 » pull: "fetch", |
108 » logLimitFlag: "-n1", | 120 » log: "log", |
109 » logReleaseFlag: "release", | 121 » logLimitFlag: "-n1", |
122 » logReleaseFlag: "release", | |
110 } | 123 } |
111 | 124 |
112 var svn = vcs{ | 125 var svn = vcs{ |
113 » cmd: "svn", | 126 » cmd: "svn", |
114 » metadir: ".svn", | 127 » metadir: ".svn", |
115 » clone: "checkout", | 128 » clone: "checkout", |
116 » update: "update", | 129 » update: "update", |
117 » pull: "", | 130 » updateReleaseFlag: "release", |
118 » log: "log", | 131 » log: "log", |
119 » logLimitFlag: "-l1", | 132 » logLimitFlag: "-l1", |
120 » logReleaseFlag: "release", | 133 » logReleaseFlag: "release", |
134 } | |
135 | |
136 var bzr = vcs{ | |
137 » cmd: "bzr", | |
138 » metadir: ".bzr", | |
139 » clone: "branch", | |
140 » update: "update", | |
141 » updateReleaseFlag: "-rrelease", | |
142 » pull: "pull", | |
143 » pullForceFlag: "--overwrite", | |
144 » log: "log", | |
145 » logLimitFlag: "-l1", | |
146 » logReleaseFlag: "-rrelease", | |
121 } | 147 } |
122 | 148 |
123 // vcsCheckout checks out repo into dst using vcs. | 149 // vcsCheckout checks out repo into dst using vcs. |
124 // It tries to check out (or update, if the dst already | 150 // It tries to check out (or update, if the dst already |
125 // exists and -u was specified on the command line) | 151 // exists and -u was specified on the command line) |
126 // the repository at tag/branch "release". If there is no | 152 // the repository at tag/branch "release". If there is no |
127 // such tag or branch, it falls back to the repository tip. | 153 // such tag or branch, it falls back to the repository tip. |
128 func vcsCheckout(vcs *vcs, dst, repo, dashpath string) os.Error { | 154 func vcsCheckout(vcs *vcs, dst, repo, dashpath string) os.Error { |
129 dir, err := os.Stat(dst + "/" + vcs.metadir) | 155 dir, err := os.Stat(dst + "/" + vcs.metadir) |
130 if err == nil && !dir.IsDirectory() { | 156 if err == nil && !dir.IsDirectory() { |
131 return os.ErrorString("not a directory: " + dst) | 157 return os.ErrorString("not a directory: " + dst) |
132 } | 158 } |
133 if err != nil { | 159 if err != nil { |
134 parent, _ := path.Split(dst) | 160 parent, _ := path.Split(dst) |
135 if err := os.MkdirAll(parent, 0777); err != nil { | 161 if err := os.MkdirAll(parent, 0777); err != nil { |
136 return err | 162 return err |
137 } | 163 } |
138 if err := run("/", nil, vcs.cmd, vcs.clone, repo, dst); err != n il { | 164 if err := run("/", nil, vcs.cmd, vcs.clone, repo, dst); err != n il { |
139 return err | 165 return err |
140 } | 166 } |
141 » » quietRun(dst, nil, vcs.cmd, vcs.update, "release") | 167 » » quietRun(dst, nil, vcs.cmd, vcs.update, vcs.updateReleaseFlag) |
142 | 168 |
143 // success on first installation - report | 169 // success on first installation - report |
144 maybeReportToDashboard(dashpath) | 170 maybeReportToDashboard(dashpath) |
145 } else if *update { | 171 } else if *update { |
172 // Retrieve new revisions from the remote branch, if the VCS | |
173 // supports this operation independently (e.g. svn doesn't) | |
146 if vcs.pull != "" { | 174 if vcs.pull != "" { |
147 » » » if err := run(dst, nil, vcs.cmd, vcs.pull); err != nil { | 175 » » » if vcs.pullForceFlag != "" { |
176 » » » » if err := run(dst, nil, vcs.cmd, vcs.pull, vcs.p ullForceFlag); err != nil { | |
177 » » » » » return err | |
178 » » » » } | |
179 » » » } else if err := run(dst, nil, vcs.cmd, vcs.pull); err ! = nil { | |
148 return err | 180 return err |
149 } | 181 } |
150 } | 182 } |
151 » » // check for release with hg log -l 1 -r release | 183 |
152 » » // if success, hg update release | 184 » » // Try to detect if a "release" tag exists. If it does, update |
153 » » // else hg update | 185 » » // to the tagged version. If no tag is found, then update to th e |
186 » » // tip afterwards. | |
187 » » // XXX What is the expected behavior with svn here? This seems | |
rsc1
2010/06/28 21:17:44
// NOTE(n13m3y3r@gmail.com): What is the expected
niemeyer
2010/06/28 21:46:30
Done. I've just used my actual email instead.
| |
188 » » // to be running "svn log -l1 release", which doesn't make m uch | |
189 » » // sense in this context, and in the best case will fail. | |
190 » » // -- Gustavo Niemeyer | |
154 if err := quietRun(dst, nil, vcs.cmd, vcs.log, vcs.logLimitFlag, vcs.logReleaseFlag); err == nil { | 191 if err := quietRun(dst, nil, vcs.cmd, vcs.log, vcs.logLimitFlag, vcs.logReleaseFlag); err == nil { |
155 » » » if err := run(dst, nil, vcs.cmd, vcs.update, "release"); err != nil { | 192 » » » if err := run(dst, nil, vcs.cmd, vcs.update, vcs.updateR eleaseFlag); err != nil { |
193 » » » » // The VCS supports tagging, has the "release" t ag, but | |
194 » » » » // something else went wrong. Report. | |
156 return err | 195 return err |
157 } | 196 } |
158 » » } else { | 197 » » } else if err := run(dst, nil, vcs.cmd, vcs.update); err != nil { |
159 » » » if err := run(dst, nil, vcs.cmd, vcs.update); err != nil { | 198 » » » return err |
160 » » » » return err | |
161 » » » } | |
162 } | 199 } |
163 } | 200 } |
164 return nil | 201 return nil |
165 } | 202 } |
OLD | NEW |