| 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 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 # Override the revision number. | 733 # Override the revision number. |
| 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 if revision: | 743 command = self.AddAdditionalFlags(command, options, revision) |
| 744 command.extend(['--revision', str(revision).strip()]) | |
| 745 scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list) | 744 scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list) |
| 746 return | 745 return |
| 747 | 746 |
| 748 # Get the existing scm url and the revision number of the current checkout. | 747 # Get the existing scm url and the revision number of the current checkout. |
| 749 from_info = scm.SVN.CaptureInfo(os.path.join(checkout_path, '.'), '.') | 748 from_info = scm.SVN.CaptureInfo(os.path.join(checkout_path, '.'), '.') |
| 750 if not from_info: | 749 if not from_info: |
| 751 raise gclient_utils.Error("Can't update/checkout %r if an unversioned " | 750 raise gclient_utils.Error("Can't update/checkout %r if an unversioned " |
| 752 "directory is present. Delete the directory " | 751 "directory is present. Delete the directory " |
| 753 "and try again." % | 752 "and try again." % |
| 754 checkout_path) | 753 checkout_path) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 if scm.SVN.CaptureStatus(checkout_path): | 790 if scm.SVN.CaptureStatus(checkout_path): |
| 792 raise gclient_utils.Error("Can't switch the checkout to %s; UUID " | 791 raise gclient_utils.Error("Can't switch the checkout to %s; UUID " |
| 793 "don't match and there is local changes " | 792 "don't match and there is local changes " |
| 794 "in %s. Delete the directory and " | 793 "in %s. Delete the directory and " |
| 795 "try again." % (url, checkout_path)) | 794 "try again." % (url, checkout_path)) |
| 796 # Ok delete it. | 795 # Ok delete it. |
| 797 print("\n_____ switching %s to a new checkout" % self.relpath) | 796 print("\n_____ switching %s to a new checkout" % self.relpath) |
| 798 gclient_utils.RemoveDirectory(checkout_path) | 797 gclient_utils.RemoveDirectory(checkout_path) |
| 799 # We need to checkout. | 798 # We need to checkout. |
| 800 command = ['checkout', url, checkout_path] | 799 command = ['checkout', url, checkout_path] |
| 801 if revision: | 800 command = self.AddAdditionalFlags(command, options, revision) |
| 802 command.extend(['--revision', str(revision).strip()]) | |
| 803 scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list) | 801 scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list) |
| 804 return | 802 return |
| 805 | 803 |
| 806 | 804 |
| 807 # If the provided url has a revision number that matches the revision | 805 # If the provided url has a revision number that matches the revision |
| 808 # number of the existing directory, then we don't need to bother updating. | 806 # number of the existing directory, then we don't need to bother updating. |
| 809 if not options.force and str(from_info['Revision']) == revision: | 807 if not options.force and str(from_info['Revision']) == revision: |
| 810 if options.verbose or not forced_revision: | 808 if options.verbose or not forced_revision: |
| 811 print("\n_____ %s%s" % (self.relpath, rev_str)) | 809 print("\n_____ %s%s" % (self.relpath, rev_str)) |
| 812 return | 810 return |
| 813 | 811 |
| 814 command = ["update", checkout_path] | 812 command = ["update", checkout_path] |
| 815 if revision: | 813 command = self.AddAdditionalFlags(command, options, revision) |
| 816 command.extend(['--revision', str(revision).strip()]) | |
| 817 scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list) | 814 scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list) |
| 818 | 815 |
| 819 def updatesingle(self, options, args, file_list): | 816 def updatesingle(self, options, args, file_list): |
| 820 checkout_path = os.path.join(self._root_dir, self.relpath) | 817 checkout_path = os.path.join(self._root_dir, self.relpath) |
| 821 filename = args.pop() | 818 filename = args.pop() |
| 822 if scm.SVN.AssertVersion("1.5")[0]: | 819 if scm.SVN.AssertVersion("1.5")[0]: |
| 823 if not os.path.exists(os.path.join(checkout_path, '.svn')): | 820 if not os.path.exists(os.path.join(checkout_path, '.svn')): |
| 824 # Create an empty checkout and then update the one file we want. Future | 821 # Create an empty checkout and then update the one file we want. Future |
| 825 # operations will only apply to the one file we checked out. | 822 # operations will only apply to the one file we checked out. |
| 826 command = ["checkout", "--depth", "empty", self.url, checkout_path] | 823 command = ["checkout", "--depth", "empty", self.url, checkout_path] |
| 827 scm.SVN.Run(command, self._root_dir) | 824 scm.SVN.Run(command, self._root_dir) |
| 828 if os.path.exists(os.path.join(checkout_path, filename)): | 825 if os.path.exists(os.path.join(checkout_path, filename)): |
| 829 os.remove(os.path.join(checkout_path, filename)) | 826 os.remove(os.path.join(checkout_path, filename)) |
| 830 command = ["update", filename] | 827 command = ["update", filename] |
| 831 scm.SVN.RunAndGetFileList(options, command, checkout_path, file_list) | 828 scm.SVN.RunAndGetFileList(options, command, checkout_path, file_list) |
| 832 # After the initial checkout, we can use update as if it were any other | 829 # After the initial checkout, we can use update as if it were any other |
| 833 # dep. | 830 # dep. |
| 834 self.update(options, args, file_list) | 831 self.update(options, args, file_list) |
| 835 else: | 832 else: |
| 836 # If the installed version of SVN doesn't support --depth, fallback to | 833 # If the installed version of SVN doesn't support --depth, fallback to |
| 837 # just exporting the file. This has the downside that revision | 834 # just exporting the file. This has the downside that revision |
| 838 # information is not stored next to the file, so we will have to | 835 # information is not stored next to the file, so we will have to |
| 839 # re-export the file every time we sync. | 836 # re-export the file every time we sync. |
| 840 if not os.path.exists(checkout_path): | 837 if not os.path.exists(checkout_path): |
| 841 os.makedirs(checkout_path) | 838 os.makedirs(checkout_path) |
| 842 command = ["export", os.path.join(self.url, filename), | 839 command = ["export", os.path.join(self.url, filename), |
| 843 os.path.join(checkout_path, filename)] | 840 os.path.join(checkout_path, filename)] |
| 844 if options.revision: | 841 command = self.AddAdditionalFlags(command, options, options.revision) |
| 845 command.extend(['--revision', str(options.revision).strip()]) | |
| 846 scm.SVN.Run(command, self._root_dir) | 842 scm.SVN.Run(command, self._root_dir) |
| 847 | 843 |
| 848 def revert(self, options, args, file_list): | 844 def revert(self, options, args, file_list): |
| 849 """Reverts local modifications. Subversion specific. | 845 """Reverts local modifications. Subversion specific. |
| 850 | 846 |
| 851 All reverted files will be appended to file_list, even if Subversion | 847 All reverted files will be appended to file_list, even if Subversion |
| 852 doesn't know about them. | 848 doesn't know about them. |
| 853 """ | 849 """ |
| 854 __pychecker__ = 'unusednames=args' | 850 __pychecker__ = 'unusednames=args' |
| 855 path = os.path.join(self._root_dir, self.relpath) | 851 path = os.path.join(self._root_dir, self.relpath) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory " | 916 print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory " |
| 921 "does not exist." | 917 "does not exist." |
| 922 % (' '.join(command), path)) | 918 % (' '.join(command), path)) |
| 923 # There's no file list to retrieve. | 919 # There's no file list to retrieve. |
| 924 else: | 920 else: |
| 925 scm.SVN.RunAndGetFileList(options, command, path, file_list) | 921 scm.SVN.RunAndGetFileList(options, command, path, file_list) |
| 926 | 922 |
| 927 def FullUrlForRelativeUrl(self, url): | 923 def FullUrlForRelativeUrl(self, url): |
| 928 # Find the forth '/' and strip from there. A bit hackish. | 924 # Find the forth '/' and strip from there. A bit hackish. |
| 929 return '/'.join(self.url.split('/')[:4]) + url | 925 return '/'.join(self.url.split('/')[:4]) + url |
| 926 |
| 927 def AddAdditionalFlags(self, command, options, revision): |
| 928 """Add additional flags to command depending on what options are set. |
| 929 command should be a list of strings that represents an svn command. |
| 930 |
| 931 This method returns a new list to be used as a command.""" |
| 932 new_command = command[:] |
| 933 if revision: |
| 934 new_command.extend(['--revision', str(revision).strip()]) |
| 935 if options.force: |
| 936 new_command.append('--force') |
| 937 return new_command |
| OLD | NEW |