OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 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 """Generate a CL to roll a DEPS entry to the specified revision number and post | 6 """Generate a CL to roll a DEPS entry to the specified revision number and post |
7 it to Rietveld so that the CL will land automatically if it passes the | 7 it to Rietveld so that the CL will land automatically if it passes the |
8 commit-queue's checks. | 8 commit-queue's checks. |
9 """ | 9 """ |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... | |
38 new_content = re.sub(old_line, new_line, content, 1) | 38 new_content = re.sub(old_line, new_line, content, 1) |
39 old_rev = re.search(old_line, content).group(2) | 39 old_rev = re.search(old_line, content).group(2) |
40 if not old_rev or new_content == content: | 40 if not old_rev or new_content == content: |
41 die_with_error('Failed to update the DEPS file') | 41 die_with_error('Failed to update the DEPS file') |
42 | 42 |
43 if not is_dry_run: | 43 if not is_dry_run: |
44 open(path, 'w').write(new_content) | 44 open(path, 'w').write(new_content) |
45 return old_rev | 45 return old_rev |
46 | 46 |
47 | 47 |
48 class PrintSubprocess(object): | |
49 """Wrapper for subprocess2 which prints out every command.""" | |
50 def __getattr__(self, attr): | |
51 def _run_subprocess2(cmd, *args, **kwargs): | |
52 print cmd | |
M-A Ruel
2014/05/02 16:34:41
you'll want to sys.stdout.flush()
borenet
2014/05/02 19:51:15
Done.
| |
53 return getattr(subprocess2, attr)(cmd, *args, **kwargs) | |
54 return _run_subprocess2 | |
55 | |
56 prnt_subprocess = PrintSubprocess() | |
57 | |
58 | |
48 def main(): | 59 def main(): |
49 tool_dir = os.path.dirname(os.path.abspath(__file__)) | 60 tool_dir = os.path.dirname(os.path.abspath(__file__)) |
50 parser = optparse.OptionParser(usage='%prog [options] <project> <new rev>', | 61 parser = optparse.OptionParser(usage='%prog [options] <project> <new rev>', |
51 description=sys.modules[__name__].__doc__) | 62 description=sys.modules[__name__].__doc__) |
52 parser.add_option('-v', '--verbose', action='count', default=0) | 63 parser.add_option('-v', '--verbose', action='count', default=0) |
53 parser.add_option('--dry-run', action='store_true') | 64 parser.add_option('--dry-run', action='store_true') |
54 parser.add_option('-f', '--force', action='store_true', | 65 parser.add_option('-f', '--force', action='store_true', |
55 help='Make destructive changes to the local checkout if ' | 66 help='Make destructive changes to the local checkout if ' |
56 'necessary.') | 67 'necessary.') |
57 parser.add_option('--commit', action='store_true', default=True, | 68 parser.add_option('--commit', action='store_true', default=True, |
(...skipping 22 matching lines...) Expand all Loading... | |
80 root_dir = os.path.dirname(tool_dir) | 91 root_dir = os.path.dirname(tool_dir) |
81 os.chdir(root_dir) | 92 os.chdir(root_dir) |
82 | 93 |
83 project = args[0] | 94 project = args[0] |
84 new_rev = int(args[1]) | 95 new_rev = int(args[1]) |
85 | 96 |
86 # Silence the editor. | 97 # Silence the editor. |
87 os.environ['EDITOR'] = 'true' | 98 os.environ['EDITOR'] = 'true' |
88 | 99 |
89 if options.force and not options.dry_run: | 100 if options.force and not options.dry_run: |
90 subprocess2.check_call(['git', 'clean', '-d', '-f']) | 101 prnt_subprocess.check_call(['git', 'clean', '-d', '-f']) |
91 subprocess2.call(['git', 'rebase', '--abort']) | 102 prnt_subprocess.call(['git', 'rebase', '--abort']) |
92 | 103 |
93 old_branch = scm.GIT.GetBranch(root_dir) | 104 old_branch = scm.GIT.GetBranch(root_dir) |
94 new_branch = '%s_roll' % project | 105 new_branch = '%s_roll' % project |
95 | 106 |
96 if options.upstream == new_branch: | 107 if options.upstream == new_branch: |
97 parser.error('Cannot set %s as its own upstream.' % new_branch) | 108 parser.error('Cannot set %s as its own upstream.' % new_branch) |
98 | 109 |
99 if old_branch == new_branch: | 110 if old_branch == new_branch: |
100 if options.force: | 111 if options.force: |
101 if not options.dry_run: | 112 if not options.dry_run: |
102 subprocess2.check_call(['git', 'checkout', options.upstream, '-f']) | 113 prnt_subprocess.check_call(['git', 'checkout', options.upstream, '-f']) |
103 subprocess2.call(['git', 'branch', '-D', old_branch]) | 114 prnt_subprocess.call(['git', 'branch', '-D', old_branch]) |
104 else: | 115 else: |
105 parser.error('Please delete the branch %s and move to a different branch' | 116 parser.error('Please delete the branch %s and move to a different branch' |
106 % new_branch) | 117 % new_branch) |
107 | 118 |
108 if not options.dry_run: | 119 if not options.dry_run: |
109 subprocess2.check_call(['git', 'fetch', 'origin']) | 120 prnt_subprocess.check_call(['git', 'fetch', 'origin']) |
110 subprocess2.call(['git', 'svn', 'fetch']) | 121 prnt_subprocess.call(['git', 'svn', 'fetch']) |
111 branch_cmd = ['git', 'checkout', '-b', new_branch, options.upstream] | 122 branch_cmd = ['git', 'checkout', '-b', new_branch, options.upstream] |
112 if options.force: | 123 if options.force: |
113 branch_cmd.append('-f') | 124 branch_cmd.append('-f') |
114 subprocess2.check_output(branch_cmd) | 125 prnt_subprocess.check_output(branch_cmd) |
115 | 126 |
116 try: | 127 try: |
117 old_rev = int(process_deps(os.path.join(root_dir, 'DEPS'), project, new_rev, | 128 old_rev = int(process_deps(os.path.join(root_dir, 'DEPS'), project, new_rev, |
118 options.dry_run)) | 129 options.dry_run)) |
119 print '%s roll %s:%s' % (project.title(), old_rev, new_rev) | 130 print '%s roll %s:%s' % (project.title(), old_rev, new_rev) |
120 | 131 |
121 review_field = 'TBR' if options.commit else 'R' | 132 review_field = 'TBR' if options.commit else 'R' |
122 commit_msg = options.message or '%s roll %s:%s\n' % (project.title(), | 133 commit_msg = options.message or '%s roll %s:%s\n' % (project.title(), |
123 old_rev, new_rev) | 134 old_rev, new_rev) |
124 commit_msg += '\n%s=%s\n' % (review_field, options.reviewers) | 135 commit_msg += '\n%s=%s\n' % (review_field, options.reviewers) |
125 | 136 |
126 if options.dry_run: | 137 if options.dry_run: |
127 print 'Commit message: ' + commit_msg | 138 print 'Commit message: ' + commit_msg |
128 return 0 | 139 return 0 |
129 | 140 |
130 subprocess2.check_output(['git', 'commit', '-m', commit_msg, 'DEPS']) | 141 prnt_subprocess.check_output(['git', 'commit', '-m', commit_msg, 'DEPS']) |
131 subprocess2.check_call(['git', 'diff', '--no-ext-diff', options.upstream]) | 142 prnt_subprocess.check_call(['git', 'diff', '--no-ext-diff', |
143 options.upstream]) | |
132 upload_cmd = ['git', 'cl', 'upload'] | 144 upload_cmd = ['git', 'cl', 'upload'] |
133 if options.commit: | 145 if options.commit: |
134 upload_cmd.append('--use-commit-queue') | 146 upload_cmd.append('--use-commit-queue') |
135 if options.reviewers: | 147 if options.reviewers: |
136 upload_cmd.append('--send-mail') | 148 upload_cmd.append('--send-mail') |
137 if options.cc: | 149 if options.cc: |
138 upload_cmd.extend(['--cc', options.cc]) | 150 upload_cmd.extend(['--cc', options.cc]) |
139 subprocess2.check_call(upload_cmd) | 151 prnt_subprocess.check_call(upload_cmd) |
140 finally: | 152 finally: |
141 if not options.dry_run: | 153 if not options.dry_run: |
142 subprocess2.check_output(['git', 'checkout', old_branch]) | 154 prnt_subprocess.check_output(['git', 'checkout', old_branch]) |
143 subprocess2.check_output(['git', 'branch', '-D', new_branch]) | 155 prnt_subprocess.check_output(['git', 'branch', '-D', new_branch]) |
144 return 0 | 156 return 0 |
145 | 157 |
146 | 158 |
147 if __name__ == '__main__': | 159 if __name__ == '__main__': |
148 sys.exit(main()) | 160 sys.exit(main()) |
OLD | NEW |