Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: gclient_scm.py

Issue 2162583004: Revert "Remove all safesync_url functionality from gclient" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gclient.py ('k') | recipe_modules/bot_update/resources/bot_update.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12 matching lines...) Expand all
23 import shutil 23 import shutil
24 import subprocess2 24 import subprocess2
25 25
26 26
27 THIS_FILE_PATH = os.path.abspath(__file__) 27 THIS_FILE_PATH = os.path.abspath(__file__)
28 28
29 GSUTIL_DEFAULT_PATH = os.path.join( 29 GSUTIL_DEFAULT_PATH = os.path.join(
30 os.path.dirname(os.path.abspath(__file__)), 'gsutil.py') 30 os.path.dirname(os.path.abspath(__file__)), 'gsutil.py')
31 31
32 32
33 class NoUsableRevError(gclient_utils.Error):
34 """Raised if requested revision isn't found in checkout."""
35
36
33 class DiffFiltererWrapper(object): 37 class DiffFiltererWrapper(object):
34 """Simple base class which tracks which file is being diffed and 38 """Simple base class which tracks which file is being diffed and
35 replaces instances of its file name in the original and 39 replaces instances of its file name in the original and
36 working copy lines of the svn/git diff output.""" 40 working copy lines of the svn/git diff output."""
37 index_string = None 41 index_string = None
38 original_prefix = "--- " 42 original_prefix = "--- "
39 working_prefix = "+++ " 43 working_prefix = "+++ "
40 44
41 def __init__(self, relpath, print_func): 45 def __init__(self, relpath, print_func):
42 # Note that we always use '/' as the path separator to be 46 # Note that we always use '/' as the path separator to be
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 default_rev = "refs/heads/master" 746 default_rev = "refs/heads/master"
743 if options.upstream: 747 if options.upstream:
744 if self._GetCurrentBranch(): 748 if self._GetCurrentBranch():
745 upstream_branch = scm.GIT.GetUpstreamBranch(self.checkout_path) 749 upstream_branch = scm.GIT.GetUpstreamBranch(self.checkout_path)
746 default_rev = upstream_branch or default_rev 750 default_rev = upstream_branch or default_rev
747 _, deps_revision = gclient_utils.SplitUrlRevision(self.url) 751 _, deps_revision = gclient_utils.SplitUrlRevision(self.url)
748 if not deps_revision: 752 if not deps_revision:
749 deps_revision = default_rev 753 deps_revision = default_rev
750 if deps_revision.startswith('refs/heads/'): 754 if deps_revision.startswith('refs/heads/'):
751 deps_revision = deps_revision.replace('refs/heads/', self.remote + '/') 755 deps_revision = deps_revision.replace('refs/heads/', self.remote + '/')
752 if not scm.GIT.IsValidRevision(cwd=self.checkout_path, rev=deps_revision): 756 try:
753 # There's a chance we just don't have the corresponding object. 757 deps_revision = self.GetUsableRev(deps_revision, options)
754 self._Fetch(options) 758 except NoUsableRevError as e:
759 # If the DEPS entry's url and hash changed, try to update the origin.
760 # See also http://crbug.com/520067.
761 logging.warn(
762 'Couldn\'t find usable revision, will retrying to update instead: %s',
763 e.message)
764 return self.update(options, [], file_list)
755 765
756 if file_list is not None: 766 if file_list is not None:
757 files = self._Capture(['diff', deps_revision, '--name-only']).split() 767 files = self._Capture(['diff', deps_revision, '--name-only']).split()
758 768
759 self._Run(['reset', '--hard', deps_revision], options) 769 self._Run(['reset', '--hard', deps_revision], options)
760 self._Run(['clean', '-f', '-d'], options) 770 self._Run(['clean', '-f', '-d'], options)
761 771
762 if file_list is not None: 772 if file_list is not None:
763 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) 773 file_list.extend([os.path.join(self.checkout_path, f) for f in files])
764 774
(...skipping 10 matching lines...) Expand all
775 self.Print('________ couldn\'t run status in %s:\n' 785 self.Print('________ couldn\'t run status in %s:\n'
776 'The directory does not exist.' % self.checkout_path) 786 'The directory does not exist.' % self.checkout_path)
777 else: 787 else:
778 merge_base = self._Capture(['merge-base', 'HEAD', self.remote]) 788 merge_base = self._Capture(['merge-base', 'HEAD', self.remote])
779 self._Run(['diff', '--name-status', merge_base], options, 789 self._Run(['diff', '--name-status', merge_base], options,
780 stdout=self.out_fh) 790 stdout=self.out_fh)
781 if file_list is not None: 791 if file_list is not None:
782 files = self._Capture(['diff', '--name-only', merge_base]).split() 792 files = self._Capture(['diff', '--name-only', merge_base]).split()
783 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) 793 file_list.extend([os.path.join(self.checkout_path, f) for f in files])
784 794
795 def GetUsableRev(self, rev, options):
796 """Finds a useful revision for this repository.
797
798 If SCM is git-svn and the head revision is less than |rev|, git svn fetch
799 will be called on the source."""
800 sha1 = None
801 if not os.path.isdir(self.checkout_path):
802 raise NoUsableRevError(
803 ( 'We could not find a valid hash for safesync_url response "%s".\n'
804 'Safesync URLs with a git checkout currently require the repo to\n'
805 'be cloned without a safesync_url before adding the safesync_url.\n'
806 'For more info, see: '
807 'http://code.google.com/p/chromium/wiki/UsingNewGit'
808 '#Initial_checkout' ) % rev)
809 elif rev.isdigit() and len(rev) < 7:
810 # Handles an SVN rev. As an optimization, only verify an SVN revision as
811 # [0-9]{1,6} for now to avoid making a network request.
812 if scm.GIT.IsGitSvn(cwd=self.checkout_path):
813 local_head = scm.GIT.GetGitSvnHeadRev(cwd=self.checkout_path)
814 if not local_head or local_head < int(rev):
815 try:
816 logging.debug('Looking for git-svn configuration optimizations.')
817 if scm.GIT.Capture(['config', '--get', 'svn-remote.svn.fetch'],
818 cwd=self.checkout_path):
819 self._Fetch(options)
820 except subprocess2.CalledProcessError:
821 logging.debug('git config --get svn-remote.svn.fetch failed, '
822 'ignoring possible optimization.')
823 if options.verbose:
824 self.Print('Running git svn fetch. This might take a while.\n')
825 scm.GIT.Capture(['svn', 'fetch'], cwd=self.checkout_path)
826 try:
827 sha1 = scm.GIT.GetBlessedSha1ForSvnRev(
828 cwd=self.checkout_path, rev=rev)
829 except gclient_utils.Error, e:
830 sha1 = e.message
831 self.Print('Warning: Could not find a git revision with accurate\n'
832 '.DEPS.git that maps to SVN revision %s. Sync-ing to\n'
833 'the closest sane git revision, which is:\n'
834 ' %s\n' % (rev, e.message))
835 if not sha1:
836 raise NoUsableRevError(
837 ( 'It appears that either your git-svn remote is incorrectly\n'
838 'configured or the revision in your safesync_url is\n'
839 'higher than git-svn remote\'s HEAD as we couldn\'t find a\n'
840 'corresponding git hash for SVN rev %s.' ) % rev)
841 else:
842 if scm.GIT.IsValidRevision(cwd=self.checkout_path, rev=rev):
843 sha1 = rev
844 else:
845 # May exist in origin, but we don't have it yet, so fetch and look
846 # again.
847 self._Fetch(options)
848 if scm.GIT.IsValidRevision(cwd=self.checkout_path, rev=rev):
849 sha1 = rev
850
851 if not sha1:
852 raise NoUsableRevError(
853 ( 'We could not find a valid hash for safesync_url response "%s".\n'
854 'Safesync URLs with a git checkout currently require a git-svn\n'
855 'remote or a safesync_url that provides git sha1s. Please add a\n'
856 'git-svn remote or change your safesync_url. For more info, see:\n'
857 'http://code.google.com/p/chromium/wiki/UsingNewGit'
858 '#Initial_checkout' ) % rev)
859
860 return sha1
861
785 def FullUrlForRelativeUrl(self, url): 862 def FullUrlForRelativeUrl(self, url):
786 # Strip from last '/' 863 # Strip from last '/'
787 # Equivalent to unix basename 864 # Equivalent to unix basename
788 base_url = self.url 865 base_url = self.url
789 return base_url[:base_url.rfind('/')] + url 866 return base_url[:base_url.rfind('/')] + url
790 867
791 def GetGitBackupDirPath(self): 868 def GetGitBackupDirPath(self):
792 """Returns the path where the .git folder for the current project can be 869 """Returns the path where the .git folder for the current project can be
793 staged/restored. Use case: subproject moved from DEPS <-> outer project.""" 870 staged/restored. Use case: subproject moved from DEPS <-> outer project."""
794 return os.path.join(self._root_dir, 871 return os.path.join(self._root_dir,
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after
1579 command = ['status'] + args 1656 command = ['status'] + args
1580 if not os.path.isdir(self.checkout_path): 1657 if not os.path.isdir(self.checkout_path):
1581 # svn status won't work if the directory doesn't exist. 1658 # svn status won't work if the directory doesn't exist.
1582 self.Print(('\n________ couldn\'t run \'%s\' in \'%s\':\n' 1659 self.Print(('\n________ couldn\'t run \'%s\' in \'%s\':\n'
1583 'The directory does not exist.') % 1660 'The directory does not exist.') %
1584 (' '.join(command), self.checkout_path)) 1661 (' '.join(command), self.checkout_path))
1585 # There's no file list to retrieve. 1662 # There's no file list to retrieve.
1586 else: 1663 else:
1587 self._RunAndGetFileList(command, options, file_list) 1664 self._RunAndGetFileList(command, options, file_list)
1588 1665
1666 def GetUsableRev(self, rev, _options):
1667 """Verifies the validity of the revision for this repository."""
1668 if not scm.SVN.IsValidRevision(url='%s@%s' % (self.url, rev)):
1669 raise NoUsableRevError(
1670 ( '%s isn\'t a valid revision. Please check that your safesync_url is\n'
1671 'correct.') % rev)
1672 return rev
1673
1589 def FullUrlForRelativeUrl(self, url): 1674 def FullUrlForRelativeUrl(self, url):
1590 # Find the forth '/' and strip from there. A bit hackish. 1675 # Find the forth '/' and strip from there. A bit hackish.
1591 return '/'.join(self.url.split('/')[:4]) + url 1676 return '/'.join(self.url.split('/')[:4]) + url
1592 1677
1593 def _Run(self, args, options, **kwargs): 1678 def _Run(self, args, options, **kwargs):
1594 """Runs a commands that goes to stdout.""" 1679 """Runs a commands that goes to stdout."""
1595 kwargs.setdefault('cwd', self.checkout_path) 1680 kwargs.setdefault('cwd', self.checkout_path)
1596 gclient_utils.CheckCallAndFilterAndHeader(['svn'] + args, 1681 gclient_utils.CheckCallAndFilterAndHeader(['svn'] + args,
1597 always=options.verbose, **kwargs) 1682 always=options.verbose, **kwargs)
1598 1683
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1633 new_command.append('--force') 1718 new_command.append('--force')
1634 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1719 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1635 new_command.extend(('--accept', 'theirs-conflict')) 1720 new_command.extend(('--accept', 'theirs-conflict'))
1636 elif options.manually_grab_svn_rev: 1721 elif options.manually_grab_svn_rev:
1637 new_command.append('--force') 1722 new_command.append('--force')
1638 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1723 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1639 new_command.extend(('--accept', 'postpone')) 1724 new_command.extend(('--accept', 'postpone'))
1640 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1725 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1641 new_command.extend(('--accept', 'postpone')) 1726 new_command.extend(('--accept', 'postpone'))
1642 return new_command 1727 return new_command
OLDNEW
« no previous file with comments | « gclient.py ('k') | recipe_modules/bot_update/resources/bot_update.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698