OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 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 """Rolls DEPS controlled dependency. | 6 """Rolls DEPS controlled dependency. |
7 | 7 |
8 Works only with git checkout and git dependencies. Currently this | 8 Works only with git checkout and git dependencies. Currently this |
9 script will always roll to the tip of to origin/master. | 9 script will always roll to the tip of to origin/master. |
10 """ | 10 """ |
11 | 11 |
12 import argparse | 12 import argparse |
13 import os | 13 import os |
14 import re | 14 import re |
15 import subprocess | 15 import subprocess |
16 import sys | 16 import sys |
17 | 17 |
18 NEED_SHELL = sys.platform.startswith('win') | 18 NEED_SHELL = sys.platform.startswith('win') |
19 | 19 |
20 GITILES_REGEX = r'https?://[^/]*\.googlesource\.com/' | |
21 | |
22 | 20 |
23 class Error(Exception): | 21 class Error(Exception): |
24 pass | 22 pass |
25 | 23 |
26 | 24 |
27 def check_output(*args, **kwargs): | 25 def check_output(*args, **kwargs): |
28 """subprocess.check_output() passing shell=True on Windows for git.""" | 26 """subprocess.check_output() passing shell=True on Windows for git.""" |
29 kwargs.setdefault('shell', NEED_SHELL) | 27 kwargs.setdefault('shell', NEED_SHELL) |
30 return subprocess.check_output(*args, **kwargs) | 28 return subprocess.check_output(*args, **kwargs) |
31 | 29 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 79 |
82 check_call(['git', 'fetch', 'origin'], cwd=full_dir) | 80 check_call(['git', 'fetch', 'origin'], cwd=full_dir) |
83 master = check_output( | 81 master = check_output( |
84 ['git', 'rev-parse', 'origin/master'], cwd=full_dir).strip() | 82 ['git', 'rev-parse', 'origin/master'], cwd=full_dir).strip() |
85 print('Found new revision %s' % master) | 83 print('Found new revision %s' % master) |
86 | 84 |
87 if master == head: | 85 if master == head: |
88 raise Error('No revision to roll!') | 86 raise Error('No revision to roll!') |
89 | 87 |
90 commit_range = '%s..%s' % (head[:9], master[:9]) | 88 commit_range = '%s..%s' % (head[:9], master[:9]) |
91 upstream_url = check_output( | |
92 ['git', 'config', 'remote.origin.url'], cwd=full_dir).strip() | |
93 | 89 |
94 log_url = None | 90 logs = check_output( |
95 if re.match(GITILES_REGEX, upstream_url): | 91 ['git', 'log', commit_range, '--date=short', '--format=%ad %ae %s'], |
96 log_url = '%s/+log/%s..%s' % (upstream_url, head, master) | 92 cwd=full_dir).strip() |
97 | 93 logs = re.sub(r'(?m)^(\d\d\d\d-\d\d-\d\d [^@]+)@[^ ]+( .*)$', r'\1\2', logs) |
98 msg_args = { | 94 cmd = 'git log %s --date=short --format=\'%%ad %%ae %%s\'' % commit_range |
99 'deps_dir': deps_dir, | 95 reviewer = 'R=%s\n' % ','.join(reviewers) if reviewers else '' |
100 'commit_range': commit_range, | 96 bug = 'BUG=%s\n' % bug if bug else '' |
101 'log': '%s\n\n' % log_url if log_url else '', | |
102 'reviewer': 'R=%s\n' % ','.join(reviewers) if reviewers else '', | |
103 'bug': 'BUG=%s\n' % bug if bug else '', | |
104 } | |
105 msg = ( | 97 msg = ( |
106 'Roll %(deps_dir)s %(commit_range)s\n' | 98 'Roll %s/ to %s.\n' |
107 '\n' | 99 '\n' |
108 '%(log)s' | 100 '$ %s\n' |
109 '%(reviewer)s' | 101 '%s\n\n' |
110 '%(bug)s' % msg_args) | 102 '%s' |
| 103 '%s') % ( |
| 104 deps_dir, |
| 105 master, |
| 106 cmd, |
| 107 logs, |
| 108 reviewer, |
| 109 bug) |
111 | 110 |
112 print('Commit message:') | 111 print('Commit message:') |
113 print('\n'.join(' ' + i for i in msg.splitlines())) | 112 print('\n'.join(' ' + i for i in msg.splitlines())) |
114 deps_content = deps_content.replace(head, master) | 113 deps_content = deps_content.replace(head, master) |
115 with open(deps, 'wb') as f: | 114 with open(deps, 'wb') as f: |
116 f.write(deps_content) | 115 f.write(deps_content) |
117 check_call(['git', 'add', 'DEPS'], cwd=root) | 116 check_call(['git', 'add', 'DEPS'], cwd=root) |
118 check_call(['git', 'commit', '-m', msg], cwd=root) | 117 check_call(['git', 'commit', '-m', msg], cwd=root) |
119 print('') | 118 print('') |
120 if not reviewers: | 119 if not reviewers: |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 | 152 |
154 except Error as e: | 153 except Error as e: |
155 sys.stderr.write('error: %s\n' % e) | 154 sys.stderr.write('error: %s\n' % e) |
156 return 1 | 155 return 1 |
157 | 156 |
158 return 0 | 157 return 0 |
159 | 158 |
160 | 159 |
161 if __name__ == '__main__': | 160 if __name__ == '__main__': |
162 sys.exit(main()) | 161 sys.exit(main()) |
OLD | NEW |