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 | 20 |
21 class Error(Exception): | 21 class Error(Exception): |
22 pass | 22 pass |
23 | 23 |
24 | 24 |
| 25 class AlreadyRolledError(Error): |
| 26 pass |
| 27 |
| 28 |
25 def check_output(*args, **kwargs): | 29 def check_output(*args, **kwargs): |
26 """subprocess.check_output() passing shell=True on Windows for git.""" | 30 """subprocess.check_output() passing shell=True on Windows for git.""" |
27 kwargs.setdefault('shell', NEED_SHELL) | 31 kwargs.setdefault('shell', NEED_SHELL) |
28 return subprocess.check_output(*args, **kwargs) | 32 return subprocess.check_output(*args, **kwargs) |
29 | 33 |
30 | 34 |
31 def check_call(*args, **kwargs): | 35 def check_call(*args, **kwargs): |
32 """subprocess.check_call() passing shell=True on Windows for git.""" | 36 """subprocess.check_call() passing shell=True on Windows for git.""" |
33 kwargs.setdefault('shell', NEED_SHELL) | 37 kwargs.setdefault('shell', NEED_SHELL) |
34 subprocess.check_call(*args, **kwargs) | 38 subprocess.check_call(*args, **kwargs) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 else: | 106 else: |
103 raise Error('Expected to find commit %s for %s in DEPS' % (head, key)) | 107 raise Error('Expected to find commit %s for %s in DEPS' % (head, key)) |
104 | 108 |
105 print('Found old revision %s' % head) | 109 print('Found old revision %s' % head) |
106 | 110 |
107 check_call(['git', 'fetch', 'origin', '--quiet'], cwd=full_dir) | 111 check_call(['git', 'fetch', 'origin', '--quiet'], cwd=full_dir) |
108 roll_to = check_output(['git', 'rev-parse', roll_to], cwd=full_dir).strip() | 112 roll_to = check_output(['git', 'rev-parse', roll_to], cwd=full_dir).strip() |
109 print('Found new revision %s' % roll_to) | 113 print('Found new revision %s' % roll_to) |
110 | 114 |
111 if roll_to == head: | 115 if roll_to == head: |
112 raise Error('No revision to roll!') | 116 raise AlreadyRolledError('No revision to roll!') |
113 | 117 |
114 commit_range = '%s..%s' % (head[:9], roll_to[:9]) | 118 commit_range = '%s..%s' % (head[:9], roll_to[:9]) |
115 | 119 |
116 upstream_url = check_output( | 120 upstream_url = check_output( |
117 ['git', 'config', 'remote.origin.url'], cwd=full_dir).strip() | 121 ['git', 'config', 'remote.origin.url'], cwd=full_dir).strip() |
118 log_url = get_log_url(upstream_url, head, roll_to) | 122 log_url = get_log_url(upstream_url, head, roll_to) |
119 cmd = [ | 123 cmd = [ |
120 'git', 'log', commit_range, '--date=short', '--no-merges', | 124 'git', 'log', commit_range, '--date=short', '--no-merges', |
121 ] | 125 ] |
122 logs = check_output( | 126 logs = check_output( |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 args.roll_to, | 210 args.roll_to, |
207 args.key, | 211 args.key, |
208 reviewers, | 212 reviewers, |
209 args.bug, | 213 args.bug, |
210 args.no_log, | 214 args.no_log, |
211 args.log_limit, | 215 args.log_limit, |
212 args.ignore_dirty_tree) | 216 args.ignore_dirty_tree) |
213 | 217 |
214 except Error as e: | 218 except Error as e: |
215 sys.stderr.write('error: %s\n' % e) | 219 sys.stderr.write('error: %s\n' % e) |
216 return 1 | 220 return 2 if isinstance(e, AlreadyRolledError) else 1 |
217 | 221 |
218 return 0 | 222 return 0 |
219 | 223 |
220 | 224 |
221 if __name__ == '__main__': | 225 if __name__ == '__main__': |
222 sys.exit(main()) | 226 sys.exit(main()) |
OLD | NEW |