OLD | NEW |
1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 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 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 rev_str = '' | 735 rev_str = '' |
736 | 736 |
737 if not os.path.exists(self.checkout_path): | 737 if not os.path.exists(self.checkout_path): |
738 # We need to checkout. | 738 # We need to checkout. |
739 command = ['checkout', url, self.checkout_path] | 739 command = ['checkout', url, self.checkout_path] |
740 command = self._AddAdditionalUpdateFlags(command, options, revision) | 740 command = self._AddAdditionalUpdateFlags(command, options, revision) |
741 self._RunAndGetFileList(command, options, file_list, self._root_dir) | 741 self._RunAndGetFileList(command, options, file_list, self._root_dir) |
742 return | 742 return |
743 | 743 |
744 # Get the existing scm url and the revision number of the current checkout. | 744 # Get the existing scm url and the revision number of the current checkout. |
745 from_info = scm.SVN.CaptureInfo(os.path.join(self.checkout_path, '.'), '.') | 745 try: |
746 if not from_info: | 746 from_info = scm.SVN.CaptureInfo(os.path.join(self.checkout_path, '.')) |
747 raise gclient_utils.Error(('Can\'t update/checkout %r if an unversioned ' | 747 except gclient_utils.Error: |
748 'directory is present. Delete the directory ' | 748 raise gclient_utils.Error( |
749 'and try again.') % | 749 ('Can\'t update/checkout %s if an unversioned directory is present. ' |
750 self.checkout_path) | 750 'Delete the directory and try again.') % self.checkout_path) |
751 | 751 |
752 # Look for locked directories. | 752 # Look for locked directories. |
753 dir_info = scm.SVN.CaptureStatus(os.path.join(self.checkout_path, '.')) | 753 dir_info = scm.SVN.CaptureStatus(os.path.join(self.checkout_path, '.')) |
754 if [True for d in dir_info | 754 if [True for d in dir_info |
755 if d[0][2] == 'L' and d[1] == self.checkout_path]: | 755 if d[0][2] == 'L' and d[1] == self.checkout_path]: |
756 # The current directory is locked, clean it up. | 756 # The current directory is locked, clean it up. |
757 self._Run(['cleanup'], options) | 757 self._Run(['cleanup'], options) |
758 | 758 |
759 # Retrieve the current HEAD version because svn is slow at null updates. | 759 # Retrieve the current HEAD version because svn is slow at null updates. |
760 if options.manually_grab_svn_rev and not revision: | 760 if options.manually_grab_svn_rev and not revision: |
761 from_info_live = scm.SVN.CaptureInfo(from_info['URL'], '.') | 761 from_info_live = scm.SVN.CaptureInfo(from_info['URL']) |
762 revision = str(from_info_live['Revision']) | 762 revision = str(from_info_live['Revision']) |
763 rev_str = ' at %s' % revision | 763 rev_str = ' at %s' % revision |
764 | 764 |
765 if from_info['URL'] != base_url: | 765 if from_info['URL'] != base_url: |
766 # The repository url changed, need to switch. | 766 # The repository url changed, need to switch. |
767 to_info = scm.SVN.CaptureInfo(url, '.') | 767 try: |
768 if not to_info.get('Repository Root') or not to_info.get('UUID'): | 768 to_info = scm.SVN.CaptureInfo(url) |
| 769 except gclient_utils.Error: |
769 # The url is invalid or the server is not accessible, it's safer to bail | 770 # The url is invalid or the server is not accessible, it's safer to bail |
770 # out right now. | 771 # out right now. |
771 raise gclient_utils.Error('This url is unreachable: %s' % url) | 772 raise gclient_utils.Error('This url is unreachable: %s' % url) |
772 can_switch = ((from_info['Repository Root'] != to_info['Repository Root']) | 773 can_switch = ((from_info['Repository Root'] != to_info['Repository Root']) |
773 and (from_info['UUID'] == to_info['UUID'])) | 774 and (from_info['UUID'] == to_info['UUID'])) |
774 if can_switch: | 775 if can_switch: |
775 options.stdout.write('\n_____ relocating %s to a new checkout\n' % | 776 options.stdout.write('\n_____ relocating %s to a new checkout\n' % |
776 self.relpath) | 777 self.relpath) |
777 # We have different roots, so check if we can switch --relocate. | 778 # We have different roots, so check if we can switch --relocate. |
778 # Subversion only permits this if the repository UUIDs match. | 779 # Subversion only permits this if the repository UUIDs match. |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 # "svn up --revision BASE" achieve the same effect. | 913 # "svn up --revision BASE" achieve the same effect. |
913 self._RunAndGetFileList(['update', '--revision', 'BASE'], options, | 914 self._RunAndGetFileList(['update', '--revision', 'BASE'], options, |
914 file_list) | 915 file_list) |
915 except OSError, e: | 916 except OSError, e: |
916 # Maybe the directory disapeared meanwhile. We don't want it to throw an | 917 # Maybe the directory disapeared meanwhile. We don't want it to throw an |
917 # exception. | 918 # exception. |
918 logging.error('Failed to update:\n%s' % str(e)) | 919 logging.error('Failed to update:\n%s' % str(e)) |
919 | 920 |
920 def revinfo(self, options, args, file_list): | 921 def revinfo(self, options, args, file_list): |
921 """Display revision""" | 922 """Display revision""" |
922 return scm.SVN.CaptureBaseRevision(self.checkout_path) | 923 try: |
| 924 return scm.SVN.CaptureRevision(self.checkout_path) |
| 925 except gclient_utils.Error: |
| 926 return None |
923 | 927 |
924 def runhooks(self, options, args, file_list): | 928 def runhooks(self, options, args, file_list): |
925 self.status(options, args, file_list) | 929 self.status(options, args, file_list) |
926 | 930 |
927 def status(self, options, args, file_list): | 931 def status(self, options, args, file_list): |
928 """Display status information.""" | 932 """Display status information.""" |
929 command = ['status'] + args | 933 command = ['status'] + args |
930 if not os.path.isdir(self.checkout_path): | 934 if not os.path.isdir(self.checkout_path): |
931 # svn status won't work if the directory doesn't exist. | 935 # svn status won't work if the directory doesn't exist. |
932 options.stdout.write( | 936 options.stdout.write( |
(...skipping 26 matching lines...) Expand all Loading... |
959 | 963 |
960 This method returns a new list to be used as a command.""" | 964 This method returns a new list to be used as a command.""" |
961 new_command = command[:] | 965 new_command = command[:] |
962 if revision: | 966 if revision: |
963 new_command.extend(['--revision', str(revision).strip()]) | 967 new_command.extend(['--revision', str(revision).strip()]) |
964 # --force was added to 'svn update' in svn 1.5. | 968 # --force was added to 'svn update' in svn 1.5. |
965 if ((options.force or options.manually_grab_svn_rev) and | 969 if ((options.force or options.manually_grab_svn_rev) and |
966 scm.SVN.AssertVersion("1.5")[0]): | 970 scm.SVN.AssertVersion("1.5")[0]): |
967 new_command.append('--force') | 971 new_command.append('--force') |
968 return new_command | 972 return new_command |
OLD | NEW |