| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 78 |
| 79 def CreateSCM(url, root_dir=None, relpath=None): | 79 def CreateSCM(url, root_dir=None, relpath=None): |
| 80 SCM_MAP = { | 80 SCM_MAP = { |
| 81 'svn' : SVNWrapper, | 81 'svn' : SVNWrapper, |
| 82 'git' : GitWrapper, | 82 'git' : GitWrapper, |
| 83 } | 83 } |
| 84 | 84 |
| 85 scm_name = GetScmName(url) | 85 scm_name = GetScmName(url) |
| 86 if not scm_name in SCM_MAP: | 86 if not scm_name in SCM_MAP: |
| 87 raise gclient_utils.Error('No SCM found for url %s' % url) | 87 raise gclient_utils.Error('No SCM found for url %s' % url) |
| 88 return SCM_MAP[scm_name](url, root_dir, relpath) | 88 scm_class = SCM_MAP[scm_name] |
| 89 if not scm_class.BinaryExists(): |
| 90 raise gclient_utils.Error('%s command not found' % scm_name) |
| 91 return scm_class(url, root_dir, relpath) |
| 89 | 92 |
| 90 | 93 |
| 91 # SCMWrapper base class | 94 # SCMWrapper base class |
| 92 | 95 |
| 93 class SCMWrapper(object): | 96 class SCMWrapper(object): |
| 94 """Add necessary glue between all the supported SCM. | 97 """Add necessary glue between all the supported SCM. |
| 95 | 98 |
| 96 This is the abstraction layer to bind to different SCM. | 99 This is the abstraction layer to bind to different SCM. |
| 97 """ | 100 """ |
| 98 def __init__(self, url=None, root_dir=None, relpath=None): | 101 def __init__(self, url=None, root_dir=None, relpath=None): |
| (...skipping 27 matching lines...) Expand all Loading... |
| 126 | 129 |
| 127 class GitWrapper(SCMWrapper): | 130 class GitWrapper(SCMWrapper): |
| 128 """Wrapper for Git""" | 131 """Wrapper for Git""" |
| 129 | 132 |
| 130 def __init__(self, url=None, root_dir=None, relpath=None): | 133 def __init__(self, url=None, root_dir=None, relpath=None): |
| 131 """Removes 'git+' fake prefix from git URL.""" | 134 """Removes 'git+' fake prefix from git URL.""" |
| 132 if url.startswith('git+http://') or url.startswith('git+https://'): | 135 if url.startswith('git+http://') or url.startswith('git+https://'): |
| 133 url = url[4:] | 136 url = url[4:] |
| 134 SCMWrapper.__init__(self, url, root_dir, relpath) | 137 SCMWrapper.__init__(self, url, root_dir, relpath) |
| 135 | 138 |
| 139 @staticmethod |
| 140 def BinaryExists(): |
| 141 """Returns true if the command exists.""" |
| 142 try: |
| 143 # We assume git is newer than 1.7. See: crbug.com/114483 |
| 144 result, version = scm.GIT.AssertVersion('1.7') |
| 145 if not result: |
| 146 raise gclient_utils.Error('Git version is older than 1.7: %s' % version) |
| 147 return result |
| 148 except OSError: |
| 149 return False |
| 150 |
| 136 def GetRevisionDate(self, revision): | 151 def GetRevisionDate(self, revision): |
| 137 """Returns the given revision's date in ISO-8601 format (which contains the | 152 """Returns the given revision's date in ISO-8601 format (which contains the |
| 138 time zone).""" | 153 time zone).""" |
| 139 # TODO(floitsch): get the time-stamp of the given revision and not just the | 154 # TODO(floitsch): get the time-stamp of the given revision and not just the |
| 140 # time-stamp of the currently checked out revision. | 155 # time-stamp of the currently checked out revision. |
| 141 return self._Capture(['log', '-n', '1', '--format=%ai']) | 156 return self._Capture(['log', '-n', '1', '--format=%ai']) |
| 142 | 157 |
| 143 @staticmethod | 158 @staticmethod |
| 144 def cleanup(options, args, file_list): | 159 def cleanup(options, args, file_list): |
| 145 """'Cleanup' the repo. | 160 """'Cleanup' the repo. |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 kwargs.setdefault('print_stdout', True) | 783 kwargs.setdefault('print_stdout', True) |
| 769 stdout = kwargs.get('stdout', sys.stdout) | 784 stdout = kwargs.get('stdout', sys.stdout) |
| 770 stdout.write('\n________ running \'git %s\' in \'%s\'\n' % ( | 785 stdout.write('\n________ running \'git %s\' in \'%s\'\n' % ( |
| 771 ' '.join(args), kwargs['cwd'])) | 786 ' '.join(args), kwargs['cwd'])) |
| 772 gclient_utils.CheckCallAndFilter(['git'] + args, **kwargs) | 787 gclient_utils.CheckCallAndFilter(['git'] + args, **kwargs) |
| 773 | 788 |
| 774 | 789 |
| 775 class SVNWrapper(SCMWrapper): | 790 class SVNWrapper(SCMWrapper): |
| 776 """ Wrapper for SVN """ | 791 """ Wrapper for SVN """ |
| 777 | 792 |
| 793 @staticmethod |
| 794 def BinaryExists(): |
| 795 """Returns true if the command exists.""" |
| 796 try: |
| 797 result, version = scm.SVN.AssertVersion('1.4') |
| 798 if not result: |
| 799 raise gclient_utils.Error('SVN version is older than 1.4: %s' % version) |
| 800 return result |
| 801 except OSError: |
| 802 return False |
| 803 |
| 778 def GetRevisionDate(self, revision): | 804 def GetRevisionDate(self, revision): |
| 779 """Returns the given revision's date in ISO-8601 format (which contains the | 805 """Returns the given revision's date in ISO-8601 format (which contains the |
| 780 time zone).""" | 806 time zone).""" |
| 781 date = scm.SVN.Capture( | 807 date = scm.SVN.Capture( |
| 782 ['propget', '--revprop', 'svn:date', '-r', revision], | 808 ['propget', '--revprop', 'svn:date', '-r', revision], |
| 783 os.path.join(self.checkout_path, '.')) | 809 os.path.join(self.checkout_path, '.')) |
| 784 return date.strip() | 810 return date.strip() |
| 785 | 811 |
| 786 def cleanup(self, options, args, file_list): | 812 def cleanup(self, options, args, file_list): |
| 787 """Cleanup working copy.""" | 813 """Cleanup working copy.""" |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1129 new_command.append('--force') | 1155 new_command.append('--force') |
| 1130 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1156 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1131 new_command.extend(('--accept', 'theirs-conflict')) | 1157 new_command.extend(('--accept', 'theirs-conflict')) |
| 1132 elif options.manually_grab_svn_rev: | 1158 elif options.manually_grab_svn_rev: |
| 1133 new_command.append('--force') | 1159 new_command.append('--force') |
| 1134 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1160 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1135 new_command.extend(('--accept', 'postpone')) | 1161 new_command.extend(('--accept', 'postpone')) |
| 1136 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1162 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1137 new_command.extend(('--accept', 'postpone')) | 1163 new_command.extend(('--accept', 'postpone')) |
| 1138 return new_command | 1164 return new_command |
| OLD | NEW |