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

Side by Side Diff: gclient_scm.py

Issue 8771042: Enforces using cwd in all svn calls. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Address comments Created 9 years 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 | « gcl.py ('k') | presubmit_support.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) 2011 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2011 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 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 ' '.join(args), kwargs['cwd'])) 704 ' '.join(args), kwargs['cwd']))
705 gclient_utils.CheckCallAndFilter(['git'] + args, **kwargs) 705 gclient_utils.CheckCallAndFilter(['git'] + args, **kwargs)
706 706
707 707
708 class SVNWrapper(SCMWrapper): 708 class SVNWrapper(SCMWrapper):
709 """ Wrapper for SVN """ 709 """ Wrapper for SVN """
710 710
711 def GetRevisionDate(self, revision): 711 def GetRevisionDate(self, revision):
712 """Returns the given revision's date in ISO-8601 format (which contains the 712 """Returns the given revision's date in ISO-8601 format (which contains the
713 time zone).""" 713 time zone)."""
714 date = scm.SVN.Capture(['propget', '--revprop', 'svn:date', '-r', revision, 714 date = scm.SVN.Capture(
715 os.path.join(self.checkout_path, '.')]) 715 ['propget', '--revprop', 'svn:date', '-r', revision],
716 os.path.join(self.checkout_path, '.'))
716 return date.strip() 717 return date.strip()
717 718
718 def cleanup(self, options, args, file_list): 719 def cleanup(self, options, args, file_list):
719 """Cleanup working copy.""" 720 """Cleanup working copy."""
720 self._Run(['cleanup'] + args, options) 721 self._Run(['cleanup'] + args, options)
721 722
722 def diff(self, options, args, file_list): 723 def diff(self, options, args, file_list):
723 # NOTE: This function does not currently modify file_list. 724 # NOTE: This function does not currently modify file_list.
724 if not os.path.isdir(self.checkout_path): 725 if not os.path.isdir(self.checkout_path):
725 raise gclient_utils.Error('Directory %s is not present.' % 726 raise gclient_utils.Error('Directory %s is not present.' %
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 command = self._AddAdditionalUpdateFlags(command, options, revision) 790 command = self._AddAdditionalUpdateFlags(command, options, revision)
790 self._RunAndGetFileList(command, options, file_list, self._root_dir) 791 self._RunAndGetFileList(command, options, file_list, self._root_dir)
791 return 792 return
792 793
793 if not managed: 794 if not managed:
794 print ('________ unmanaged solution; skipping %s' % self.relpath) 795 print ('________ unmanaged solution; skipping %s' % self.relpath)
795 return 796 return
796 797
797 # Get the existing scm url and the revision number of the current checkout. 798 # Get the existing scm url and the revision number of the current checkout.
798 try: 799 try:
799 from_info = scm.SVN.CaptureInfo(os.path.join(self.checkout_path, '.')) 800 from_info = scm.SVN.CaptureLocalInfo(
801 [], os.path.join(self.checkout_path, '.'))
800 except (gclient_utils.Error, subprocess2.CalledProcessError): 802 except (gclient_utils.Error, subprocess2.CalledProcessError):
801 raise gclient_utils.Error( 803 raise gclient_utils.Error(
802 ('Can\'t update/checkout %s if an unversioned directory is present. ' 804 ('Can\'t update/checkout %s if an unversioned directory is present. '
803 'Delete the directory and try again.') % self.checkout_path) 805 'Delete the directory and try again.') % self.checkout_path)
804 806
805 if 'URL' not in from_info: 807 if 'URL' not in from_info:
806 raise gclient_utils.Error( 808 raise gclient_utils.Error(
807 ('gclient is confused. Couldn\'t get the url for %s.\n' 809 ('gclient is confused. Couldn\'t get the url for %s.\n'
808 'Try using @unmanaged.\n%s') % ( 810 'Try using @unmanaged.\n%s') % (
809 self.checkout_path, from_info)) 811 self.checkout_path, from_info))
810 812
811 # Look for locked directories. 813 # Look for locked directories.
812 dir_info = scm.SVN.CaptureStatus(os.path.join(self.checkout_path, '.')) 814 dir_info = scm.SVN.CaptureStatus(
815 None, os.path.join(self.checkout_path, '.'))
813 if any(d[0][2] == 'L' for d in dir_info): 816 if any(d[0][2] == 'L' for d in dir_info):
814 try: 817 try:
815 self._Run(['cleanup', self.checkout_path], options) 818 self._Run(['cleanup', self.checkout_path], options)
816 except subprocess2.CalledProcessError, e: 819 except subprocess2.CalledProcessError, e:
817 # Get the status again, svn cleanup may have cleaned up at least 820 # Get the status again, svn cleanup may have cleaned up at least
818 # something. 821 # something.
819 dir_info = scm.SVN.CaptureStatus(os.path.join(self.checkout_path, '.')) 822 dir_info = scm.SVN.CaptureStatus(
823 None, os.path.join(self.checkout_path, '.'))
820 824
821 # Try to fix the failures by removing troublesome files. 825 # Try to fix the failures by removing troublesome files.
822 for d in dir_info: 826 for d in dir_info:
823 if d[0][2] == 'L': 827 if d[0][2] == 'L':
824 if d[0][0] == '!' and options.force: 828 if d[0][0] == '!' and options.force:
825 print 'Removing troublesome path %s' % d[1] 829 print 'Removing troublesome path %s' % d[1]
826 gclient_utils.rmtree(d[1]) 830 gclient_utils.rmtree(d[1])
827 else: 831 else:
828 print 'Not removing troublesome path %s automatically.' % d[1] 832 print 'Not removing troublesome path %s automatically.' % d[1]
829 if d[0][0] == '!': 833 if d[0][0] == '!':
830 print 'You can pass --force to enable automatic removal.' 834 print 'You can pass --force to enable automatic removal.'
831 raise e 835 raise e
832 836
833 # Retrieve the current HEAD version because svn is slow at null updates. 837 # Retrieve the current HEAD version because svn is slow at null updates.
834 if options.manually_grab_svn_rev and not revision: 838 if options.manually_grab_svn_rev and not revision:
835 from_info_live = scm.SVN.CaptureInfo(from_info['URL']) 839 from_info_live = scm.SVN.CaptureRemoteInfo(from_info['URL'])
836 revision = str(from_info_live['Revision']) 840 revision = str(from_info_live['Revision'])
837 rev_str = ' at %s' % revision 841 rev_str = ' at %s' % revision
838 842
839 if from_info['URL'] != base_url: 843 if from_info['URL'] != base_url:
840 # The repository url changed, need to switch. 844 # The repository url changed, need to switch.
841 try: 845 try:
842 to_info = scm.SVN.CaptureInfo(url) 846 to_info = scm.SVN.CaptureRemoteInfo(url)
843 except (gclient_utils.Error, subprocess2.CalledProcessError): 847 except (gclient_utils.Error, subprocess2.CalledProcessError):
844 # The url is invalid or the server is not accessible, it's safer to bail 848 # The url is invalid or the server is not accessible, it's safer to bail
845 # out right now. 849 # out right now.
846 raise gclient_utils.Error('This url is unreachable: %s' % url) 850 raise gclient_utils.Error('This url is unreachable: %s' % url)
847 can_switch = ((from_info['Repository Root'] != to_info['Repository Root']) 851 can_switch = ((from_info['Repository Root'] != to_info['Repository Root'])
848 and (from_info['UUID'] == to_info['UUID'])) 852 and (from_info['UUID'] == to_info['UUID']))
849 if can_switch: 853 if can_switch:
850 print('\n_____ relocating %s to a new checkout' % self.relpath) 854 print('\n_____ relocating %s to a new checkout' % self.relpath)
851 # We have different roots, so check if we can switch --relocate. 855 # We have different roots, so check if we can switch --relocate.
852 # Subversion only permits this if the repository UUIDs match. 856 # Subversion only permits this if the repository UUIDs match.
853 # Perform the switch --relocate, then rewrite the from_url 857 # Perform the switch --relocate, then rewrite the from_url
854 # to reflect where we "are now." (This is the same way that 858 # to reflect where we "are now." (This is the same way that
855 # Subversion itself handles the metadata when switch --relocate 859 # Subversion itself handles the metadata when switch --relocate
856 # is used.) This makes the checks below for whether we 860 # is used.) This makes the checks below for whether we
857 # can update to a revision or have to switch to a different 861 # can update to a revision or have to switch to a different
858 # branch work as expected. 862 # branch work as expected.
859 # TODO(maruel): TEST ME ! 863 # TODO(maruel): TEST ME !
860 command = ['switch', '--relocate', 864 command = ['switch', '--relocate',
861 from_info['Repository Root'], 865 from_info['Repository Root'],
862 to_info['Repository Root'], 866 to_info['Repository Root'],
863 self.relpath] 867 self.relpath]
864 self._Run(command, options, cwd=self._root_dir) 868 self._Run(command, options, cwd=self._root_dir)
865 from_info['URL'] = from_info['URL'].replace( 869 from_info['URL'] = from_info['URL'].replace(
866 from_info['Repository Root'], 870 from_info['Repository Root'],
867 to_info['Repository Root']) 871 to_info['Repository Root'])
868 else: 872 else:
869 if not options.force and not options.reset: 873 if not options.force and not options.reset:
870 # Look for local modifications but ignore unversioned files. 874 # Look for local modifications but ignore unversioned files.
871 for status in scm.SVN.CaptureStatus(self.checkout_path): 875 for status in scm.SVN.CaptureStatus(None, self.checkout_path):
872 if status[0] != '?': 876 if status[0] != '?':
873 raise gclient_utils.Error( 877 raise gclient_utils.Error(
874 ('Can\'t switch the checkout to %s; UUID don\'t match and ' 878 ('Can\'t switch the checkout to %s; UUID don\'t match and '
875 'there is local changes in %s. Delete the directory and ' 879 'there is local changes in %s. Delete the directory and '
876 'try again.') % (url, self.checkout_path)) 880 'try again.') % (url, self.checkout_path))
877 # Ok delete it. 881 # Ok delete it.
878 print('\n_____ switching %s to a new checkout' % self.relpath) 882 print('\n_____ switching %s to a new checkout' % self.relpath)
879 gclient_utils.RemoveDirectory(self.checkout_path) 883 gclient_utils.RemoveDirectory(self.checkout_path)
880 # We need to checkout. 884 # We need to checkout.
881 command = ['checkout', url, self.checkout_path] 885 command = ['checkout', url, self.checkout_path]
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 new_command.append('--force') 1044 new_command.append('--force')
1041 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1045 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1042 new_command.extend(('--accept', 'theirs-conflict')) 1046 new_command.extend(('--accept', 'theirs-conflict'))
1043 elif options.manually_grab_svn_rev: 1047 elif options.manually_grab_svn_rev:
1044 new_command.append('--force') 1048 new_command.append('--force')
1045 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1049 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1046 new_command.extend(('--accept', 'postpone')) 1050 new_command.extend(('--accept', 'postpone'))
1047 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1051 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1048 new_command.extend(('--accept', 'postpone')) 1052 new_command.extend(('--accept', 'postpone'))
1049 return new_command 1053 return new_command
OLDNEW
« no previous file with comments | « gcl.py ('k') | presubmit_support.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698