| 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 from __future__ import print_function | 7 from __future__ import print_function |
| 8 | 8 |
| 9 import errno | 9 import errno |
| 10 import logging | 10 import logging |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 # always specify branches as they are in the upstream repo. | 382 # always specify branches as they are in the upstream repo. |
| 383 rev_type = "branch" | 383 rev_type = "branch" |
| 384 else: | 384 else: |
| 385 # hash is also a tag, only make a distinction at checkout | 385 # hash is also a tag, only make a distinction at checkout |
| 386 rev_type = "hash" | 386 rev_type = "hash" |
| 387 | 387 |
| 388 mirror = self._GetMirror(url, options) | 388 mirror = self._GetMirror(url, options) |
| 389 if mirror: | 389 if mirror: |
| 390 url = mirror.mirror_path | 390 url = mirror.mirror_path |
| 391 | 391 |
| 392 # If we are going to introduce a new project, there is a possibility that |
| 393 # we are syncing back to a state where the project was originally a |
| 394 # sub-project rolled by DEPS (realistic case: crossing the Blink merge point |
| 395 # syncing backwards, when Blink was a DEPS entry and not part of src.git). |
| 396 # In such case, we might have a backup of the former .git folder, which can |
| 397 # be used to avoid re-fetching the entire repo again (useful for bisects). |
| 398 backup_dir = self.GetGitBackupDirPath() |
| 399 target_dir = os.path.join(self.checkout_path, '.git') |
| 400 if os.path.exists(backup_dir) and not os.path.exists(target_dir): |
| 401 gclient_utils.safe_makedirs(self.checkout_path) |
| 402 os.rename(backup_dir, target_dir) |
| 403 # Reset to a clean state |
| 404 self._Run(['reset', '--hard', 'HEAD'], options) |
| 405 |
| 392 if (not os.path.exists(self.checkout_path) or | 406 if (not os.path.exists(self.checkout_path) or |
| 393 (os.path.isdir(self.checkout_path) and | 407 (os.path.isdir(self.checkout_path) and |
| 394 not os.path.exists(os.path.join(self.checkout_path, '.git')))): | 408 not os.path.exists(os.path.join(self.checkout_path, '.git')))): |
| 395 if mirror: | 409 if mirror: |
| 396 self._UpdateMirror(mirror, options) | 410 self._UpdateMirror(mirror, options) |
| 397 try: | 411 try: |
| 398 self._Clone(revision, url, options) | 412 self._Clone(revision, url, options) |
| 399 except subprocess2.CalledProcessError: | 413 except subprocess2.CalledProcessError: |
| 400 self._DeleteOrMove(options.force) | 414 self._DeleteOrMove(options.force) |
| 401 self._Clone(revision, url, options) | 415 self._Clone(revision, url, options) |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 '#Initial_checkout' ) % rev) | 806 '#Initial_checkout' ) % rev) |
| 793 | 807 |
| 794 return sha1 | 808 return sha1 |
| 795 | 809 |
| 796 def FullUrlForRelativeUrl(self, url): | 810 def FullUrlForRelativeUrl(self, url): |
| 797 # Strip from last '/' | 811 # Strip from last '/' |
| 798 # Equivalent to unix basename | 812 # Equivalent to unix basename |
| 799 base_url = self.url | 813 base_url = self.url |
| 800 return base_url[:base_url.rfind('/')] + url | 814 return base_url[:base_url.rfind('/')] + url |
| 801 | 815 |
| 816 def GetGitBackupDirPath(self): |
| 817 """Returns the path where the .git folder for the current project can be |
| 818 staged/restored. Use case: subproject moved from DEPS <-> outer project.""" |
| 819 return os.path.join(self._root_dir, |
| 820 'old_' + self.relpath.replace(os.sep, '_')) + '.git' |
| 821 |
| 802 def _GetMirror(self, url, options): | 822 def _GetMirror(self, url, options): |
| 803 """Get a git_cache.Mirror object for the argument url.""" | 823 """Get a git_cache.Mirror object for the argument url.""" |
| 804 if not git_cache.Mirror.GetCachePath(): | 824 if not git_cache.Mirror.GetCachePath(): |
| 805 return None | 825 return None |
| 806 mirror_kwargs = { | 826 mirror_kwargs = { |
| 807 'print_func': self.filter, | 827 'print_func': self.filter, |
| 808 'refs': [] | 828 'refs': [] |
| 809 } | 829 } |
| 810 # TODO(hinoka): This currently just fails because lkcr/lkgr are branches | 830 # TODO(hinoka): This currently just fails because lkcr/lkgr are branches |
| 811 # not tags. This also adds 20 seconds to every bot_update | 831 # not tags. This also adds 20 seconds to every bot_update |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1602 new_command.append('--force') | 1622 new_command.append('--force') |
| 1603 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1623 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1604 new_command.extend(('--accept', 'theirs-conflict')) | 1624 new_command.extend(('--accept', 'theirs-conflict')) |
| 1605 elif options.manually_grab_svn_rev: | 1625 elif options.manually_grab_svn_rev: |
| 1606 new_command.append('--force') | 1626 new_command.append('--force') |
| 1607 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1627 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1608 new_command.extend(('--accept', 'postpone')) | 1628 new_command.extend(('--accept', 'postpone')) |
| 1609 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1629 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1610 new_command.extend(('--accept', 'postpone')) | 1630 new_command.extend(('--accept', 'postpone')) |
| 1611 return new_command | 1631 return new_command |
| OLD | NEW |