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 from __future__ import print_function | 7 from __future__ import print_function |
8 | 8 |
9 import logging | 9 import logging |
10 import os | 10 import os |
11 import posixpath | 11 import posixpath |
12 import re | 12 import re |
13 import shlex | 13 import shlex |
14 import sys | 14 import sys |
15 import tempfile | 15 import tempfile |
16 import traceback | 16 import traceback |
17 import urlparse | 17 import urlparse |
18 | 18 |
19 import download_from_google_storage | 19 import download_from_google_storage |
20 import gclient_utils | 20 import gclient_utils |
21 import git_cache | |
21 import scm | 22 import scm |
22 import subprocess2 | 23 import subprocess2 |
23 | 24 |
24 | 25 |
25 THIS_FILE_PATH = os.path.abspath(__file__) | 26 THIS_FILE_PATH = os.path.abspath(__file__) |
26 | 27 |
27 GSUTIL_DEFAULT_PATH = os.path.join( | 28 GSUTIL_DEFAULT_PATH = os.path.join( |
28 os.path.dirname(os.path.abspath(__file__)), | 29 os.path.dirname(os.path.abspath(__file__)), |
29 'third_party', 'gsutil', 'gsutil') | 30 'third_party', 'gsutil', 'gsutil') |
30 | 31 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 if not command in dir(self): | 153 if not command in dir(self): |
153 raise gclient_utils.Error('Command %s not implemented in %s wrapper' % ( | 154 raise gclient_utils.Error('Command %s not implemented in %s wrapper' % ( |
154 command, self.__class__.__name__)) | 155 command, self.__class__.__name__)) |
155 | 156 |
156 return getattr(self, command)(options, args, file_list) | 157 return getattr(self, command)(options, args, file_list) |
157 | 158 |
158 def GetActualRemoteURL(self, options): | 159 def GetActualRemoteURL(self, options): |
159 """Attempt to determine the remote URL for this SCMWrapper.""" | 160 """Attempt to determine the remote URL for this SCMWrapper.""" |
160 # Git | 161 # Git |
161 if os.path.exists(os.path.join(self.checkout_path, '.git')): | 162 if os.path.exists(os.path.join(self.checkout_path, '.git')): |
162 actual_remote_url = shlex.split(scm.GIT.Capture( | 163 actual_remote_url = shlex.split(self._Capture( |
163 ['config', '--local', '--get-regexp', r'remote.*.url'], | 164 ['config', '--local', '--get-regexp', r'remote.*.url'], |
164 self.checkout_path))[1] | 165 self.checkout_path))[1] |
165 | 166 |
166 # If a cache_dir is used, obtain the actual remote URL from the cache. | 167 # If a cache_dir is used, obtain the actual remote URL from the cache. |
167 if getattr(self, 'cache_dir', None): | 168 if getattr(self, 'cache_dir', None): |
168 try: | 169 mirror = git_cache.Mirror(self.url) |
169 full_cache_dir = self._Run(['cache', 'exists', '--cache-dir', | 170 if (mirror.exists() and mirror.mirror_path.replace('\\', '/') == |
170 self.cache_dir, self.url], | |
171 options, cwd=self._root_dir).strip() | |
172 except subprocess2.CalledProcessError: | |
173 full_cache_dir = None | |
174 if (full_cache_dir.replace('\\', '/') == | |
175 actual_remote_url.replace('\\', '/')): | 171 actual_remote_url.replace('\\', '/')): |
176 actual_remote_url = shlex.split(scm.GIT.Capture( | 172 actual_remote_url = shlex.split(self._Capture( |
177 ['config', '--local', '--get-regexp', r'remote.*.url'], | 173 ['config', '--local', '--get-regexp', r'remote.*.url'], |
178 os.path.join(self._root_dir, full_cache_dir)))[1] | 174 cwd=mirror.mirror_path))[1] |
179 return actual_remote_url | 175 return actual_remote_url |
180 | 176 |
181 # Svn | 177 # Svn |
182 if os.path.exists(os.path.join(self.checkout_path, '.svn')): | 178 if os.path.exists(os.path.join(self.checkout_path, '.svn')): |
183 return scm.SVN.CaptureLocalInfo([], self.checkout_path)['URL'] | 179 return scm.SVN.CaptureLocalInfo([], self.checkout_path)['URL'] |
184 return None | 180 return None |
185 | 181 |
186 def DoesRemoteURLMatch(self, options): | 182 def DoesRemoteURLMatch(self, options): |
187 """Determine whether the remote URL of this checkout is the expected URL.""" | 183 """Determine whether the remote URL of this checkout is the expected URL.""" |
188 if not os.path.exists(self.checkout_path): | 184 if not os.path.exists(self.checkout_path): |
(...skipping 10 matching lines...) Expand all Loading... | |
199 return False | 195 return False |
200 | 196 |
201 | 197 |
202 class GitWrapper(SCMWrapper): | 198 class GitWrapper(SCMWrapper): |
203 """Wrapper for Git""" | 199 """Wrapper for Git""" |
204 name = 'git' | 200 name = 'git' |
205 remote = 'origin' | 201 remote = 'origin' |
206 | 202 |
207 cache_dir = None | 203 cache_dir = None |
208 | 204 |
209 def __init__(self, url=None, root_dir=None, relpath=None, out_fh=None, | 205 def __init__(self, url=None, *args): |
210 out_cb=None): | |
211 """Removes 'git+' fake prefix from git URL.""" | 206 """Removes 'git+' fake prefix from git URL.""" |
212 if url.startswith('git+http://') or url.startswith('git+https://'): | 207 if url.startswith('git+http://') or url.startswith('git+https://'): |
213 url = url[4:] | 208 url = url[4:] |
214 SCMWrapper.__init__(self, url, root_dir, relpath, out_fh, out_cb) | 209 SCMWrapper.__init__(self, url, *args) |
215 | 210 |
216 @staticmethod | 211 @staticmethod |
217 def BinaryExists(): | 212 def BinaryExists(): |
218 """Returns true if the command exists.""" | 213 """Returns true if the command exists.""" |
219 try: | 214 try: |
220 # We assume git is newer than 1.7. See: crbug.com/114483 | 215 # We assume git is newer than 1.7. See: crbug.com/114483 |
221 result, version = scm.GIT.AssertVersion('1.7') | 216 result, version = scm.GIT.AssertVersion('1.7') |
222 if not result: | 217 if not result: |
223 raise gclient_utils.Error('Git version is older than 1.7: %s' % version) | 218 raise gclient_utils.Error('Git version is older than 1.7: %s' % version) |
224 return result | 219 return result |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
735 return base_url[:base_url.rfind('/')] + url | 730 return base_url[:base_url.rfind('/')] + url |
736 | 731 |
737 def _CreateOrUpdateCache(self, url, options): | 732 def _CreateOrUpdateCache(self, url, options): |
738 """Make a new git mirror or update existing mirror for |url|, and return the | 733 """Make a new git mirror or update existing mirror for |url|, and return the |
739 mirror URI to clone from. | 734 mirror URI to clone from. |
740 | 735 |
741 If no cache-dir is specified, just return |url| unchanged. | 736 If no cache-dir is specified, just return |url| unchanged. |
742 """ | 737 """ |
743 if not self.cache_dir: | 738 if not self.cache_dir: |
744 return url | 739 return url |
745 v = ['-v'] if options.verbose else [] | 740 mirror = git_cache.Mirror(url) |
746 self._Run(['cache', 'populate'] + v + ['--cache-dir', self.cache_dir, url], | 741 mirror.unlock() |
Ryan Tseng
2014/04/09 00:39:44
We actually don't want to do this. The lock is pr
szager1
2014/04/09 05:22:29
OK. I may have gone a bit overboard in adding cal
| |
747 options, cwd=self._root_dir, retry=True) | 742 mirror.populate(noisy=options.verbose) |
Ryan Tseng
2014/04/09 00:39:44
bootstrap=True?
szager1
2014/04/09 05:22:29
Done.
| |
748 return self._Run(['cache', 'exists', '--cache-dir', self.cache_dir, url], | 743 mirror.unlock() |
749 options, cwd=self._root_dir, ).strip() | 744 return mirror.mirror_path if mirror.exists() else None |
750 | 745 |
751 def _Clone(self, revision, url, options): | 746 def _Clone(self, revision, url, options): |
752 """Clone a git repository from the given URL. | 747 """Clone a git repository from the given URL. |
753 | 748 |
754 Once we've cloned the repo, we checkout a working branch if the specified | 749 Once we've cloned the repo, we checkout a working branch if the specified |
755 revision is a branch head. If it is a tag or a specific commit, then we | 750 revision is a branch head. If it is a tag or a specific commit, then we |
756 leave HEAD detached as it makes future updates simpler -- in this case the | 751 leave HEAD detached as it makes future updates simpler -- in this case the |
757 user should first create a new branch or switch to an existing branch before | 752 user should first create a new branch or switch to an existing branch before |
758 making changes in the repo.""" | 753 making changes in the repo.""" |
759 if not options.verbose: | 754 if not options.verbose: |
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1465 new_command.append('--force') | 1460 new_command.append('--force') |
1466 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1461 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1467 new_command.extend(('--accept', 'theirs-conflict')) | 1462 new_command.extend(('--accept', 'theirs-conflict')) |
1468 elif options.manually_grab_svn_rev: | 1463 elif options.manually_grab_svn_rev: |
1469 new_command.append('--force') | 1464 new_command.append('--force') |
1470 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1465 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1471 new_command.extend(('--accept', 'postpone')) | 1466 new_command.extend(('--accept', 'postpone')) |
1472 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1467 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1473 new_command.extend(('--accept', 'postpone')) | 1468 new_command.extend(('--accept', 'postpone')) |
1474 return new_command | 1469 return new_command |
OLD | NEW |