| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Gclient-specific SCM-specific operations.""" | 5 """Gclient-specific SCM-specific operations.""" |
| 6 | 6 |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import posixpath | 9 import posixpath |
| 10 import re | 10 import re |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 rev_str = ' at %s' % revision | 287 rev_str = ' at %s' % revision |
| 288 files = [] | 288 files = [] |
| 289 | 289 |
| 290 printed_path = False | 290 printed_path = False |
| 291 verbose = [] | 291 verbose = [] |
| 292 if options.verbose: | 292 if options.verbose: |
| 293 print('\n_____ %s%s' % (self.relpath, rev_str)) | 293 print('\n_____ %s%s' % (self.relpath, rev_str)) |
| 294 verbose = ['--verbose'] | 294 verbose = ['--verbose'] |
| 295 printed_path = True | 295 printed_path = True |
| 296 | 296 |
| 297 if revision.startswith('refs/heads/'): | 297 if revision.startswith('refs/'): |
| 298 rev_type = "branch" | 298 rev_type = "branch" |
| 299 elif revision.startswith('origin/'): | 299 elif revision.startswith('origin/'): |
| 300 # For compatability with old naming, translate 'origin' to 'refs/heads' | 300 # For compatability with old naming, translate 'origin' to 'refs/heads' |
| 301 revision = revision.replace('origin/', 'refs/heads/') | 301 revision = revision.replace('origin/', 'refs/heads/') |
| 302 rev_type = "branch" | 302 rev_type = "branch" |
| 303 else: | 303 else: |
| 304 # hash is also a tag, only make a distinction at checkout | 304 # hash is also a tag, only make a distinction at checkout |
| 305 rev_type = "hash" | 305 rev_type = "hash" |
| 306 | 306 |
| 307 if not os.path.exists(self.checkout_path) or ( | 307 if not os.path.exists(self.checkout_path) or ( |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 upstream_branch = scm.GIT.GetUpstreamBranch(self.checkout_path) | 395 upstream_branch = scm.GIT.GetUpstreamBranch(self.checkout_path) |
| 396 if not upstream_branch or not upstream_branch.startswith('refs/remotes'): | 396 if not upstream_branch or not upstream_branch.startswith('refs/remotes'): |
| 397 current_type = "hash" | 397 current_type = "hash" |
| 398 logging.debug("Current branch is not tracking an upstream (remote)" | 398 logging.debug("Current branch is not tracking an upstream (remote)" |
| 399 " branch.") | 399 " branch.") |
| 400 elif upstream_branch.startswith('refs/remotes'): | 400 elif upstream_branch.startswith('refs/remotes'): |
| 401 current_type = "branch" | 401 current_type = "branch" |
| 402 else: | 402 else: |
| 403 raise gclient_utils.Error('Invalid Upstream: %s' % upstream_branch) | 403 raise gclient_utils.Error('Invalid Upstream: %s' % upstream_branch) |
| 404 | 404 |
| 405 if (not re.match(r'^[0-9a-fA-F]{40}$', revision) or | 405 if not scm.GIT.IsValidRevision(self.checkout_path, revision, sha_only=True): |
| 406 not scm.GIT.IsValidRevision(cwd=self.checkout_path, rev=revision)): | |
| 407 # Update the remotes first so we have all the refs. | 406 # Update the remotes first so we have all the refs. |
| 408 backoff_time = 5 | 407 remote_output = scm.GIT.Capture(['remote'] + verbose + ['update'], |
| 409 for _ in range(10): | |
| 410 try: | |
| 411 remote_output = scm.GIT.Capture( | |
| 412 ['remote'] + verbose + ['update'], | |
| 413 cwd=self.checkout_path) | 408 cwd=self.checkout_path) |
| 414 break | |
| 415 except subprocess2.CalledProcessError, e: | |
| 416 # Hackish but at that point, git is known to work so just checking for | |
| 417 # 502 in stderr should be fine. | |
| 418 if '502' in e.stderr: | |
| 419 print(str(e)) | |
| 420 print('Sleeping %.1f seconds and retrying...' % backoff_time) | |
| 421 time.sleep(backoff_time) | |
| 422 backoff_time *= 1.3 | |
| 423 continue | |
| 424 raise | |
| 425 | |
| 426 if verbose: | 409 if verbose: |
| 427 print(remote_output.strip()) | 410 print(remote_output) |
| 428 | 411 |
| 429 self._UpdateBranchHeads(options, fetch=True) | 412 self._UpdateBranchHeads(options, fetch=True) |
| 430 | 413 |
| 431 # This is a big hammer, debatable if it should even be here... | 414 # This is a big hammer, debatable if it should even be here... |
| 432 if options.force or options.reset: | 415 if options.force or options.reset: |
| 433 target = 'HEAD' | 416 target = 'HEAD' |
| 434 if options.upstream and upstream_branch: | 417 if options.upstream and upstream_branch: |
| 435 target = upstream_branch | 418 target = upstream_branch |
| 436 self._Run(['reset', '--hard', target], options) | 419 self._Run(['reset', '--hard', target], options) |
| 437 | 420 |
| (...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1336 new_command.append('--force') | 1319 new_command.append('--force') |
| 1337 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1320 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1338 new_command.extend(('--accept', 'theirs-conflict')) | 1321 new_command.extend(('--accept', 'theirs-conflict')) |
| 1339 elif options.manually_grab_svn_rev: | 1322 elif options.manually_grab_svn_rev: |
| 1340 new_command.append('--force') | 1323 new_command.append('--force') |
| 1341 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1324 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1342 new_command.extend(('--accept', 'postpone')) | 1325 new_command.extend(('--accept', 'postpone')) |
| 1343 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1326 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1344 new_command.extend(('--accept', 'postpone')) | 1327 new_command.extend(('--accept', 'postpone')) |
| 1345 return new_command | 1328 return new_command |
| OLD | NEW |