OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 the V8 project authors. All rights reserved. | 2 # Copyright 2014 the V8 project authors. All rights reserved. |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following | 10 # copyright notice, this list of conditions and the following |
(...skipping 11 matching lines...) Expand all Loading... | |
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | 28 |
29 import re | 29 import re |
30 | 30 |
31 SHA1_RE = re.compile('^[a-fA-F0-9]{40}$') | 31 SHA1_RE = re.compile('^[a-fA-F0-9]{40}$') |
32 GIT_SVN_ID_RE = re.compile('^git-svn-id: .*@([0-9]+) .*$') | 32 ROLL_DEPS_GIT_SVN_ID_RE = re.compile('^git-svn-id: .*@([0-9]+) .*$') |
33 | |
Michael Achenbach
2014/09/04 08:08:47
This is all copied from releases.py for sharing.
| |
34 # Regular expression that matches a single commit footer line. | |
35 COMMIT_FOOTER_ENTRY_RE = re.compile(r'([^:]+):\s+(.+)') | |
36 | |
37 # Footer metadata key for commit position. | |
38 COMMIT_POSITION_FOOTER_KEY = 'Cr-Commit-Position' | |
39 | |
40 # Regular expression to parse a commit position | |
41 COMMIT_POSITION_RE = re.compile(r'(.+)@\{#(\d+)\}') | |
42 | |
43 # Key for the 'git-svn' ID metadata commit footer entry. | |
44 GIT_SVN_ID_FOOTER_KEY = 'git-svn-id' | |
45 | |
46 # e.g., git-svn-id: https://v8.googlecode.com/svn/trunk@23117 | |
47 # ce2b1a6d-e550-0410-aec6-3dcde31c8c00 | |
48 GIT_SVN_ID_RE = re.compile(r'((?:\w+)://[^@]+)@(\d+)\s+(?:[a-zA-Z0-9\-]+)') | |
49 | |
50 | |
51 # Copied from bot_update.py. | |
52 def GetCommitMessageFooterMap(message): | |
53 """Returns: (dict) A dictionary of commit message footer entries. | |
54 """ | |
55 footers = {} | |
56 | |
57 # Extract the lines in the footer block. | |
58 lines = [] | |
59 for line in message.strip().splitlines(): | |
60 line = line.strip() | |
61 if len(line) == 0: | |
62 del(lines[:]) | |
63 continue | |
64 lines.append(line) | |
65 | |
66 # Parse the footer | |
67 for line in lines: | |
68 m = COMMIT_FOOTER_ENTRY_RE.match(line) | |
69 if not m: | |
70 # If any single line isn't valid, the entire footer is invalid. | |
71 footers.clear() | |
72 return footers | |
73 footers[m.group(1)] = m.group(2).strip() | |
74 return footers | |
33 | 75 |
34 | 76 |
35 class GitFailedException(Exception): | 77 class GitFailedException(Exception): |
36 pass | 78 pass |
37 | 79 |
38 | 80 |
39 def Strip(f): | 81 def Strip(f): |
40 def new_f(*args, **kwargs): | 82 def new_f(*args, **kwargs): |
41 return f(*args, **kwargs).strip() | 83 return f(*args, **kwargs).strip() |
42 return new_f | 84 return new_f |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 | 234 |
193 def GitFetchOrigin(self): | 235 def GitFetchOrigin(self): |
194 self.Git("fetch origin") | 236 self.Git("fetch origin") |
195 | 237 |
196 def GitConvertToSVNRevision(self, git_hash): | 238 def GitConvertToSVNRevision(self, git_hash): |
197 result = self.Git(MakeArgs(["rev-list", "-n", "1", git_hash])) | 239 result = self.Git(MakeArgs(["rev-list", "-n", "1", git_hash])) |
198 if not result or not SHA1_RE.match(result): | 240 if not result or not SHA1_RE.match(result): |
199 raise GitFailedException("Git hash %s is unknown." % git_hash) | 241 raise GitFailedException("Git hash %s is unknown." % git_hash) |
200 log = self.GitLog(n=1, format="%B", git_hash=git_hash) | 242 log = self.GitLog(n=1, format="%B", git_hash=git_hash) |
201 for line in reversed(log.splitlines()): | 243 for line in reversed(log.splitlines()): |
202 match = GIT_SVN_ID_RE.match(line.strip()) | 244 match = ROLL_DEPS_GIT_SVN_ID_RE.match(line.strip()) |
203 if match: | 245 if match: |
204 return match.group(1) | 246 return match.group(1) |
205 raise GitFailedException("Couldn't convert %s to SVN." % git_hash) | 247 raise GitFailedException("Couldn't convert %s to SVN." % git_hash) |
206 | 248 |
249 @Strip | |
250 # Copied from bot_update.py and modified for svn-like numbers only. | |
251 def GetCommitPositionNumber(self, git_hash): | |
252 """Dumps the 'git' log for a specific revision and parses out the commit | |
253 position number. | |
254 | |
255 If a commit position metadata key is found, its number will be returned. | |
256 | |
257 Otherwise, we will search for a 'git-svn' metadata entry. If one is found, | |
258 its SVN revision value is returned. | |
259 """ | |
260 git_log = self.GitLog(format='%B', n=1, git_hash=git_hash) | |
261 footer_map = GetCommitMessageFooterMap(git_log) | |
262 | |
263 # Search for commit position metadata | |
264 value = footer_map.get(COMMIT_POSITION_FOOTER_KEY) | |
265 if value: | |
266 match = COMMIT_POSITION_RE.match(value) | |
267 if match: | |
268 return match.group(2) | |
269 | |
270 # Extract the svn revision from 'git-svn' metadata | |
271 value = footer_map.get(GIT_SVN_ID_FOOTER_KEY) | |
272 if value: | |
273 match = GIT_SVN_ID_RE.match(value) | |
274 if match: | |
275 return match.group(2) | |
276 return None | |
277 | |
278 ### Git svn stuff | |
279 | |
207 def GitSVNFetch(self): | 280 def GitSVNFetch(self): |
208 self.Git("svn fetch") | 281 self.Git("svn fetch") |
209 | 282 |
210 def GitSVNRebase(self): | 283 def GitSVNRebase(self): |
211 self.Git("svn rebase") | 284 self.Git("svn rebase") |
212 | 285 |
213 # TODO(machenbach): Unused? Remove. | 286 # TODO(machenbach): Unused? Remove. |
214 @Strip | 287 @Strip |
215 def GitSVNLog(self): | 288 def GitSVNLog(self): |
216 return self.Git("svn log -1 --oneline") | 289 return self.Git("svn log -1 --oneline") |
217 | 290 |
218 @Strip | 291 @Strip |
219 def GitSVNFindGitHash(self, revision, branch=""): | 292 def GitSVNFindGitHash(self, revision, branch=""): |
220 assert revision | 293 assert revision |
221 return self.Git(MakeArgs(["svn find-rev", "r%s" % revision, branch])) | 294 return self.Git(MakeArgs(["svn find-rev", "r%s" % revision, branch])) |
222 | 295 |
223 @Strip | 296 @Strip |
224 def GitSVNFindSVNRev(self, git_hash, branch=""): | 297 def GitSVNFindSVNRev(self, git_hash, branch=""): |
225 return self.Git(MakeArgs(["svn find-rev", git_hash, branch])) | 298 return self.Git(MakeArgs(["svn find-rev", git_hash, branch])) |
226 | 299 |
227 def GitSVNDCommit(self): | 300 def GitSVNDCommit(self): |
228 return self.Git("svn dcommit 2>&1", retry_on=lambda x: x is None) | 301 return self.Git("svn dcommit 2>&1", retry_on=lambda x: x is None) |
229 | 302 |
230 def GitSVNTag(self, version): | 303 def GitSVNTag(self, version): |
231 self.Git(("svn tag %s -m \"Tagging version %s\"" % (version, version)), | 304 self.Git(("svn tag %s -m \"Tagging version %s\"" % (version, version)), |
232 retry_on=lambda x: x is None) | 305 retry_on=lambda x: x is None) |
OLD | NEW |