| 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 |
| 11 import sys | 11 import sys |
| 12 import time | 12 import time |
| 13 | 13 |
| 14 import gclient_utils |
| 14 import scm | 15 import scm |
| 15 import gclient_utils | 16 import subprocess2 |
| 16 | 17 |
| 17 | 18 |
| 18 class DiffFilterer(object): | 19 class DiffFilterer(object): |
| 19 """Simple class which tracks which file is being diffed and | 20 """Simple class which tracks which file is being diffed and |
| 20 replaces instances of its file name in the original and | 21 replaces instances of its file name in the original and |
| 21 working copy lines of the svn/git diff output.""" | 22 working copy lines of the svn/git diff output.""" |
| 22 index_string = "Index: " | 23 index_string = "Index: " |
| 23 original_prefix = "--- " | 24 original_prefix = "--- " |
| 24 working_prefix = "+++ " | 25 working_prefix = "+++ " |
| 25 | 26 |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 clone_cmd.append('--no-checkout') | 489 clone_cmd.append('--no-checkout') |
| 489 detach_head = True | 490 detach_head = True |
| 490 if options.verbose: | 491 if options.verbose: |
| 491 clone_cmd.append('--verbose') | 492 clone_cmd.append('--verbose') |
| 492 clone_cmd.extend([url, self.checkout_path]) | 493 clone_cmd.extend([url, self.checkout_path]) |
| 493 | 494 |
| 494 for _ in range(3): | 495 for _ in range(3): |
| 495 try: | 496 try: |
| 496 self._Run(clone_cmd, options, cwd=self._root_dir) | 497 self._Run(clone_cmd, options, cwd=self._root_dir) |
| 497 break | 498 break |
| 498 except gclient_utils.Error, e: | 499 except (gclient_utils.Error, subprocess2.CalledProcessError), e: |
| 499 # TODO(maruel): Hackish, should be fixed by moving _Run() to | 500 # TODO(maruel): Hackish, should be fixed by moving _Run() to |
| 500 # CheckCall(). | 501 # CheckCall(). |
| 501 # Too bad we don't have access to the actual output. | 502 # Too bad we don't have access to the actual output. |
| 502 # We should check for "transfer closed with NNN bytes remaining to | 503 # We should check for "transfer closed with NNN bytes remaining to |
| 503 # read". In the meantime, just make sure .git exists. | 504 # read". In the meantime, just make sure .git exists. |
| 504 if (e.args[0] == 'git command clone returned 128' and | 505 if (e.args[0] == 'git command clone returned 128' and |
| 505 os.path.exists(os.path.join(self.checkout_path, '.git'))): | 506 os.path.exists(os.path.join(self.checkout_path, '.git'))): |
| 506 print(str(e)) | 507 print(str(e)) |
| 507 print('Retrying...') | 508 print('Retrying...') |
| 508 continue | 509 continue |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 if not os.path.exists(self.checkout_path): | 744 if not os.path.exists(self.checkout_path): |
| 744 # We need to checkout. | 745 # We need to checkout. |
| 745 command = ['checkout', url, self.checkout_path] | 746 command = ['checkout', url, self.checkout_path] |
| 746 command = self._AddAdditionalUpdateFlags(command, options, revision) | 747 command = self._AddAdditionalUpdateFlags(command, options, revision) |
| 747 self._RunAndGetFileList(command, options, file_list, self._root_dir) | 748 self._RunAndGetFileList(command, options, file_list, self._root_dir) |
| 748 return | 749 return |
| 749 | 750 |
| 750 # Get the existing scm url and the revision number of the current checkout. | 751 # Get the existing scm url and the revision number of the current checkout. |
| 751 try: | 752 try: |
| 752 from_info = scm.SVN.CaptureInfo(os.path.join(self.checkout_path, '.')) | 753 from_info = scm.SVN.CaptureInfo(os.path.join(self.checkout_path, '.')) |
| 753 except gclient_utils.Error: | 754 except (gclient_utils.Error, subprocess2.CalledProcessError): |
| 754 raise gclient_utils.Error( | 755 raise gclient_utils.Error( |
| 755 ('Can\'t update/checkout %s if an unversioned directory is present. ' | 756 ('Can\'t update/checkout %s if an unversioned directory is present. ' |
| 756 'Delete the directory and try again.') % self.checkout_path) | 757 'Delete the directory and try again.') % self.checkout_path) |
| 757 | 758 |
| 758 # Look for locked directories. | 759 # Look for locked directories. |
| 759 dir_info = scm.SVN.CaptureStatus(os.path.join(self.checkout_path, '.')) | 760 dir_info = scm.SVN.CaptureStatus(os.path.join(self.checkout_path, '.')) |
| 760 if [True for d in dir_info | 761 if [True for d in dir_info |
| 761 if d[0][2] == 'L' and d[1] == self.checkout_path]: | 762 if d[0][2] == 'L' and d[1] == self.checkout_path]: |
| 762 # The current directory is locked, clean it up. | 763 # The current directory is locked, clean it up. |
| 763 self._Run(['cleanup'], options) | 764 self._Run(['cleanup'], options) |
| 764 | 765 |
| 765 # Retrieve the current HEAD version because svn is slow at null updates. | 766 # Retrieve the current HEAD version because svn is slow at null updates. |
| 766 if options.manually_grab_svn_rev and not revision: | 767 if options.manually_grab_svn_rev and not revision: |
| 767 from_info_live = scm.SVN.CaptureInfo(from_info['URL']) | 768 from_info_live = scm.SVN.CaptureInfo(from_info['URL']) |
| 768 revision = str(from_info_live['Revision']) | 769 revision = str(from_info_live['Revision']) |
| 769 rev_str = ' at %s' % revision | 770 rev_str = ' at %s' % revision |
| 770 | 771 |
| 771 if from_info['URL'] != base_url: | 772 if from_info['URL'] != base_url: |
| 772 # The repository url changed, need to switch. | 773 # The repository url changed, need to switch. |
| 773 try: | 774 try: |
| 774 to_info = scm.SVN.CaptureInfo(url) | 775 to_info = scm.SVN.CaptureInfo(url) |
| 775 except gclient_utils.Error: | 776 except (gclient_utils.Error, subprocess2.CalledProcessError): |
| 776 # 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 |
| 777 # out right now. | 778 # out right now. |
| 778 raise gclient_utils.Error('This url is unreachable: %s' % url) | 779 raise gclient_utils.Error('This url is unreachable: %s' % url) |
| 779 can_switch = ((from_info['Repository Root'] != to_info['Repository Root']) | 780 can_switch = ((from_info['Repository Root'] != to_info['Repository Root']) |
| 780 and (from_info['UUID'] == to_info['UUID'])) | 781 and (from_info['UUID'] == to_info['UUID'])) |
| 781 if can_switch: | 782 if can_switch: |
| 782 print('\n_____ relocating %s to a new checkout' % self.relpath) | 783 print('\n_____ relocating %s to a new checkout' % self.relpath) |
| 783 # We have different roots, so check if we can switch --relocate. | 784 # We have different roots, so check if we can switch --relocate. |
| 784 # Subversion only permits this if the repository UUIDs match. | 785 # Subversion only permits this if the repository UUIDs match. |
| 785 # Perform the switch --relocate, then rewrite the from_url | 786 # Perform the switch --relocate, then rewrite the from_url |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 self._RunAndGetFileList(['update', '--revision', 'BASE'], options, | 883 self._RunAndGetFileList(['update', '--revision', 'BASE'], options, |
| 883 file_list) | 884 file_list) |
| 884 except OSError, e: | 885 except OSError, e: |
| 885 # Maybe the directory disapeared meanwhile. Do not throw an exception. | 886 # Maybe the directory disapeared meanwhile. Do not throw an exception. |
| 886 logging.error('Failed to update:\n%s' % str(e)) | 887 logging.error('Failed to update:\n%s' % str(e)) |
| 887 | 888 |
| 888 def revinfo(self, options, args, file_list): | 889 def revinfo(self, options, args, file_list): |
| 889 """Display revision""" | 890 """Display revision""" |
| 890 try: | 891 try: |
| 891 return scm.SVN.CaptureRevision(self.checkout_path) | 892 return scm.SVN.CaptureRevision(self.checkout_path) |
| 892 except gclient_utils.Error: | 893 except (gclient_utils.Error, subprocess2.CalledProcessError): |
| 893 return None | 894 return None |
| 894 | 895 |
| 895 def runhooks(self, options, args, file_list): | 896 def runhooks(self, options, args, file_list): |
| 896 self.status(options, args, file_list) | 897 self.status(options, args, file_list) |
| 897 | 898 |
| 898 def status(self, options, args, file_list): | 899 def status(self, options, args, file_list): |
| 899 """Display status information.""" | 900 """Display status information.""" |
| 900 command = ['status'] + args | 901 command = ['status'] + args |
| 901 if not os.path.isdir(self.checkout_path): | 902 if not os.path.isdir(self.checkout_path): |
| 902 # svn status won't work if the directory doesn't exist. | 903 # svn status won't work if the directory doesn't exist. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 933 | 934 |
| 934 This method returns a new list to be used as a command.""" | 935 This method returns a new list to be used as a command.""" |
| 935 new_command = command[:] | 936 new_command = command[:] |
| 936 if revision: | 937 if revision: |
| 937 new_command.extend(['--revision', str(revision).strip()]) | 938 new_command.extend(['--revision', str(revision).strip()]) |
| 938 # --force was added to 'svn update' in svn 1.5. | 939 # --force was added to 'svn update' in svn 1.5. |
| 939 if ((options.force or options.manually_grab_svn_rev) and | 940 if ((options.force or options.manually_grab_svn_rev) and |
| 940 scm.SVN.AssertVersion("1.5")[0]): | 941 scm.SVN.AssertVersion("1.5")[0]): |
| 941 new_command.append('--force') | 942 new_command.append('--force') |
| 942 return new_command | 943 return new_command |
| OLD | NEW |