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 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 revision = str(options.revision) | 734 revision = str(options.revision) |
735 if revision: | 735 if revision: |
736 forced_revision = True | 736 forced_revision = True |
737 url = '%s@%s' % (url, revision) | 737 url = '%s@%s' % (url, revision) |
738 rev_str = ' at %s' % revision | 738 rev_str = ' at %s' % revision |
739 | 739 |
740 if not os.path.exists(checkout_path): | 740 if not os.path.exists(checkout_path): |
741 # We need to checkout. | 741 # We need to checkout. |
742 command = ['checkout', url, checkout_path] | 742 command = ['checkout', url, checkout_path] |
743 command = self.AddAdditionalFlags(command, options, revision) | 743 command = self.AddAdditionalFlags(command, options, revision) |
744 scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list) | 744 scm.SVN.RunAndGetFileList(options.verbose, command, self._root_dir, |
| 745 file_list) |
745 return | 746 return |
746 | 747 |
747 # Get the existing scm url and the revision number of the current checkout. | 748 # Get the existing scm url and the revision number of the current checkout. |
748 from_info = scm.SVN.CaptureInfo(os.path.join(checkout_path, '.'), '.') | 749 from_info = scm.SVN.CaptureInfo(os.path.join(checkout_path, '.'), '.') |
749 if not from_info: | 750 if not from_info: |
750 raise gclient_utils.Error("Can't update/checkout %r if an unversioned " | 751 raise gclient_utils.Error("Can't update/checkout %r if an unversioned " |
751 "directory is present. Delete the directory " | 752 "directory is present. Delete the directory " |
752 "and try again." % | 753 "and try again." % |
753 checkout_path) | 754 checkout_path) |
754 | 755 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 raise gclient_utils.Error( | 801 raise gclient_utils.Error( |
801 ('Can\'t switch the checkout to %s; UUID don\'t match and ' | 802 ('Can\'t switch the checkout to %s; UUID don\'t match and ' |
802 'there is local changes in %s. Delete the directory and ' | 803 'there is local changes in %s. Delete the directory and ' |
803 'try again.') % (url, checkout_path)) | 804 'try again.') % (url, checkout_path)) |
804 # Ok delete it. | 805 # Ok delete it. |
805 print("\n_____ switching %s to a new checkout" % self.relpath) | 806 print("\n_____ switching %s to a new checkout" % self.relpath) |
806 gclient_utils.RemoveDirectory(checkout_path) | 807 gclient_utils.RemoveDirectory(checkout_path) |
807 # We need to checkout. | 808 # We need to checkout. |
808 command = ['checkout', url, checkout_path] | 809 command = ['checkout', url, checkout_path] |
809 command = self.AddAdditionalFlags(command, options, revision) | 810 command = self.AddAdditionalFlags(command, options, revision) |
810 scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list) | 811 scm.SVN.RunAndGetFileList(options.verbose, command, self._root_dir, |
| 812 file_list) |
811 return | 813 return |
812 | 814 |
813 | 815 |
814 # If the provided url has a revision number that matches the revision | 816 # If the provided url has a revision number that matches the revision |
815 # number of the existing directory, then we don't need to bother updating. | 817 # number of the existing directory, then we don't need to bother updating. |
816 if not options.force and str(from_info['Revision']) == revision: | 818 if not options.force and str(from_info['Revision']) == revision: |
817 if options.verbose or not forced_revision: | 819 if options.verbose or not forced_revision: |
818 print("\n_____ %s%s" % (self.relpath, rev_str)) | 820 print("\n_____ %s%s" % (self.relpath, rev_str)) |
819 return | 821 return |
820 | 822 |
821 command = ["update", checkout_path] | 823 command = ["update", checkout_path] |
822 command = self.AddAdditionalFlags(command, options, revision) | 824 command = self.AddAdditionalFlags(command, options, revision) |
823 scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list) | 825 scm.SVN.RunAndGetFileList(options.verbose, command, self._root_dir, |
| 826 file_list) |
824 | 827 |
825 def updatesingle(self, options, args, file_list): | 828 def updatesingle(self, options, args, file_list): |
826 checkout_path = os.path.join(self._root_dir, self.relpath) | 829 checkout_path = os.path.join(self._root_dir, self.relpath) |
827 filename = args.pop() | 830 filename = args.pop() |
828 if scm.SVN.AssertVersion("1.5")[0]: | 831 if scm.SVN.AssertVersion("1.5")[0]: |
829 if not os.path.exists(os.path.join(checkout_path, '.svn')): | 832 if not os.path.exists(os.path.join(checkout_path, '.svn')): |
830 # Create an empty checkout and then update the one file we want. Future | 833 # Create an empty checkout and then update the one file we want. Future |
831 # operations will only apply to the one file we checked out. | 834 # operations will only apply to the one file we checked out. |
832 command = ["checkout", "--depth", "empty", self.url, checkout_path] | 835 command = ["checkout", "--depth", "empty", self.url, checkout_path] |
833 scm.SVN.Run(command, self._root_dir) | 836 scm.SVN.Run(command, self._root_dir) |
834 if os.path.exists(os.path.join(checkout_path, filename)): | 837 if os.path.exists(os.path.join(checkout_path, filename)): |
835 os.remove(os.path.join(checkout_path, filename)) | 838 os.remove(os.path.join(checkout_path, filename)) |
836 command = ["update", filename] | 839 command = ["update", filename] |
837 scm.SVN.RunAndGetFileList(options, command, checkout_path, file_list) | 840 scm.SVN.RunAndGetFileList(options.verbose, command, checkout_path, |
| 841 file_list) |
838 # After the initial checkout, we can use update as if it were any other | 842 # After the initial checkout, we can use update as if it were any other |
839 # dep. | 843 # dep. |
840 self.update(options, args, file_list) | 844 self.update(options, args, file_list) |
841 else: | 845 else: |
842 # If the installed version of SVN doesn't support --depth, fallback to | 846 # If the installed version of SVN doesn't support --depth, fallback to |
843 # just exporting the file. This has the downside that revision | 847 # just exporting the file. This has the downside that revision |
844 # information is not stored next to the file, so we will have to | 848 # information is not stored next to the file, so we will have to |
845 # re-export the file every time we sync. | 849 # re-export the file every time we sync. |
846 if not os.path.exists(checkout_path): | 850 if not os.path.exists(checkout_path): |
847 os.makedirs(checkout_path) | 851 os.makedirs(checkout_path) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 gclient_utils.RemoveDirectory(file_path) | 896 gclient_utils.RemoveDirectory(file_path) |
893 else: | 897 else: |
894 logging.error('no idea what is %s.\nYou just found a bug in gclient' | 898 logging.error('no idea what is %s.\nYou just found a bug in gclient' |
895 ', please ping maruel@chromium.org ASAP!' % file_path) | 899 ', please ping maruel@chromium.org ASAP!' % file_path) |
896 except EnvironmentError: | 900 except EnvironmentError: |
897 logging.error('Failed to remove %s.' % file_path) | 901 logging.error('Failed to remove %s.' % file_path) |
898 | 902 |
899 try: | 903 try: |
900 # svn revert is so broken we don't even use it. Using | 904 # svn revert is so broken we don't even use it. Using |
901 # "svn up --revision BASE" achieve the same effect. | 905 # "svn up --revision BASE" achieve the same effect. |
902 scm.SVN.RunAndGetFileList(options, ['update', '--revision', 'BASE'], path, | 906 scm.SVN.RunAndGetFileList(options.verbose, |
| 907 ['update', '--revision', 'BASE'], path, |
903 file_list) | 908 file_list) |
904 except OSError, e: | 909 except OSError, e: |
905 # Maybe the directory disapeared meanwhile. We don't want it to throw an | 910 # Maybe the directory disapeared meanwhile. We don't want it to throw an |
906 # exception. | 911 # exception. |
907 logging.error('Failed to update:\n%s' % str(e)) | 912 logging.error('Failed to update:\n%s' % str(e)) |
908 | 913 |
909 def revinfo(self, options, args, file_list): | 914 def revinfo(self, options, args, file_list): |
910 """Display revision""" | 915 """Display revision""" |
911 return scm.SVN.CaptureBaseRevision(self.checkout_path) | 916 return scm.SVN.CaptureBaseRevision(self.checkout_path) |
912 | 917 |
913 def runhooks(self, options, args, file_list): | 918 def runhooks(self, options, args, file_list): |
914 self.status(options, args, file_list) | 919 self.status(options, args, file_list) |
915 | 920 |
916 def status(self, options, args, file_list): | 921 def status(self, options, args, file_list): |
917 """Display status information.""" | 922 """Display status information.""" |
918 path = os.path.join(self._root_dir, self.relpath) | 923 path = os.path.join(self._root_dir, self.relpath) |
919 command = ['status'] | 924 command = ['status'] |
920 command.extend(args) | 925 command.extend(args) |
921 if not os.path.isdir(path): | 926 if not os.path.isdir(path): |
922 # svn status won't work if the directory doesn't exist. | 927 # svn status won't work if the directory doesn't exist. |
923 print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory " | 928 print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory " |
924 "does not exist." | 929 "does not exist." |
925 % (' '.join(command), path)) | 930 % (' '.join(command), path)) |
926 # There's no file list to retrieve. | 931 # There's no file list to retrieve. |
927 else: | 932 else: |
928 scm.SVN.RunAndGetFileList(options, command, path, file_list) | 933 scm.SVN.RunAndGetFileList(options.verbose, command, path, file_list) |
929 | 934 |
930 def FullUrlForRelativeUrl(self, url): | 935 def FullUrlForRelativeUrl(self, url): |
931 # Find the forth '/' and strip from there. A bit hackish. | 936 # Find the forth '/' and strip from there. A bit hackish. |
932 return '/'.join(self.url.split('/')[:4]) + url | 937 return '/'.join(self.url.split('/')[:4]) + url |
933 | 938 |
934 @staticmethod | 939 @staticmethod |
935 def AddAdditionalFlags(command, options, revision): | 940 def AddAdditionalFlags(command, options, revision): |
936 """Add additional flags to command depending on what options are set. | 941 """Add additional flags to command depending on what options are set. |
937 command should be a list of strings that represents an svn command. | 942 command should be a list of strings that represents an svn command. |
938 | 943 |
939 This method returns a new list to be used as a command.""" | 944 This method returns a new list to be used as a command.""" |
940 new_command = command[:] | 945 new_command = command[:] |
941 if revision: | 946 if revision: |
942 new_command.extend(['--revision', str(revision).strip()]) | 947 new_command.extend(['--revision', str(revision).strip()]) |
943 # --force was added to 'svn update' in svn 1.5. | 948 # --force was added to 'svn update' in svn 1.5. |
944 if options.force and scm.SVN.AssertVersion("1.5")[0]: | 949 if options.force and scm.SVN.AssertVersion("1.5")[0]: |
945 new_command.append('--force') | 950 new_command.append('--force') |
946 return new_command | 951 return new_command |
OLD | NEW |