OLD | NEW |
1 # Copyright (c) 2009 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 |
11 import subprocess | 11 import subprocess |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 revision = str(options.revision) | 675 revision = str(options.revision) |
676 if revision: | 676 if revision: |
677 forced_revision = True | 677 forced_revision = True |
678 url = '%s@%s' % (url, revision) | 678 url = '%s@%s' % (url, revision) |
679 rev_str = ' at %s' % revision | 679 rev_str = ' at %s' % revision |
680 | 680 |
681 if not os.path.exists(checkout_path): | 681 if not os.path.exists(checkout_path): |
682 # We need to checkout. | 682 # We need to checkout. |
683 command = ['checkout', url, checkout_path] | 683 command = ['checkout', url, checkout_path] |
684 if revision: | 684 if revision: |
685 command.extend(['--revision', str(revision)]) | 685 command.extend(['--revision', str(revision).strip()]) |
686 scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list) | 686 scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list) |
687 return | 687 return |
688 | 688 |
689 # Get the existing scm url and the revision number of the current checkout. | 689 # Get the existing scm url and the revision number of the current checkout. |
690 from_info = scm.SVN.CaptureInfo(os.path.join(checkout_path, '.'), '.') | 690 from_info = scm.SVN.CaptureInfo(os.path.join(checkout_path, '.'), '.') |
691 if not from_info: | 691 if not from_info: |
692 raise gclient_utils.Error("Can't update/checkout %r if an unversioned " | 692 raise gclient_utils.Error("Can't update/checkout %r if an unversioned " |
693 "directory is present. Delete the directory " | 693 "directory is present. Delete the directory " |
694 "and try again." % | 694 "and try again." % |
695 checkout_path) | 695 checkout_path) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 raise gclient_utils.Error("Can't switch the checkout to %s; UUID " | 733 raise gclient_utils.Error("Can't switch the checkout to %s; UUID " |
734 "don't match and there is local changes " | 734 "don't match and there is local changes " |
735 "in %s. Delete the directory and " | 735 "in %s. Delete the directory and " |
736 "try again." % (url, checkout_path)) | 736 "try again." % (url, checkout_path)) |
737 # Ok delete it. | 737 # Ok delete it. |
738 print("\n_____ switching %s to a new checkout" % self.relpath) | 738 print("\n_____ switching %s to a new checkout" % self.relpath) |
739 gclient_utils.RemoveDirectory(checkout_path) | 739 gclient_utils.RemoveDirectory(checkout_path) |
740 # We need to checkout. | 740 # We need to checkout. |
741 command = ['checkout', url, checkout_path] | 741 command = ['checkout', url, checkout_path] |
742 if revision: | 742 if revision: |
743 command.extend(['--revision', str(revision)]) | 743 command.extend(['--revision', str(revision).strip()]) |
744 scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list) | 744 scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list) |
745 return | 745 return |
746 | 746 |
747 | 747 |
748 # If the provided url has a revision number that matches the revision | 748 # If the provided url has a revision number that matches the revision |
749 # number of the existing directory, then we don't need to bother updating. | 749 # number of the existing directory, then we don't need to bother updating. |
750 if not options.force and str(from_info['Revision']) == revision: | 750 if not options.force and str(from_info['Revision']) == revision: |
751 if options.verbose or not forced_revision: | 751 if options.verbose or not forced_revision: |
752 print("\n_____ %s%s" % (self.relpath, rev_str)) | 752 print("\n_____ %s%s" % (self.relpath, rev_str)) |
753 return | 753 return |
754 | 754 |
755 command = ["update", checkout_path] | 755 command = ["update", checkout_path] |
756 if revision: | 756 if revision: |
757 command.extend(['--revision', str(revision)]) | 757 command.extend(['--revision', str(revision).strip()]) |
758 scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list) | 758 scm.SVN.RunAndGetFileList(options, command, self._root_dir, file_list) |
759 | 759 |
760 def updatesingle(self, options, args, file_list): | 760 def updatesingle(self, options, args, file_list): |
761 checkout_path = os.path.join(self._root_dir, self.relpath) | 761 checkout_path = os.path.join(self._root_dir, self.relpath) |
762 filename = args.pop() | 762 filename = args.pop() |
763 if scm.SVN.AssertVersion("1.5")[0]: | 763 if scm.SVN.AssertVersion("1.5")[0]: |
764 if not os.path.exists(os.path.join(checkout_path, '.svn')): | 764 if not os.path.exists(os.path.join(checkout_path, '.svn')): |
765 # Create an empty checkout and then update the one file we want. Future | 765 # Create an empty checkout and then update the one file we want. Future |
766 # operations will only apply to the one file we checked out. | 766 # operations will only apply to the one file we checked out. |
767 command = ["checkout", "--depth", "empty", self.url, checkout_path] | 767 command = ["checkout", "--depth", "empty", self.url, checkout_path] |
768 scm.SVN.Run(command, self._root_dir) | 768 scm.SVN.Run(command, self._root_dir) |
769 if os.path.exists(os.path.join(checkout_path, filename)): | 769 if os.path.exists(os.path.join(checkout_path, filename)): |
770 os.remove(os.path.join(checkout_path, filename)) | 770 os.remove(os.path.join(checkout_path, filename)) |
771 command = ["update", filename] | 771 command = ["update", filename] |
772 scm.SVN.RunAndGetFileList(options, command, checkout_path, file_list) | 772 scm.SVN.RunAndGetFileList(options, command, checkout_path, file_list) |
773 # After the initial checkout, we can use update as if it were any other | 773 # After the initial checkout, we can use update as if it were any other |
774 # dep. | 774 # dep. |
775 self.update(options, args, file_list) | 775 self.update(options, args, file_list) |
776 else: | 776 else: |
777 # If the installed version of SVN doesn't support --depth, fallback to | 777 # If the installed version of SVN doesn't support --depth, fallback to |
778 # just exporting the file. This has the downside that revision | 778 # just exporting the file. This has the downside that revision |
779 # information is not stored next to the file, so we will have to | 779 # information is not stored next to the file, so we will have to |
780 # re-export the file every time we sync. | 780 # re-export the file every time we sync. |
781 if not os.path.exists(checkout_path): | 781 if not os.path.exists(checkout_path): |
782 os.makedirs(checkout_path) | 782 os.makedirs(checkout_path) |
783 command = ["export", os.path.join(self.url, filename), | 783 command = ["export", os.path.join(self.url, filename), |
784 os.path.join(checkout_path, filename)] | 784 os.path.join(checkout_path, filename)] |
785 if options.revision: | 785 if options.revision: |
786 command.extend(['--revision', str(options.revision)]) | 786 command.extend(['--revision', str(options.revision).strip()]) |
787 scm.SVN.Run(command, self._root_dir) | 787 scm.SVN.Run(command, self._root_dir) |
788 | 788 |
789 def revert(self, options, args, file_list): | 789 def revert(self, options, args, file_list): |
790 """Reverts local modifications. Subversion specific. | 790 """Reverts local modifications. Subversion specific. |
791 | 791 |
792 All reverted files will be appended to file_list, even if Subversion | 792 All reverted files will be appended to file_list, even if Subversion |
793 doesn't know about them. | 793 doesn't know about them. |
794 """ | 794 """ |
795 __pychecker__ = 'unusednames=args' | 795 __pychecker__ = 'unusednames=args' |
796 path = os.path.join(self._root_dir, self.relpath) | 796 path = os.path.join(self._root_dir, self.relpath) |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory " | 861 print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory " |
862 "does not exist." | 862 "does not exist." |
863 % (' '.join(command), path)) | 863 % (' '.join(command), path)) |
864 # There's no file list to retrieve. | 864 # There's no file list to retrieve. |
865 else: | 865 else: |
866 scm.SVN.RunAndGetFileList(options, command, path, file_list) | 866 scm.SVN.RunAndGetFileList(options, command, path, file_list) |
867 | 867 |
868 def FullUrlForRelativeUrl(self, url): | 868 def FullUrlForRelativeUrl(self, url): |
869 # Find the forth '/' and strip from there. A bit hackish. | 869 # Find the forth '/' and strip from there. A bit hackish. |
870 return '/'.join(self.url.split('/')[:4]) + url | 870 return '/'.join(self.url.split('/')[:4]) + url |
OLD | NEW |