Edward Lesmes | 7149d23 | 2019-08-12 21:04:04 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
maruel@chromium.org | 9655094 | 2015-05-22 18:46:51 +0000 | [diff] [blame] | 2 | # Copyright 2015 The Chromium Authors. All rights reserved. |
szager@chromium.org | 03fd85b | 2014-06-09 23:43:33 +0000 | [diff] [blame] | 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
maruel@chromium.org | 9655094 | 2015-05-22 18:46:51 +0000 | [diff] [blame] | 6 | """Rolls DEPS controlled dependency. |
szager@chromium.org | 03fd85b | 2014-06-09 23:43:33 +0000 | [diff] [blame] | 7 | |
sbc@chromium.org | 30e5b23 | 2015-06-01 18:06:59 +0000 | [diff] [blame] | 8 | Works only with git checkout and git dependencies. Currently this |
| 9 | script will always roll to the tip of to origin/master. |
szager@chromium.org | 03fd85b | 2014-06-09 23:43:33 +0000 | [diff] [blame] | 10 | """ |
| 11 | |
Raul Tambre | 80ee78e | 2019-05-06 22:41:05 +0000 | [diff] [blame] | 12 | from __future__ import print_function |
| 13 | |
sbc@chromium.org | 30e5b23 | 2015-06-01 18:06:59 +0000 | [diff] [blame] | 14 | import argparse |
szager@chromium.org | 03fd85b | 2014-06-09 23:43:33 +0000 | [diff] [blame] | 15 | import os |
| 16 | import re |
maruel@chromium.org | 9655094 | 2015-05-22 18:46:51 +0000 | [diff] [blame] | 17 | import subprocess |
szager@chromium.org | 03fd85b | 2014-06-09 23:43:33 +0000 | [diff] [blame] | 18 | import sys |
| 19 | |
scottmg@chromium.org | c20f470 | 2015-05-23 00:44:46 +0000 | [diff] [blame] | 20 | NEED_SHELL = sys.platform.startswith('win') |
Edward Lemur | faae42e | 2018-11-26 18:34:30 +0000 | [diff] [blame] | 21 | GCLIENT_PATH = os.path.join( |
| 22 | os.path.dirname(os.path.abspath(__file__)), 'gclient.py') |
scottmg@chromium.org | c20f470 | 2015-05-23 00:44:46 +0000 | [diff] [blame] | 23 | |
| 24 | |
Marc-Antoine Ruel | 1e2cb15 | 2019-04-17 17:32:52 +0000 | [diff] [blame] | 25 | # Commit subject that will be considered a roll. In the format generated by the |
| 26 | # git log used, so it's "<year>-<month>-<day> <author> <subject>" |
| 27 | _ROLL_SUBJECT = re.compile( |
| 28 | # Date |
| 29 | r'^\d\d\d\d-\d\d-\d\d ' |
| 30 | # Author |
| 31 | r'[^ ]+ ' |
| 32 | # Subject |
| 33 | r'(' |
| 34 | # Generated by |
| 35 | # https://skia.googlesource.com/buildbot/+/master/autoroll/go/repo_manager/deps_repo_manager.go |
| 36 | r'Roll [^ ]+ [a-f0-9]+\.\.[a-f0-9]+ \(\d+ commits\)' |
| 37 | r'|' |
| 38 | # Generated by |
| 39 | # https://chromium.googlesource.com/infra/infra/+/master/recipes/recipe_modules/recipe_autoroller/api.py |
| 40 | r'Roll recipe dependencies \(trivial\)\.' |
| 41 | r')$') |
| 42 | |
| 43 | |
sbc@chromium.org | e5d984b | 2015-05-29 22:09:39 +0000 | [diff] [blame] | 44 | class Error(Exception): |
| 45 | pass |
| 46 | |
| 47 | |
smut | 7036c4f | 2016-06-09 14:28:48 -0700 | [diff] [blame] | 48 | class AlreadyRolledError(Error): |
| 49 | pass |
| 50 | |
| 51 | |
scottmg@chromium.org | c20f470 | 2015-05-23 00:44:46 +0000 | [diff] [blame] | 52 | def check_output(*args, **kwargs): |
| 53 | """subprocess.check_output() passing shell=True on Windows for git.""" |
| 54 | kwargs.setdefault('shell', NEED_SHELL) |
Edward Lemur | 9ea51a5 | 2019-11-25 19:02:13 +0000 | [diff] [blame] | 55 | return subprocess.check_output(*args, **kwargs).decode('utf-8') |
scottmg@chromium.org | c20f470 | 2015-05-23 00:44:46 +0000 | [diff] [blame] | 56 | |
| 57 | |
| 58 | def check_call(*args, **kwargs): |
| 59 | """subprocess.check_call() passing shell=True on Windows for git.""" |
| 60 | kwargs.setdefault('shell', NEED_SHELL) |
| 61 | subprocess.check_call(*args, **kwargs) |
| 62 | |
| 63 | |
maruel@chromium.org | 9655094 | 2015-05-22 18:46:51 +0000 | [diff] [blame] | 64 | def is_pristine(root, merge_base='origin/master'): |
| 65 | """Returns True if a git checkout is pristine.""" |
| 66 | cmd = ['git', 'diff', '--ignore-submodules', merge_base] |
scottmg@chromium.org | c20f470 | 2015-05-23 00:44:46 +0000 | [diff] [blame] | 67 | return not (check_output(cmd, cwd=root).strip() or |
| 68 | check_output(cmd + ['--cached'], cwd=root).strip()) |
szager@chromium.org | 03fd85b | 2014-06-09 23:43:33 +0000 | [diff] [blame] | 69 | |
| 70 | |
maruel@chromium.org | 398ed34 | 2015-09-29 12:27:25 +0000 | [diff] [blame] | 71 | def get_log_url(upstream_url, head, master): |
| 72 | """Returns an URL to read logs via a Web UI if applicable.""" |
| 73 | if re.match(r'https://[^/]*\.googlesource\.com/', upstream_url): |
| 74 | # gitiles |
| 75 | return '%s/+log/%s..%s' % (upstream_url, head[:12], master[:12]) |
| 76 | if upstream_url.startswith('https://github.com/'): |
| 77 | upstream_url = upstream_url.rstrip('/') |
| 78 | if upstream_url.endswith('.git'): |
| 79 | upstream_url = upstream_url[:-len('.git')] |
| 80 | return '%s/compare/%s...%s' % (upstream_url, head[:12], master[:12]) |
| 81 | return None |
| 82 | |
| 83 | |
| 84 | def should_show_log(upstream_url): |
| 85 | """Returns True if a short log should be included in the tree.""" |
| 86 | # Skip logs for very active projects. |
Eric Boren | 07efc5a | 2017-08-28 09:13:20 -0400 | [diff] [blame] | 87 | if upstream_url.endswith('/v8/v8.git'): |
maruel@chromium.org | 398ed34 | 2015-09-29 12:27:25 +0000 | [diff] [blame] | 88 | return False |
| 89 | if 'webrtc' in upstream_url: |
| 90 | return False |
| 91 | return True |
| 92 | |
| 93 | |
Edward Lemur | faae42e | 2018-11-26 18:34:30 +0000 | [diff] [blame] | 94 | def gclient(args): |
| 95 | """Executes gclient with the given args and returns the stdout.""" |
| 96 | return check_output([sys.executable, GCLIENT_PATH] + args).strip() |
sbc@chromium.org | 9820112 | 2015-04-22 20:21:34 +0000 | [diff] [blame] | 97 | |
maruel@chromium.org | 9655094 | 2015-05-22 18:46:51 +0000 | [diff] [blame] | 98 | |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 99 | def generate_commit_message( |
| 100 | full_dir, dependency, head, roll_to, no_log, log_limit): |
| 101 | """Creates the commit message for this specific roll.""" |
Sylvain Defresne | ae2b962 | 2020-01-31 09:46:06 +0000 | [diff] [blame] | 102 | commit_range = '%s..%s' % (head, roll_to) |
| 103 | commit_range_for_header = '%s..%s' % (head[:9], roll_to[:9]) |
maruel@chromium.org | 398ed34 | 2015-09-29 12:27:25 +0000 | [diff] [blame] | 104 | upstream_url = check_output( |
| 105 | ['git', 'config', 'remote.origin.url'], cwd=full_dir).strip() |
| 106 | log_url = get_log_url(upstream_url, head, roll_to) |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 107 | cmd = ['git', 'log', commit_range, '--date=short', '--no-merges'] |
maruel@chromium.org | c6e39fe | 2015-09-23 13:45:52 +0000 | [diff] [blame] | 108 | logs = check_output( |
Sylvain Defresne | ae2b962 | 2020-01-31 09:46:06 +0000 | [diff] [blame] | 109 | # Args with '=' are automatically quoted. |
| 110 | cmd + ['--format=%ad %ae %s', '--'], |
Marc-Antoine Ruel | 51104fe | 2017-03-01 17:57:41 -0500 | [diff] [blame] | 111 | cwd=full_dir).rstrip() |
maruel@chromium.org | c6e39fe | 2015-09-23 13:45:52 +0000 | [diff] [blame] | 112 | logs = re.sub(r'(?m)^(\d\d\d\d-\d\d-\d\d [^@]+)@[^ ]+( .*)$', r'\1\2', logs) |
Marc-Antoine Ruel | 51104fe | 2017-03-01 17:57:41 -0500 | [diff] [blame] | 113 | lines = logs.splitlines() |
Marc-Antoine Ruel | 1e2cb15 | 2019-04-17 17:32:52 +0000 | [diff] [blame] | 114 | cleaned_lines = [l for l in lines if not _ROLL_SUBJECT.match(l)] |
Marc-Antoine Ruel | 51104fe | 2017-03-01 17:57:41 -0500 | [diff] [blame] | 115 | logs = '\n'.join(cleaned_lines) + '\n' |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 116 | |
Marc-Antoine Ruel | 51104fe | 2017-03-01 17:57:41 -0500 | [diff] [blame] | 117 | nb_commits = len(lines) |
| 118 | rolls = nb_commits - len(cleaned_lines) |
Marc-Antoine Ruel | 51104fe | 2017-03-01 17:57:41 -0500 | [diff] [blame] | 119 | header = 'Roll %s/ %s (%d commit%s%s)\n\n' % ( |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 120 | dependency, |
Sylvain Defresne | ae2b962 | 2020-01-31 09:46:06 +0000 | [diff] [blame] | 121 | commit_range_for_header, |
maruel@chromium.org | 398ed34 | 2015-09-29 12:27:25 +0000 | [diff] [blame] | 122 | nb_commits, |
Marc-Antoine Ruel | 51104fe | 2017-03-01 17:57:41 -0500 | [diff] [blame] | 123 | 's' if nb_commits > 1 else '', |
| 124 | ('; %s trivial rolls' % rolls) if rolls else '') |
maruel@chromium.org | 398ed34 | 2015-09-29 12:27:25 +0000 | [diff] [blame] | 125 | log_section = '' |
| 126 | if log_url: |
| 127 | log_section = log_url + '\n\n' |
johannkoenig@google.com | 64f2fc3 | 2015-10-07 19:11:17 +0000 | [diff] [blame] | 128 | log_section += '$ %s ' % ' '.join(cmd) |
| 129 | log_section += '--format=\'%ad %ae %s\'\n' |
Sylvain Defresne | 4ada8ab | 2020-01-31 17:22:56 +0000 | [diff] [blame] | 130 | log_section = log_section.replace(commit_range, commit_range_for_header) |
Eric Boren | 3be96a8 | 2017-09-29 10:07:46 -0400 | [diff] [blame] | 131 | # It is important that --no-log continues to work, as it is used by |
| 132 | # internal -> external rollers. Please do not remove or break it. |
maruel@chromium.org | 398ed34 | 2015-09-29 12:27:25 +0000 | [diff] [blame] | 133 | if not no_log and should_show_log(upstream_url): |
Marc-Antoine Ruel | 51104fe | 2017-03-01 17:57:41 -0500 | [diff] [blame] | 134 | if len(cleaned_lines) > log_limit: |
Marc-Antoine Ruel | 6ce1822 | 2019-01-16 21:36:36 +0000 | [diff] [blame] | 135 | # Keep the first N/2 log entries and last N/2 entries. |
| 136 | lines = logs.splitlines(True) |
Edward Lesmes | 994bed5 | 2020-04-01 16:21:40 +0000 | [diff] [blame] | 137 | lines = lines[:log_limit//2] + ['(...)\n'] + lines[-log_limit//2:] |
Marc-Antoine Ruel | 6ce1822 | 2019-01-16 21:36:36 +0000 | [diff] [blame] | 138 | logs = ''.join(lines) |
maruel@chromium.org | 398ed34 | 2015-09-29 12:27:25 +0000 | [diff] [blame] | 139 | log_section += logs |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 140 | return header + log_section |
maruel@chromium.org | 398ed34 | 2015-09-29 12:27:25 +0000 | [diff] [blame] | 141 | |
maruel@chromium.org | 9655094 | 2015-05-22 18:46:51 +0000 | [diff] [blame] | 142 | |
Edward Lemur | faae42e | 2018-11-26 18:34:30 +0000 | [diff] [blame] | 143 | def calculate_roll(full_dir, dependency, roll_to): |
Edward Lesmes | c772cf7 | 2018-04-03 14:47:30 -0400 | [diff] [blame] | 144 | """Calculates the roll for a dependency by processing gclient_dict, and |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 145 | fetching the dependency via git. |
| 146 | """ |
Edward Lemur | faae42e | 2018-11-26 18:34:30 +0000 | [diff] [blame] | 147 | head = gclient(['getdep', '-r', dependency]) |
Edward Lesmes | c772cf7 | 2018-04-03 14:47:30 -0400 | [diff] [blame] | 148 | if not head: |
| 149 | raise Error('%s is unpinned.' % dependency) |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 150 | check_call(['git', 'fetch', 'origin', '--quiet'], cwd=full_dir) |
| 151 | roll_to = check_output(['git', 'rev-parse', roll_to], cwd=full_dir).strip() |
| 152 | return head, roll_to |
| 153 | |
| 154 | |
Robert Iannucci | c1e6594 | 2018-10-18 17:59:45 +0000 | [diff] [blame] | 155 | def gen_commit_msg(logs, cmdline, reviewers, bug): |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 156 | """Returns the final commit message.""" |
| 157 | commit_msg = '' |
| 158 | if len(logs) > 1: |
| 159 | commit_msg = 'Rolling %d dependencies\n\n' % len(logs) |
| 160 | commit_msg += '\n\n'.join(logs) |
Kenneth Russell | ebe839b | 2017-12-22 14:55:39 -0800 | [diff] [blame] | 161 | commit_msg += '\nCreated with:\n ' + cmdline + '\n' |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 162 | commit_msg += 'R=%s\n' % ','.join(reviewers) if reviewers else '' |
Robert Iannucci | c1e6594 | 2018-10-18 17:59:45 +0000 | [diff] [blame] | 163 | commit_msg += '\nBug: %s\n' % bug if bug else '' |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 164 | return commit_msg |
| 165 | |
| 166 | |
Edward Lemur | faae42e | 2018-11-26 18:34:30 +0000 | [diff] [blame] | 167 | def finalize(commit_msg, current_dir, rolls): |
| 168 | """Commits changes to the DEPS file, then uploads a CL.""" |
maruel@chromium.org | 9655094 | 2015-05-22 18:46:51 +0000 | [diff] [blame] | 169 | print('Commit message:') |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 170 | print('\n'.join(' ' + i for i in commit_msg.splitlines())) |
| 171 | |
Edward Lesmes | 3f277fc | 2018-04-06 15:32:51 -0400 | [diff] [blame] | 172 | check_call(['git', 'add', 'DEPS'], cwd=current_dir) |
| 173 | check_call(['git', 'commit', '--quiet', '-m', commit_msg], cwd=current_dir) |
maruel@chromium.org | 398ed34 | 2015-09-29 12:27:25 +0000 | [diff] [blame] | 174 | |
| 175 | # Pull the dependency to the right revision. This is surprising to users |
| 176 | # otherwise. |
Marc-Antoine Ruel | 8e57b4b | 2019-10-11 01:01:36 +0000 | [diff] [blame] | 177 | for _head, roll_to, full_dir in sorted(rolls.values()): |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 178 | check_call(['git', 'checkout', '--quiet', roll_to], cwd=full_dir) |
szager@chromium.org | 03fd85b | 2014-06-09 23:43:33 +0000 | [diff] [blame] | 179 | |
| 180 | |
maruel@chromium.org | 9655094 | 2015-05-22 18:46:51 +0000 | [diff] [blame] | 181 | def main(): |
sbc@chromium.org | 30e5b23 | 2015-06-01 18:06:59 +0000 | [diff] [blame] | 182 | parser = argparse.ArgumentParser(description=__doc__) |
maruel@chromium.org | 398ed34 | 2015-09-29 12:27:25 +0000 | [diff] [blame] | 183 | parser.add_argument( |
smut@google.com | 02d2087 | 2015-11-14 00:46:41 +0000 | [diff] [blame] | 184 | '--ignore-dirty-tree', action='store_true', |
| 185 | help='Roll anyways, even if there is a diff.') |
| 186 | parser.add_argument( |
maruel@chromium.org | 398ed34 | 2015-09-29 12:27:25 +0000 | [diff] [blame] | 187 | '-r', '--reviewer', |
maruel@chromium.org | 9655094 | 2015-05-22 18:46:51 +0000 | [diff] [blame] | 188 | help='To specify multiple reviewers, use comma separated list, e.g. ' |
scottmg@chromium.org | c20f470 | 2015-05-23 00:44:46 +0000 | [diff] [blame] | 189 | '-r joe,jane,john. Defaults to @chromium.org') |
maruel@chromium.org | 398ed34 | 2015-09-29 12:27:25 +0000 | [diff] [blame] | 190 | parser.add_argument('-b', '--bug', help='Associate a bug number to the roll') |
Eric Boren | 3be96a8 | 2017-09-29 10:07:46 -0400 | [diff] [blame] | 191 | # It is important that --no-log continues to work, as it is used by |
| 192 | # internal -> external rollers. Please do not remove or break it. |
maruel@chromium.org | 398ed34 | 2015-09-29 12:27:25 +0000 | [diff] [blame] | 193 | parser.add_argument( |
| 194 | '--no-log', action='store_true', |
| 195 | help='Do not include the short log in the commit message') |
| 196 | parser.add_argument( |
| 197 | '--log-limit', type=int, default=100, |
| 198 | help='Trim log after N commits (default: %(default)s)') |
| 199 | parser.add_argument( |
| 200 | '--roll-to', default='origin/master', |
| 201 | help='Specify the new commit to roll to (default: %(default)s)') |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 202 | parser.add_argument( |
| 203 | '--key', action='append', default=[], |
| 204 | help='Regex(es) for dependency in DEPS file') |
| 205 | parser.add_argument('dep_path', nargs='+', help='Path(s) to dependency') |
sbc@chromium.org | 30e5b23 | 2015-06-01 18:06:59 +0000 | [diff] [blame] | 206 | args = parser.parse_args() |
maruel@chromium.org | 9655094 | 2015-05-22 18:46:51 +0000 | [diff] [blame] | 207 | |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 208 | if len(args.dep_path) > 1: |
| 209 | if args.roll_to != 'origin/master': |
| 210 | parser.error( |
| 211 | 'Can\'t use multiple paths to roll simultaneously and --roll-to') |
| 212 | if args.key: |
| 213 | parser.error( |
| 214 | 'Can\'t use multiple paths to roll simultaneously and --key') |
maruel@chromium.org | 9655094 | 2015-05-22 18:46:51 +0000 | [diff] [blame] | 215 | reviewers = None |
sbc@chromium.org | 30e5b23 | 2015-06-01 18:06:59 +0000 | [diff] [blame] | 216 | if args.reviewer: |
| 217 | reviewers = args.reviewer.split(',') |
maruel@chromium.org | 9655094 | 2015-05-22 18:46:51 +0000 | [diff] [blame] | 218 | for i, r in enumerate(reviewers): |
| 219 | if not '@' in r: |
| 220 | reviewers[i] = r + '@chromium.org' |
| 221 | |
Edward Lemur | faae42e | 2018-11-26 18:34:30 +0000 | [diff] [blame] | 222 | gclient_root = gclient(['root']) |
Edward Lesmes | 3f277fc | 2018-04-06 15:32:51 -0400 | [diff] [blame] | 223 | current_dir = os.getcwd() |
Bruce Dawson | 37b62e5 | 2020-06-23 18:06:00 +0000 | [diff] [blame^] | 224 | dependencies = sorted(d.replace('\\', '/').rstrip('/') for d in args.dep_path) |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 225 | cmdline = 'roll-dep ' + ' '.join(dependencies) + ''.join( |
| 226 | ' --key ' + k for k in args.key) |
sbc@chromium.org | e5d984b | 2015-05-29 22:09:39 +0000 | [diff] [blame] | 227 | try: |
Edward Lesmes | 3f277fc | 2018-04-06 15:32:51 -0400 | [diff] [blame] | 228 | if not args.ignore_dirty_tree and not is_pristine(current_dir): |
| 229 | raise Error( |
| 230 | 'Ensure %s is clean first (no non-merged commits).' % current_dir) |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 231 | # First gather all the information without modifying anything, except for a |
| 232 | # git fetch. |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 233 | rolls = {} |
| 234 | for dependency in dependencies: |
Edward Lemur | faae42e | 2018-11-26 18:34:30 +0000 | [diff] [blame] | 235 | full_dir = os.path.normpath(os.path.join(gclient_root, dependency)) |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 236 | if not os.path.isdir(full_dir): |
Edward Lemur | faae42e | 2018-11-26 18:34:30 +0000 | [diff] [blame] | 237 | print('Dependency %s not found at %s' % (dependency, full_dir)) |
| 238 | full_dir = os.path.normpath(os.path.join(current_dir, dependency)) |
| 239 | print('Will look for relative dependency at %s' % full_dir) |
| 240 | if not os.path.isdir(full_dir): |
| 241 | raise Error('Directory not found: %s (%s)' % (dependency, full_dir)) |
| 242 | |
| 243 | head, roll_to = calculate_roll(full_dir, dependency, args.roll_to) |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 244 | if roll_to == head: |
| 245 | if len(dependencies) == 1: |
| 246 | raise AlreadyRolledError('No revision to roll!') |
| 247 | print('%s: Already at latest commit %s' % (dependency, roll_to)) |
| 248 | else: |
| 249 | print( |
| 250 | '%s: Rolling from %s to %s' % (dependency, head[:10], roll_to[:10])) |
Edward Lemur | faae42e | 2018-11-26 18:34:30 +0000 | [diff] [blame] | 251 | rolls[dependency] = (head, roll_to, full_dir) |
sbc@chromium.org | e5d984b | 2015-05-29 22:09:39 +0000 | [diff] [blame] | 252 | |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 253 | logs = [] |
Edward Lemur | faae42e | 2018-11-26 18:34:30 +0000 | [diff] [blame] | 254 | setdep_args = [] |
Marc-Antoine Ruel | 8e57b4b | 2019-10-11 01:01:36 +0000 | [diff] [blame] | 255 | for dependency, (head, roll_to, full_dir) in sorted(rolls.items()): |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 256 | log = generate_commit_message( |
| 257 | full_dir, dependency, head, roll_to, args.no_log, args.log_limit) |
| 258 | logs.append(log) |
Edward Lemur | faae42e | 2018-11-26 18:34:30 +0000 | [diff] [blame] | 259 | setdep_args.extend(['-r', '{}@{}'.format(dependency, roll_to)]) |
Edward Lesmes | c772cf7 | 2018-04-03 14:47:30 -0400 | [diff] [blame] | 260 | |
Edward Lemur | faae42e | 2018-11-26 18:34:30 +0000 | [diff] [blame] | 261 | gclient(['setdep'] + setdep_args) |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 262 | |
Robert Iannucci | c1e6594 | 2018-10-18 17:59:45 +0000 | [diff] [blame] | 263 | commit_msg = gen_commit_msg(logs, cmdline, reviewers, args.bug) |
Edward Lemur | faae42e | 2018-11-26 18:34:30 +0000 | [diff] [blame] | 264 | finalize(commit_msg, current_dir, rolls) |
sbc@chromium.org | e5d984b | 2015-05-29 22:09:39 +0000 | [diff] [blame] | 265 | except Error as e: |
| 266 | sys.stderr.write('error: %s\n' % e) |
smut | 7036c4f | 2016-06-09 14:28:48 -0700 | [diff] [blame] | 267 | return 2 if isinstance(e, AlreadyRolledError) else 1 |
Edward Lemur | 3c11794 | 2020-03-12 17:21:12 +0000 | [diff] [blame] | 268 | except subprocess.CalledProcessError: |
| 269 | return 1 |
sbc@chromium.org | e5d984b | 2015-05-29 22:09:39 +0000 | [diff] [blame] | 270 | |
Marc-Antoine Ruel | 85a8c10 | 2017-12-12 15:42:25 -0500 | [diff] [blame] | 271 | print('') |
| 272 | if not reviewers: |
| 273 | print('You forgot to pass -r, make sure to insert a R=foo@example.com line') |
| 274 | print('to the commit description before emailing.') |
| 275 | print('') |
| 276 | print('Run:') |
| 277 | print(' git cl upload --send-mail') |
sbc@chromium.org | e5d984b | 2015-05-29 22:09:39 +0000 | [diff] [blame] | 278 | return 0 |
szager@chromium.org | 03fd85b | 2014-06-09 23:43:33 +0000 | [diff] [blame] | 279 | |
sbc@chromium.org | 9820112 | 2015-04-22 20:21:34 +0000 | [diff] [blame] | 280 | |
szager@chromium.org | 03fd85b | 2014-06-09 23:43:33 +0000 | [diff] [blame] | 281 | if __name__ == '__main__': |
maruel@chromium.org | 9655094 | 2015-05-22 18:46:51 +0000 | [diff] [blame] | 282 | sys.exit(main()) |