| 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 | 
| 11 | 11 | 
| 12 from distutils.version import LooseVersion | 12 from distutils.version import LooseVersion | 
| 13 from multiprocessing.pool import ThreadPool | 13 from multiprocessing.pool import ThreadPool | 
| 14 import base64 | 14 import base64 | 
| 15 import collections | 15 import collections | 
| 16 import httplib | 16 import httplib | 
| 17 import json | 17 import json | 
| 18 import logging | 18 import logging | 
| 19 import multiprocessing | 19 import multiprocessing | 
| 20 import optparse | 20 import optparse | 
| 21 import os | 21 import os | 
| 22 import re | 22 import re | 
| 23 import stat | 23 import stat | 
| 24 import sys | 24 import sys | 
| 25 import textwrap | 25 import textwrap | 
| 26 import time |  | 
| 27 import traceback | 26 import traceback | 
| 28 import urllib | 27 import urllib | 
| 29 import urllib2 | 28 import urllib2 | 
| 30 import urlparse | 29 import urlparse | 
| 31 import uuid | 30 import uuid | 
| 32 import webbrowser | 31 import webbrowser | 
| 33 import zlib | 32 import zlib | 
| 34 | 33 | 
| 35 try: | 34 try: | 
| 36   import readline  # pylint: disable=F0401,W0611 | 35   import readline  # pylint: disable=F0401,W0611 | 
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 141       LooseVersion(version[len(prefix):]) >= LooseVersion(min_version)) | 140       LooseVersion(version[len(prefix):]) >= LooseVersion(min_version)) | 
| 142 | 141 | 
| 143 | 142 | 
| 144 def BranchExists(branch): | 143 def BranchExists(branch): | 
| 145   """Return True if specified branch exists.""" | 144   """Return True if specified branch exists.""" | 
| 146   code, _ = RunGitWithCode(['rev-parse', '--verify', branch], | 145   code, _ = RunGitWithCode(['rev-parse', '--verify', branch], | 
| 147                            suppress_stderr=True) | 146                            suppress_stderr=True) | 
| 148   return not code | 147   return not code | 
| 149 | 148 | 
| 150 | 149 | 
|  | 150 def time_sleep(seconds): | 
|  | 151   # Use this so that it can be mocked in tests without interfering with python | 
|  | 152   # system machinery. | 
|  | 153   import time  # Local import to discourage others from importing time globally. | 
|  | 154   return time.sleep(seconds) | 
|  | 155 | 
|  | 156 | 
| 151 def ask_for_data(prompt): | 157 def ask_for_data(prompt): | 
| 152   try: | 158   try: | 
| 153     return raw_input(prompt) | 159     return raw_input(prompt) | 
| 154   except KeyboardInterrupt: | 160   except KeyboardInterrupt: | 
| 155     # Hide the exception. | 161     # Hide the exception. | 
| 156     sys.exit(1) | 162     sys.exit(1) | 
| 157 | 163 | 
| 158 | 164 | 
| 159 def _git_branch_config_key(branch, key): | 165 def _git_branch_config_key(branch, key): | 
| 160   """Helper method to return Git config key for a branch.""" | 166   """Helper method to return Git config key for a branch.""" | 
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 306         raise BuildbucketResponseException( | 312         raise BuildbucketResponseException( | 
| 307             'Buildbucket returns invalid json content: %s.\n' | 313             'Buildbucket returns invalid json content: %s.\n' | 
| 308             'Please file bugs at http://crbug.com, label "Infra-BuildBucket".' % | 314             'Please file bugs at http://crbug.com, label "Infra-BuildBucket".' % | 
| 309             content) | 315             content) | 
| 310       return content_json | 316       return content_json | 
| 311     if response.status < 500 or try_count >= 2: | 317     if response.status < 500 or try_count >= 2: | 
| 312       raise httplib2.HttpLib2Error(content) | 318       raise httplib2.HttpLib2Error(content) | 
| 313 | 319 | 
| 314     # status >= 500 means transient failures. | 320     # status >= 500 means transient failures. | 
| 315     logging.debug('Transient errors when %s. Will retry.', operation_name) | 321     logging.debug('Transient errors when %s. Will retry.', operation_name) | 
| 316     time.sleep(0.5 + 1.5*try_count) | 322     time_sleep(0.5 + 1.5*try_count) | 
| 317     try_count += 1 | 323     try_count += 1 | 
| 318   assert False, 'unreachable' | 324   assert False, 'unreachable' | 
| 319 | 325 | 
| 320 | 326 | 
| 321 def _trigger_try_jobs(auth_config, changelist, masters, options, | 327 def _trigger_try_jobs(auth_config, changelist, masters, options, | 
| 322                       category='git_cl_try', patchset=None): | 328                       category='git_cl_try', patchset=None): | 
| 323   assert changelist.GetIssue(), 'CL must be uploaded first' | 329   assert changelist.GetIssue(), 'CL must be uploaded first' | 
| 324   codereview_url = changelist.GetCodereviewServer() | 330   codereview_url = changelist.GetCodereviewServer() | 
| 325   assert codereview_url, 'CL must be uploaded first' | 331   assert codereview_url, 'CL must be uploaded first' | 
| 326   patchset = patchset or changelist.GetMostRecentPatchset() | 332   patchset = patchset or changelist.GetMostRecentPatchset() | 
| (...skipping 5046 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 5373 if __name__ == '__main__': | 5379 if __name__ == '__main__': | 
| 5374   # These affect sys.stdout so do it outside of main() to simplify mocks in | 5380   # These affect sys.stdout so do it outside of main() to simplify mocks in | 
| 5375   # unit testing. | 5381   # unit testing. | 
| 5376   fix_encoding.fix_encoding() | 5382   fix_encoding.fix_encoding() | 
| 5377   setup_color.init() | 5383   setup_color.init() | 
| 5378   try: | 5384   try: | 
| 5379     sys.exit(main(sys.argv[1:])) | 5385     sys.exit(main(sys.argv[1:])) | 
| 5380   except KeyboardInterrupt: | 5386   except KeyboardInterrupt: | 
| 5381     sys.stderr.write('interrupted\n') | 5387     sys.stderr.write('interrupted\n') | 
| 5382     sys.exit(1) | 5388     sys.exit(1) | 
| OLD | NEW | 
|---|