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