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 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 # Only update if git is not controlling the directory. | 718 # Only update if git is not controlling the directory. |
719 checkout_path = os.path.join(self._root_dir, self.relpath) | 719 checkout_path = os.path.join(self._root_dir, self.relpath) |
720 git_path = os.path.join(self._root_dir, self.relpath, '.git') | 720 git_path = os.path.join(self._root_dir, self.relpath, '.git') |
721 if os.path.exists(git_path): | 721 if os.path.exists(git_path): |
722 print("________ found .git directory; skipping %s" % self.relpath) | 722 print("________ found .git directory; skipping %s" % self.relpath) |
723 return | 723 return |
724 | 724 |
725 if args: | 725 if args: |
726 raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args)) | 726 raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args)) |
727 | 727 |
| 728 # revision is the revision to match. It is None if no revision is specified, |
| 729 # i.e. the 'deps ain't pinned'. |
728 url, revision = gclient_utils.SplitUrlRevision(self.url) | 730 url, revision = gclient_utils.SplitUrlRevision(self.url) |
| 731 # Keep the original unpinned url for reference in case the repo is switched. |
729 base_url = url | 732 base_url = url |
730 forced_revision = False | |
731 rev_str = "" | |
732 if options.revision: | 733 if options.revision: |
733 # Override the revision number. | 734 # Override the revision number. |
734 revision = str(options.revision) | 735 revision = str(options.revision) |
735 if revision: | 736 if revision: |
736 forced_revision = True | 737 forced_revision = True |
| 738 # Reconstruct the url. |
737 url = '%s@%s' % (url, revision) | 739 url = '%s@%s' % (url, revision) |
738 rev_str = ' at %s' % revision | 740 rev_str = ' at %s' % revision |
| 741 else: |
| 742 forced_revision = False |
| 743 rev_str = '' |
739 | 744 |
740 if not os.path.exists(checkout_path): | 745 if not os.path.exists(checkout_path): |
741 # We need to checkout. | 746 # We need to checkout. |
742 command = ['checkout', url, checkout_path] | 747 command = ['checkout', url, checkout_path] |
743 command = self.AddAdditionalFlags(command, options, revision) | 748 command = self._AddAdditionalUpdateFlags(command, options, revision) |
744 scm.SVN.RunAndGetFileList(options.verbose, command, self._root_dir, | 749 scm.SVN.RunAndGetFileList(options.verbose, command, self._root_dir, |
745 file_list) | 750 file_list) |
746 return | 751 return |
747 | 752 |
748 # Get the existing scm url and the revision number of the current checkout. | 753 # Get the existing scm url and the revision number of the current checkout. |
749 from_info = scm.SVN.CaptureInfo(os.path.join(checkout_path, '.'), '.') | 754 from_info = scm.SVN.CaptureInfo(os.path.join(checkout_path, '.'), '.') |
750 if not from_info: | 755 if not from_info: |
751 raise gclient_utils.Error("Can't update/checkout %r if an unversioned " | 756 raise gclient_utils.Error(('Can\'t update/checkout %r if an unversioned ' |
752 "directory is present. Delete the directory " | 757 'directory is present. Delete the directory ' |
753 "and try again." % | 758 'and try again.') % |
754 checkout_path) | 759 checkout_path) |
755 | 760 |
756 # Look for locked directories. | 761 # Look for locked directories. |
757 dir_info = scm.SVN.CaptureStatus(os.path.join(checkout_path, '.')) | 762 dir_info = scm.SVN.CaptureStatus(os.path.join(checkout_path, '.')) |
758 if [True for d in dir_info if d[0][2] == 'L' and d[1] == checkout_path]: | 763 if [True for d in dir_info if d[0][2] == 'L' and d[1] == checkout_path]: |
759 # The current directory is locked, clean it up. | 764 # The current directory is locked, clean it up. |
760 scm.SVN.Run(['cleanup'], checkout_path) | 765 scm.SVN.Run(['cleanup'], checkout_path) |
761 | 766 |
762 if options.manually_grab_svn_rev: | 767 # Retrieve the current HEAD version because svn is slow at null updates. |
763 # Retrieve the current HEAD version because svn is slow at null updates. | 768 if options.manually_grab_svn_rev and not revision: |
764 if not revision: | 769 from_info_live = scm.SVN.CaptureInfo(from_info['URL'], '.') |
765 from_info_live = scm.SVN.CaptureInfo(from_info['URL'], '.') | 770 revision = str(from_info_live['Revision']) |
766 revision = str(from_info_live['Revision']) | 771 rev_str = ' at %s' % revision |
767 rev_str = ' at %s' % revision | |
768 | 772 |
769 if from_info['URL'] != base_url: | 773 if from_info['URL'] != base_url: |
| 774 # The repository url changed, need to switch. |
770 to_info = scm.SVN.CaptureInfo(url, '.') | 775 to_info = scm.SVN.CaptureInfo(url, '.') |
771 if not to_info.get('Repository Root') or not to_info.get('UUID'): | 776 if not to_info.get('Repository Root') or not to_info.get('UUID'): |
772 # The url is invalid or the server is not accessible, it's safer to bail | 777 # The url is invalid or the server is not accessible, it's safer to bail |
773 # out right now. | 778 # out right now. |
774 raise gclient_utils.Error('This url is unreachable: %s' % url) | 779 raise gclient_utils.Error('This url is unreachable: %s' % url) |
775 can_switch = ((from_info['Repository Root'] != to_info['Repository Root']) | 780 can_switch = ((from_info['Repository Root'] != to_info['Repository Root']) |
776 and (from_info['UUID'] == to_info['UUID'])) | 781 and (from_info['UUID'] == to_info['UUID'])) |
777 if can_switch: | 782 if can_switch: |
778 print("\n_____ relocating %s to a new checkout" % self.relpath) | 783 print('\n_____ relocating %s to a new checkout' % self.relpath) |
779 # We have different roots, so check if we can switch --relocate. | 784 # We have different roots, so check if we can switch --relocate. |
780 # Subversion only permits this if the repository UUIDs match. | 785 # Subversion only permits this if the repository UUIDs match. |
781 # Perform the switch --relocate, then rewrite the from_url | 786 # Perform the switch --relocate, then rewrite the from_url |
782 # to reflect where we "are now." (This is the same way that | 787 # to reflect where we "are now." (This is the same way that |
783 # Subversion itself handles the metadata when switch --relocate | 788 # Subversion itself handles the metadata when switch --relocate |
784 # is used.) This makes the checks below for whether we | 789 # is used.) This makes the checks below for whether we |
785 # can update to a revision or have to switch to a different | 790 # can update to a revision or have to switch to a different |
786 # branch work as expected. | 791 # branch work as expected. |
787 # TODO(maruel): TEST ME ! | 792 # TODO(maruel): TEST ME ! |
788 command = ["switch", "--relocate", | 793 command = ['switch', '--relocate', |
789 from_info['Repository Root'], | 794 from_info['Repository Root'], |
790 to_info['Repository Root'], | 795 to_info['Repository Root'], |
791 self.relpath] | 796 self.relpath] |
792 scm.SVN.Run(command, self._root_dir) | 797 scm.SVN.Run(command, self._root_dir) |
793 from_info['URL'] = from_info['URL'].replace( | 798 from_info['URL'] = from_info['URL'].replace( |
794 from_info['Repository Root'], | 799 from_info['Repository Root'], |
795 to_info['Repository Root']) | 800 to_info['Repository Root']) |
796 else: | 801 else: |
797 if not options.force: | 802 if not options.force: |
798 # Look for local modifications but ignore unversioned files. | 803 # Look for local modifications but ignore unversioned files. |
799 for status in scm.SVN.CaptureStatus(checkout_path): | 804 for status in scm.SVN.CaptureStatus(checkout_path): |
800 if status[0] != '?': | 805 if status[0] != '?': |
801 raise gclient_utils.Error( | 806 raise gclient_utils.Error( |
802 ('Can\'t switch the checkout to %s; UUID don\'t match and ' | 807 ('Can\'t switch the checkout to %s; UUID don\'t match and ' |
803 'there is local changes in %s. Delete the directory and ' | 808 'there is local changes in %s. Delete the directory and ' |
804 'try again.') % (url, checkout_path)) | 809 'try again.') % (url, checkout_path)) |
805 # Ok delete it. | 810 # Ok delete it. |
806 print("\n_____ switching %s to a new checkout" % self.relpath) | 811 print('\n_____ switching %s to a new checkout' % self.relpath) |
807 gclient_utils.RemoveDirectory(checkout_path) | 812 gclient_utils.RemoveDirectory(checkout_path) |
808 # We need to checkout. | 813 # We need to checkout. |
809 command = ['checkout', url, checkout_path] | 814 command = ['checkout', url, checkout_path] |
810 command = self.AddAdditionalFlags(command, options, revision) | 815 command = self._AddAdditionalUpdateFlags(command, options, revision) |
811 scm.SVN.RunAndGetFileList(options.verbose, command, self._root_dir, | 816 scm.SVN.RunAndGetFileList(options.verbose, command, self._root_dir, |
812 file_list) | 817 file_list) |
813 return | 818 return |
814 | 819 |
815 | |
816 # If the provided url has a revision number that matches the revision | 820 # If the provided url has a revision number that matches the revision |
817 # number of the existing directory, then we don't need to bother updating. | 821 # number of the existing directory, then we don't need to bother updating. |
818 if not options.force and str(from_info['Revision']) == revision: | 822 if not options.force and str(from_info['Revision']) == revision: |
819 if options.verbose or not forced_revision: | 823 if options.verbose or not forced_revision: |
820 print("\n_____ %s%s" % (self.relpath, rev_str)) | 824 print('\n_____ %s%s' % (self.relpath, rev_str)) |
821 return | 825 return |
822 | 826 |
823 command = ["update", checkout_path] | 827 command = ['update', checkout_path] |
824 command = self.AddAdditionalFlags(command, options, revision) | 828 command = self._AddAdditionalUpdateFlags(command, options, revision) |
825 scm.SVN.RunAndGetFileList(options.verbose, command, self._root_dir, | 829 scm.SVN.RunAndGetFileList(options.verbose, command, self._root_dir, |
826 file_list) | 830 file_list) |
827 | 831 |
828 def updatesingle(self, options, args, file_list): | 832 def updatesingle(self, options, args, file_list): |
829 checkout_path = os.path.join(self._root_dir, self.relpath) | 833 checkout_path = os.path.join(self._root_dir, self.relpath) |
830 filename = args.pop() | 834 filename = args.pop() |
831 if scm.SVN.AssertVersion("1.5")[0]: | 835 if scm.SVN.AssertVersion("1.5")[0]: |
832 if not os.path.exists(os.path.join(checkout_path, '.svn')): | 836 if not os.path.exists(os.path.join(checkout_path, '.svn')): |
833 # Create an empty checkout and then update the one file we want. Future | 837 # Create an empty checkout and then update the one file we want. Future |
834 # operations will only apply to the one file we checked out. | 838 # operations will only apply to the one file we checked out. |
835 command = ["checkout", "--depth", "empty", self.url, checkout_path] | 839 command = ["checkout", "--depth", "empty", self.url, checkout_path] |
836 scm.SVN.Run(command, self._root_dir) | 840 scm.SVN.Run(command, self._root_dir) |
837 if os.path.exists(os.path.join(checkout_path, filename)): | 841 if os.path.exists(os.path.join(checkout_path, filename)): |
838 os.remove(os.path.join(checkout_path, filename)) | 842 os.remove(os.path.join(checkout_path, filename)) |
839 command = ["update", filename] | 843 command = ["update", filename] |
840 scm.SVN.RunAndGetFileList(options.verbose, command, checkout_path, | 844 scm.SVN.RunAndGetFileList(options.verbose, command, checkout_path, |
841 file_list) | 845 file_list) |
842 # After the initial checkout, we can use update as if it were any other | 846 # After the initial checkout, we can use update as if it were any other |
843 # dep. | 847 # dep. |
844 self.update(options, args, file_list) | 848 self.update(options, args, file_list) |
845 else: | 849 else: |
846 # If the installed version of SVN doesn't support --depth, fallback to | 850 # If the installed version of SVN doesn't support --depth, fallback to |
847 # just exporting the file. This has the downside that revision | 851 # just exporting the file. This has the downside that revision |
848 # information is not stored next to the file, so we will have to | 852 # information is not stored next to the file, so we will have to |
849 # re-export the file every time we sync. | 853 # re-export the file every time we sync. |
850 if not os.path.exists(checkout_path): | 854 if not os.path.exists(checkout_path): |
851 os.makedirs(checkout_path) | 855 os.makedirs(checkout_path) |
852 command = ["export", os.path.join(self.url, filename), | 856 command = ["export", os.path.join(self.url, filename), |
853 os.path.join(checkout_path, filename)] | 857 os.path.join(checkout_path, filename)] |
854 command = self.AddAdditionalFlags(command, options, options.revision) | 858 command = self._AddAdditionalUpdateFlags(command, options, |
| 859 options.revision) |
855 scm.SVN.Run(command, self._root_dir) | 860 scm.SVN.Run(command, self._root_dir) |
856 | 861 |
857 def revert(self, options, args, file_list): | 862 def revert(self, options, args, file_list): |
858 """Reverts local modifications. Subversion specific. | 863 """Reverts local modifications. Subversion specific. |
859 | 864 |
860 All reverted files will be appended to file_list, even if Subversion | 865 All reverted files will be appended to file_list, even if Subversion |
861 doesn't know about them. | 866 doesn't know about them. |
862 """ | 867 """ |
863 path = os.path.join(self._root_dir, self.relpath) | 868 path = os.path.join(self._root_dir, self.relpath) |
864 if not os.path.isdir(path): | 869 if not os.path.isdir(path): |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 % (' '.join(command), path)) | 935 % (' '.join(command), path)) |
931 # There's no file list to retrieve. | 936 # There's no file list to retrieve. |
932 else: | 937 else: |
933 scm.SVN.RunAndGetFileList(options.verbose, command, path, file_list) | 938 scm.SVN.RunAndGetFileList(options.verbose, command, path, file_list) |
934 | 939 |
935 def FullUrlForRelativeUrl(self, url): | 940 def FullUrlForRelativeUrl(self, url): |
936 # Find the forth '/' and strip from there. A bit hackish. | 941 # Find the forth '/' and strip from there. A bit hackish. |
937 return '/'.join(self.url.split('/')[:4]) + url | 942 return '/'.join(self.url.split('/')[:4]) + url |
938 | 943 |
939 @staticmethod | 944 @staticmethod |
940 def AddAdditionalFlags(command, options, revision): | 945 def _AddAdditionalUpdateFlags(command, options, revision): |
941 """Add additional flags to command depending on what options are set. | 946 """Add additional flags to command depending on what options are set. |
942 command should be a list of strings that represents an svn command. | 947 command should be a list of strings that represents an svn command. |
943 | 948 |
944 This method returns a new list to be used as a command.""" | 949 This method returns a new list to be used as a command.""" |
945 new_command = command[:] | 950 new_command = command[:] |
946 if revision: | 951 if revision: |
947 new_command.extend(['--revision', str(revision).strip()]) | 952 new_command.extend(['--revision', str(revision).strip()]) |
948 # --force was added to 'svn update' in svn 1.5. | 953 # --force was added to 'svn update' in svn 1.5. |
949 if options.force and scm.SVN.AssertVersion("1.5")[0]: | 954 if ((options.force or options.manually_grab_svn_rev) and |
| 955 scm.SVN.AssertVersion("1.5")[0]): |
950 new_command.append('--force') | 956 new_command.append('--force') |
951 return new_command | 957 return new_command |
OLD | NEW |