OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """This scripts takes the path to a dep and an svn revision, and updates the | 6 """This scripts takes the path to a dep and an svn revision, and updates the |
7 parent repo's DEPS file with the corresponding git revision. Sample invocation: | 7 parent repo's DEPS file with the corresponding git revision. Sample invocation: |
8 | 8 |
9 [chromium/src]$ roll-dep third_party/WebKit 12345 | 9 [chromium/src]$ roll-dep third_party/WebKit 12345 |
10 | 10 |
11 After the script completes, the DEPS file will be dirty with the new revision. | 11 After the script completes, the DEPS file will be dirty with the new revision. |
12 The user can then: | 12 The user can then: |
13 | 13 |
14 $ git add DEPS | 14 $ git add DEPS |
15 $ git commit | 15 $ git commit |
16 """ | 16 """ |
17 | 17 |
18 import ast | 18 import ast |
19 import os | 19 import os |
20 import re | 20 import re |
21 import sys | 21 import sys |
22 | 22 |
23 from itertools import izip | 23 from itertools import izip |
24 from subprocess import Popen, PIPE | 24 from subprocess import Popen, PIPE |
25 from textwrap import dedent | 25 from textwrap import dedent |
26 | 26 |
27 | 27 |
28 SHA1_RE = re.compile('^[a-fA-F0-9]{40}$') | 28 SHA1_RE = re.compile('^[a-fA-F0-9]{40}$') |
29 GIT_SVN_ID_RE = re.compile('^git-svn-id: .*@([0-9]+) .*$') | 29 GIT_SVN_ID_RE = re.compile('^git-svn-id: .*@([0-9]+) .*$') |
| 30 ROLL_DESCRIPTION_STR = '''Roll %s from %s to %s |
| 31 |
| 32 Summary of changes available at: |
| 33 %s |
| 34 ''' |
| 35 |
| 36 |
| 37 def shorten_dep_path(dep): |
| 38 """Shorten the given dep path if necessary.""" |
| 39 while len(dep) > 31: |
| 40 dep = '.../' + dep.lstrip('./').partition('/')[2] |
| 41 return dep |
30 | 42 |
31 | 43 |
32 def posix_path(path): | 44 def posix_path(path): |
33 """Convert a possibly-Windows path to a posix-style path.""" | 45 """Convert a possibly-Windows path to a posix-style path.""" |
34 (_, path) = os.path.splitdrive(path) | 46 (_, path) = os.path.splitdrive(path) |
35 return path.replace(os.sep, '/') | 47 return path.replace(os.sep, '/') |
36 | 48 |
37 | 49 |
38 def platform_path(path): | 50 def platform_path(path): |
39 """Convert a path to the native path format of the host OS.""" | 51 """Convert a path to the native path format of the host OS.""" |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 'Could not find definition of "%s" var in DEPS file.' % var_name) | 253 'Could not find definition of "%s" var in DEPS file.' % var_name) |
242 val_node = vars_node.values[var_idx] | 254 val_node = vars_node.values[var_idx] |
243 return update_node(deps_lines, deps_ast, val_node, git_revision) | 255 return update_node(deps_lines, deps_ast, val_node, git_revision) |
244 | 256 |
245 | 257 |
246 def generate_commit_message(deps_section, dep_name, new_rev): | 258 def generate_commit_message(deps_section, dep_name, new_rev): |
247 (url, _, old_rev) = deps_section[dep_name].partition('@') | 259 (url, _, old_rev) = deps_section[dep_name].partition('@') |
248 if url.endswith('.git'): | 260 if url.endswith('.git'): |
249 url = url[:-4] | 261 url = url[:-4] |
250 url += '/+log/%s..%s' % (old_rev[:12], new_rev[:12]) | 262 url += '/+log/%s..%s' % (old_rev[:12], new_rev[:12]) |
251 return dedent('''\ | 263 return dedent(ROLL_DESCRIPTION_STR % ( |
252 Rolled %s | 264 shorten_dep_path(dep_name), old_rev[:12], new_rev[:12], url)) |
253 from revision %s | |
254 to revision %s | |
255 Summary of changes available at: | |
256 %s\n''' % (dep_name, old_rev, new_rev, url)) | |
257 | 265 |
258 def update_deps_entry(deps_lines, deps_ast, value_node, new_rev, comment): | 266 def update_deps_entry(deps_lines, deps_ast, value_node, new_rev, comment): |
259 line_idx = update_node(deps_lines, deps_ast, value_node, new_rev) | 267 line_idx = update_node(deps_lines, deps_ast, value_node, new_rev) |
260 (content, _, _) = deps_lines[line_idx].partition('#') | 268 (content, _, _) = deps_lines[line_idx].partition('#') |
261 if comment: | 269 if comment: |
262 deps_lines[line_idx] = '%s # %s' % (content.rstrip(), comment) | 270 deps_lines[line_idx] = '%s # %s' % (content.rstrip(), comment) |
263 else: | 271 else: |
264 deps_lines[line_idx] = content.rstrip() | 272 deps_lines[line_idx] = content.rstrip() |
265 | 273 |
266 def update_deps(soln_path, dep_name, new_rev, comment): | 274 def update_deps(soln_path, dep_name, new_rev, comment): |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 soln = get_solution(gclient_root, dep_path) | 328 soln = get_solution(gclient_root, dep_path) |
321 soln_path = os.path.relpath(os.path.join(gclient_root, soln['name'])) | 329 soln_path = os.path.relpath(os.path.join(gclient_root, soln['name'])) |
322 dep_name = posix_path(os.path.relpath(dep_path, gclient_root)) | 330 dep_name = posix_path(os.path.relpath(dep_path, gclient_root)) |
323 (git_rev, svn_rev) = get_git_revision(dep_path, revision) | 331 (git_rev, svn_rev) = get_git_revision(dep_path, revision) |
324 comment = ('from svn revision %s' % svn_rev) if svn_rev else None | 332 comment = ('from svn revision %s' % svn_rev) if svn_rev else None |
325 assert git_rev, 'Could not find git revision matching %s.' % revision | 333 assert git_rev, 'Could not find git revision matching %s.' % revision |
326 return update_deps(soln_path, dep_name, git_rev, comment) | 334 return update_deps(soln_path, dep_name, git_rev, comment) |
327 | 335 |
328 if __name__ == '__main__': | 336 if __name__ == '__main__': |
329 sys.exit(main(sys.argv[1:])) | 337 sys.exit(main(sys.argv[1:])) |
OLD | NEW |