| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
| 7 | 7 |
| 8 """A git-command for integrating reviews on Rietveld and Gerrit.""" | 8 """A git-command for integrating reviews on Rietveld and Gerrit.""" |
| 9 | 9 |
| 10 from __future__ import print_function | 10 from __future__ import print_function |
| (...skipping 4259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4270 print('It will show up on %s in ~1 min, once it gets a Cr-Commit-Position ' | 4270 print('It will show up on %s in ~1 min, once it gets a Cr-Commit-Position ' |
| 4271 'footer.' % branch) | 4271 'footer.' % branch) |
| 4272 | 4272 |
| 4273 hook = POSTUPSTREAM_HOOK_PATTERN % cmd | 4273 hook = POSTUPSTREAM_HOOK_PATTERN % cmd |
| 4274 if os.path.isfile(hook): | 4274 if os.path.isfile(hook): |
| 4275 RunCommand([hook, merge_base], error_ok=True) | 4275 RunCommand([hook, merge_base], error_ok=True) |
| 4276 | 4276 |
| 4277 return 1 if killed else 0 | 4277 return 1 if killed else 0 |
| 4278 | 4278 |
| 4279 | 4279 |
| 4280 def WaitForRealCommit(remote, pushed_commit, local_base_ref, real_ref): | 4280 def _WaitForRealCommit(remote, pushed_commit, local_base_ref, real_ref): |
| 4281 print() | 4281 print() |
| 4282 print('Waiting for commit to be landed on %s...' % real_ref) | 4282 print('Waiting for commit to be landed on %s...' % real_ref) |
| 4283 print('(If you are impatient, you may Ctrl-C once without harm)') | 4283 print('(If you are impatient, you may Ctrl-C once without harm)') |
| 4284 target_tree = RunGit(['rev-parse', '%s:' % pushed_commit]).strip() | 4284 target_tree = RunGit(['rev-parse', '%s:' % pushed_commit]).strip() |
| 4285 current_rev = RunGit(['rev-parse', local_base_ref]).strip() | 4285 current_rev = RunGit(['rev-parse', local_base_ref]).strip() |
| 4286 mirror = settings.GetGitMirror(remote) | 4286 mirror = settings.GetGitMirror(remote) |
| 4287 | 4287 |
| 4288 loop = 0 | 4288 loop = 0 |
| 4289 while True: | 4289 while True: |
| 4290 sys.stdout.write('fetching (%d)... \r' % loop) | 4290 sys.stdout.write('fetching (%d)... \r' % loop) |
| 4291 sys.stdout.flush() | 4291 sys.stdout.flush() |
| 4292 loop += 1 | 4292 loop += 1 |
| 4293 | 4293 |
| 4294 if mirror: | 4294 if mirror: |
| 4295 mirror.populate() | 4295 mirror.populate() |
| 4296 RunGit(['retry', 'fetch', remote, real_ref], stderr=subprocess2.VOID) | 4296 RunGit(['retry', 'fetch', remote, real_ref], stderr=subprocess2.VOID) |
| 4297 to_rev = RunGit(['rev-parse', 'FETCH_HEAD']).strip() | 4297 to_rev = RunGit(['rev-parse', 'FETCH_HEAD']).strip() |
| 4298 commits = RunGit(['rev-list', '%s..%s' % (current_rev, to_rev)]) | 4298 commits = RunGit(['rev-list', '%s..%s' % (current_rev, to_rev)]) |
| 4299 for commit in commits.splitlines(): | 4299 for commit in commits.splitlines(): |
| 4300 if RunGit(['rev-parse', '%s:' % commit]).strip() == target_tree: | 4300 if RunGit(['rev-parse', '%s:' % commit]).strip() == target_tree: |
| 4301 print('Found commit on %s' % real_ref) | 4301 print('Found commit on %s' % real_ref) |
| 4302 return commit | 4302 return commit |
| 4303 | 4303 |
| 4304 current_rev = to_rev | 4304 current_rev = to_rev |
| 4305 | 4305 |
| 4306 | 4306 |
| 4307 def PushToGitPending(remote, pending_ref, upstream_ref): | 4307 def _PushToGitPending(remote, pending_ref, upstream_ref): |
| 4308 """Fetches pending_ref, cherry-picks current HEAD on top of it, pushes. | 4308 """Fetches pending_ref, cherry-picks current HEAD on top of it, pushes. |
| 4309 | 4309 |
| 4310 Returns: | 4310 Returns: |
| 4311 (retcode of last operation, output log of last operation). | 4311 (retcode of last operation, output log of last operation). |
| 4312 """ | 4312 """ |
| 4313 assert pending_ref.startswith('refs/'), pending_ref | 4313 assert pending_ref.startswith('refs/'), pending_ref |
| 4314 local_pending_ref = 'refs/git-cl/' + pending_ref[len('refs/'):] | 4314 local_pending_ref = 'refs/git-cl/' + pending_ref[len('refs/'):] |
| 4315 cherry = RunGit(['rev-parse', 'HEAD']).strip() | 4315 cherry = RunGit(['rev-parse', 'HEAD']).strip() |
| 4316 code = 0 | 4316 code = 0 |
| 4317 out = '' | 4317 out = '' |
| (...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5274 if __name__ == '__main__': | 5274 if __name__ == '__main__': |
| 5275 # These affect sys.stdout so do it outside of main() to simplify mocks in | 5275 # These affect sys.stdout so do it outside of main() to simplify mocks in |
| 5276 # unit testing. | 5276 # unit testing. |
| 5277 fix_encoding.fix_encoding() | 5277 fix_encoding.fix_encoding() |
| 5278 setup_color.init() | 5278 setup_color.init() |
| 5279 try: | 5279 try: |
| 5280 sys.exit(main(sys.argv[1:])) | 5280 sys.exit(main(sys.argv[1:])) |
| 5281 except KeyboardInterrupt: | 5281 except KeyboardInterrupt: |
| 5282 sys.stderr.write('interrupted\n') | 5282 sys.stderr.write('interrupted\n') |
| 5283 sys.exit(1) | 5283 sys.exit(1) |
| OLD | NEW |