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

Side by Side Diff: gclient_scm.py

Issue 1283083003: Make gclient revert work with DEPS when DEPS url changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: and svn Created 5 years, 4 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 | « no previous file | no next file » | 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 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 default_rev = "refs/heads/master" 714 default_rev = "refs/heads/master"
711 if options.upstream: 715 if options.upstream:
712 if self._GetCurrentBranch(): 716 if self._GetCurrentBranch():
713 upstream_branch = scm.GIT.GetUpstreamBranch(self.checkout_path) 717 upstream_branch = scm.GIT.GetUpstreamBranch(self.checkout_path)
714 default_rev = upstream_branch or default_rev 718 default_rev = upstream_branch or default_rev
715 _, deps_revision = gclient_utils.SplitUrlRevision(self.url) 719 _, deps_revision = gclient_utils.SplitUrlRevision(self.url)
716 if not deps_revision: 720 if not deps_revision:
717 deps_revision = default_rev 721 deps_revision = default_rev
718 if deps_revision.startswith('refs/heads/'): 722 if deps_revision.startswith('refs/heads/'):
719 deps_revision = deps_revision.replace('refs/heads/', self.remote + '/') 723 deps_revision = deps_revision.replace('refs/heads/', self.remote + '/')
720 deps_revision = self.GetUsableRev(deps_revision, options) 724 try:
725 deps_revision = self.GetUsableRev(deps_revision, options)
726 except NoUsableRevError:
727 # If the DEPS entry's url and hash changed, try to update the origin.
728 # See also http://crbug.com/520067.
729 return self.update(options, [], file_list)
721 730
722 if file_list is not None: 731 if file_list is not None:
723 files = self._Capture(['diff', deps_revision, '--name-only']).split() 732 files = self._Capture(['diff', deps_revision, '--name-only']).split()
724 733
725 self._Run(['reset', '--hard', deps_revision], options) 734 self._Run(['reset', '--hard', deps_revision], options)
726 self._Run(['clean', '-f', '-d'], options) 735 self._Run(['clean', '-f', '-d'], options)
727 736
728 if file_list is not None: 737 if file_list is not None:
729 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) 738 file_list.extend([os.path.join(self.checkout_path, f) for f in files])
730 739
(...skipping 17 matching lines...) Expand all
748 files = self._Capture(['diff', '--name-only', merge_base]).split() 757 files = self._Capture(['diff', '--name-only', merge_base]).split()
749 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) 758 file_list.extend([os.path.join(self.checkout_path, f) for f in files])
750 759
751 def GetUsableRev(self, rev, options): 760 def GetUsableRev(self, rev, options):
752 """Finds a useful revision for this repository. 761 """Finds a useful revision for this repository.
753 762
754 If SCM is git-svn and the head revision is less than |rev|, git svn fetch 763 If SCM is git-svn and the head revision is less than |rev|, git svn fetch
755 will be called on the source.""" 764 will be called on the source."""
756 sha1 = None 765 sha1 = None
757 if not os.path.isdir(self.checkout_path): 766 if not os.path.isdir(self.checkout_path):
758 raise gclient_utils.Error( 767 raise NoUsableRevError(
759 ( 'We could not find a valid hash for safesync_url response "%s".\n' 768 ( 'We could not find a valid hash for safesync_url response "%s".\n'
760 'Safesync URLs with a git checkout currently require the repo to\n' 769 'Safesync URLs with a git checkout currently require the repo to\n'
761 'be cloned without a safesync_url before adding the safesync_url.\n' 770 'be cloned without a safesync_url before adding the safesync_url.\n'
762 'For more info, see: ' 771 'For more info, see: '
763 'http://code.google.com/p/chromium/wiki/UsingNewGit' 772 'http://code.google.com/p/chromium/wiki/UsingNewGit'
764 '#Initial_checkout' ) % rev) 773 '#Initial_checkout' ) % rev)
765 elif rev.isdigit() and len(rev) < 7: 774 elif rev.isdigit() and len(rev) < 7:
766 # Handles an SVN rev. As an optimization, only verify an SVN revision as 775 # Handles an SVN rev. As an optimization, only verify an SVN revision as
767 # [0-9]{1,6} for now to avoid making a network request. 776 # [0-9]{1,6} for now to avoid making a network request.
768 if scm.GIT.IsGitSvn(cwd=self.checkout_path): 777 if scm.GIT.IsGitSvn(cwd=self.checkout_path):
(...skipping 13 matching lines...) Expand all
782 try: 791 try:
783 sha1 = scm.GIT.GetBlessedSha1ForSvnRev( 792 sha1 = scm.GIT.GetBlessedSha1ForSvnRev(
784 cwd=self.checkout_path, rev=rev) 793 cwd=self.checkout_path, rev=rev)
785 except gclient_utils.Error, e: 794 except gclient_utils.Error, e:
786 sha1 = e.message 795 sha1 = e.message
787 self.Print('Warning: Could not find a git revision with accurate\n' 796 self.Print('Warning: Could not find a git revision with accurate\n'
788 '.DEPS.git that maps to SVN revision %s. Sync-ing to\n' 797 '.DEPS.git that maps to SVN revision %s. Sync-ing to\n'
789 'the closest sane git revision, which is:\n' 798 'the closest sane git revision, which is:\n'
790 ' %s\n' % (rev, e.message)) 799 ' %s\n' % (rev, e.message))
791 if not sha1: 800 if not sha1:
792 raise gclient_utils.Error( 801 raise NoUsableRevError(
nodir 2015/08/12 17:20:08 Note that this was not catched before: it does not
tandrii(chromium) 2015/08/12 17:27:28 I am not sure about this case, but I thought PS2 i
793 ( 'It appears that either your git-svn remote is incorrectly\n' 802 ( 'It appears that either your git-svn remote is incorrectly\n'
794 'configured or the revision in your safesync_url is\n' 803 'configured or the revision in your safesync_url is\n'
795 'higher than git-svn remote\'s HEAD as we couldn\'t find a\n' 804 'higher than git-svn remote\'s HEAD as we couldn\'t find a\n'
796 'corresponding git hash for SVN rev %s.' ) % rev) 805 'corresponding git hash for SVN rev %s.' ) % rev)
797 else: 806 else:
798 if scm.GIT.IsValidRevision(cwd=self.checkout_path, rev=rev): 807 if scm.GIT.IsValidRevision(cwd=self.checkout_path, rev=rev):
799 sha1 = rev 808 sha1 = rev
800 else: 809 else:
801 # May exist in origin, but we don't have it yet, so fetch and look 810 # May exist in origin, but we don't have it yet, so fetch and look
802 # again. 811 # again.
803 self._Fetch(options) 812 self._Fetch(options)
804 if scm.GIT.IsValidRevision(cwd=self.checkout_path, rev=rev): 813 if scm.GIT.IsValidRevision(cwd=self.checkout_path, rev=rev):
805 sha1 = rev 814 sha1 = rev
806 815
807 if not sha1: 816 if not sha1:
808 raise gclient_utils.Error( 817 raise NoUsableRevError(
809 ( 'We could not find a valid hash for safesync_url response "%s".\n' 818 ( 'We could not find a valid hash for safesync_url response "%s".\n'
810 'Safesync URLs with a git checkout currently require a git-svn\n' 819 'Safesync URLs with a git checkout currently require a git-svn\n'
811 'remote or a safesync_url that provides git sha1s. Please add a\n' 820 'remote or a safesync_url that provides git sha1s. Please add a\n'
812 'git-svn remote or change your safesync_url. For more info, see:\n' 821 'git-svn remote or change your safesync_url. For more info, see:\n'
813 'http://code.google.com/p/chromium/wiki/UsingNewGit' 822 'http://code.google.com/p/chromium/wiki/UsingNewGit'
814 '#Initial_checkout' ) % rev) 823 '#Initial_checkout' ) % rev)
815 824
816 return sha1 825 return sha1
817 826
818 def FullUrlForRelativeUrl(self, url): 827 def FullUrlForRelativeUrl(self, url):
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 self.Print(('\n________ couldn\'t run \'%s\' in \'%s\':\n' 1592 self.Print(('\n________ couldn\'t run \'%s\' in \'%s\':\n'
1584 'The directory does not exist.') % 1593 'The directory does not exist.') %
1585 (' '.join(command), self.checkout_path)) 1594 (' '.join(command), self.checkout_path))
1586 # There's no file list to retrieve. 1595 # There's no file list to retrieve.
1587 else: 1596 else:
1588 self._RunAndGetFileList(command, options, file_list) 1597 self._RunAndGetFileList(command, options, file_list)
1589 1598
1590 def GetUsableRev(self, rev, _options): 1599 def GetUsableRev(self, rev, _options):
1591 """Verifies the validity of the revision for this repository.""" 1600 """Verifies the validity of the revision for this repository."""
1592 if not scm.SVN.IsValidRevision(url='%s@%s' % (self.url, rev)): 1601 if not scm.SVN.IsValidRevision(url='%s@%s' % (self.url, rev)):
1593 raise gclient_utils.Error( 1602 raise NoUsableRevError(
1594 ( '%s isn\'t a valid revision. Please check that your safesync_url is\n' 1603 ( '%s isn\'t a valid revision. Please check that your safesync_url is\n'
nodir 2015/08/12 17:20:09 this too
tandrii(chromium) 2015/08/12 17:27:28 this is inside SVN scm block, so this was doesn't
1595 'correct.') % rev) 1604 'correct.') % rev)
1596 return rev 1605 return rev
1597 1606
1598 def FullUrlForRelativeUrl(self, url): 1607 def FullUrlForRelativeUrl(self, url):
1599 # Find the forth '/' and strip from there. A bit hackish. 1608 # Find the forth '/' and strip from there. A bit hackish.
1600 return '/'.join(self.url.split('/')[:4]) + url 1609 return '/'.join(self.url.split('/')[:4]) + url
1601 1610
1602 def _Run(self, args, options, **kwargs): 1611 def _Run(self, args, options, **kwargs):
1603 """Runs a commands that goes to stdout.""" 1612 """Runs a commands that goes to stdout."""
1604 kwargs.setdefault('cwd', self.checkout_path) 1613 kwargs.setdefault('cwd', self.checkout_path)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1642 new_command.append('--force') 1651 new_command.append('--force')
1643 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1652 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1644 new_command.extend(('--accept', 'theirs-conflict')) 1653 new_command.extend(('--accept', 'theirs-conflict'))
1645 elif options.manually_grab_svn_rev: 1654 elif options.manually_grab_svn_rev:
1646 new_command.append('--force') 1655 new_command.append('--force')
1647 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1656 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1648 new_command.extend(('--accept', 'postpone')) 1657 new_command.extend(('--accept', 'postpone'))
1649 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1658 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1650 new_command.extend(('--accept', 'postpone')) 1659 new_command.extend(('--accept', 'postpone'))
1651 return new_command 1660 return new_command
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698