Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: roll_dep.py

Issue 1257233006: roll_dep: Avoid large commit messages by providing the log as a link (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
20 22
21 class Error(Exception): 23 class Error(Exception):
22 pass 24 pass
23 25
24 26
25 def check_output(*args, **kwargs): 27 def check_output(*args, **kwargs):
26 """subprocess.check_output() passing shell=True on Windows for git.""" 28 """subprocess.check_output() passing shell=True on Windows for git."""
27 kwargs.setdefault('shell', NEED_SHELL) 29 kwargs.setdefault('shell', NEED_SHELL)
28 return subprocess.check_output(*args, **kwargs) 30 return subprocess.check_output(*args, **kwargs)
29 31
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 81
80 check_call(['git', 'fetch', 'origin'], cwd=full_dir) 82 check_call(['git', 'fetch', 'origin'], cwd=full_dir)
81 master = check_output( 83 master = check_output(
82 ['git', 'rev-parse', 'origin/master'], cwd=full_dir).strip() 84 ['git', 'rev-parse', 'origin/master'], cwd=full_dir).strip()
83 print('Found new revision %s' % master) 85 print('Found new revision %s' % master)
84 86
85 if master == head: 87 if master == head:
86 raise Error('No revision to roll!') 88 raise Error('No revision to roll!')
87 89
88 commit_range = '%s..%s' % (head[:9], master[:9]) 90 commit_range = '%s..%s' % (head[:9], master[:9])
91 upstream_url = check_output(
92 ['git', 'config', 'remote.origin.url'], cwd=full_dir).strip()
89 93
90 logs = check_output( 94 log_url = None
91 ['git', 'log', commit_range, '--date=short', '--format=%ad %ae %s'], 95 if re.match(GITILES_REGEX, upstream_url):
92 cwd=full_dir).strip() 96 log_url = '%s/+log/%s..%s' % (upstream_url, head, master)
93 logs = re.sub(r'(?m)^(\d\d\d\d-\d\d-\d\d [^@]+)@[^ ]+( .*)$', r'\1\2', logs) 97
94 cmd = 'git log %s --date=short --format=\'%%ad %%ae %%s\'' % commit_range 98 msg_args = {
95 reviewer = 'R=%s\n' % ','.join(reviewers) if reviewers else '' 99 'deps_dir': deps_dir,
96 bug = 'BUG=%s\n' % bug if bug else '' 100 'commit_range': commit_range,
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 }
97 msg = ( 105 msg = (
98 'Roll %s/ to %s.\n' 106 'Roll %(deps_dir)s %(commit_range)s\n'
99 '\n' 107 '\n'
100 '$ %s\n' 108 '%(log)s'
101 '%s\n\n' 109 '%(reviewer)s'
102 '%s' 110 '%(bug)s' % msg_args)
103 '%s') % (
104 deps_dir,
105 master,
106 cmd,
107 logs,
108 reviewer,
109 bug)
110 111
111 print('Commit message:') 112 print('Commit message:')
112 print('\n'.join(' ' + i for i in msg.splitlines())) 113 print('\n'.join(' ' + i for i in msg.splitlines()))
113 deps_content = deps_content.replace(head, master) 114 deps_content = deps_content.replace(head, master)
114 with open(deps, 'wb') as f: 115 with open(deps, 'wb') as f:
115 f.write(deps_content) 116 f.write(deps_content)
116 check_call(['git', 'add', 'DEPS'], cwd=root) 117 check_call(['git', 'add', 'DEPS'], cwd=root)
117 check_call(['git', 'commit', '-m', msg], cwd=root) 118 check_call(['git', 'commit', '-m', msg], cwd=root)
118 print('') 119 print('')
119 if not reviewers: 120 if not reviewers:
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 153
153 except Error as e: 154 except Error as e:
154 sys.stderr.write('error: %s\n' % e) 155 sys.stderr.write('error: %s\n' % e)
155 return 1 156 return 1
156 157
157 return 0 158 return 0
158 159
159 160
160 if __name__ == '__main__': 161 if __name__ == '__main__':
161 sys.exit(main()) 162 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698