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 errno | 9 import errno |
10 import logging | 10 import logging |
11 import os | 11 import os |
12 import posixpath | 12 import posixpath |
13 import re | 13 import re |
14 import shlex | |
15 import sys | 14 import sys |
16 import tempfile | 15 import tempfile |
17 import traceback | 16 import traceback |
18 import urlparse | 17 import urlparse |
19 | 18 |
20 import download_from_google_storage | 19 import download_from_google_storage |
21 import gclient_utils | 20 import gclient_utils |
22 import git_cache | 21 import git_cache |
23 import scm | 22 import scm |
24 import shutil | 23 import shutil |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 151 |
153 if not command in commands: | 152 if not command in commands: |
154 raise gclient_utils.Error('Unknown command %s' % command) | 153 raise gclient_utils.Error('Unknown command %s' % command) |
155 | 154 |
156 if not command in dir(self): | 155 if not command in dir(self): |
157 raise gclient_utils.Error('Command %s not implemented in %s wrapper' % ( | 156 raise gclient_utils.Error('Command %s not implemented in %s wrapper' % ( |
158 command, self.__class__.__name__)) | 157 command, self.__class__.__name__)) |
159 | 158 |
160 return getattr(self, command)(options, args, file_list) | 159 return getattr(self, command)(options, args, file_list) |
161 | 160 |
| 161 @staticmethod |
| 162 def _get_first_remote_url(checkout_path): |
| 163 log = scm.GIT.Capture( |
| 164 ['config', '--local', '--get-regexp', r'remote.*.url'], |
| 165 cwd=checkout_path) |
| 166 # Get the second token of the first line of the log. |
| 167 return log.splitlines()[0].split(' ', 1)[1] |
| 168 |
162 def GetActualRemoteURL(self, options): | 169 def GetActualRemoteURL(self, options): |
163 """Attempt to determine the remote URL for this SCMWrapper.""" | 170 """Attempt to determine the remote URL for this SCMWrapper.""" |
164 # Git | 171 # Git |
165 if os.path.exists(os.path.join(self.checkout_path, '.git')): | 172 if os.path.exists(os.path.join(self.checkout_path, '.git')): |
166 actual_remote_url = shlex.split(scm.GIT.Capture( | 173 actual_remote_url = self._get_first_remote_url(self.checkout_path) |
167 ['config', '--local', '--get-regexp', r'remote.*.url'], | |
168 cwd=self.checkout_path))[1] | |
169 | 174 |
170 # If a cache_dir is used, obtain the actual remote URL from the cache. | 175 # If a cache_dir is used, obtain the actual remote URL from the cache. |
171 if getattr(self, 'cache_dir', None): | 176 if getattr(self, 'cache_dir', None): |
172 url, _ = gclient_utils.SplitUrlRevision(self.url) | 177 url, _ = gclient_utils.SplitUrlRevision(self.url) |
173 mirror = git_cache.Mirror(url) | 178 mirror = git_cache.Mirror(url) |
174 if (mirror.exists() and mirror.mirror_path.replace('\\', '/') == | 179 if (mirror.exists() and mirror.mirror_path.replace('\\', '/') == |
175 actual_remote_url.replace('\\', '/')): | 180 actual_remote_url.replace('\\', '/')): |
176 actual_remote_url = shlex.split(scm.GIT.Capture( | 181 actual_remote_url = self._get_first_remote_url(mirror.mirror_path) |
177 ['config', '--local', '--get-regexp', r'remote.*.url'], | |
178 cwd=mirror.mirror_path))[1] | |
179 return actual_remote_url | 182 return actual_remote_url |
180 | 183 |
181 # Svn | 184 # Svn |
182 if os.path.exists(os.path.join(self.checkout_path, '.svn')): | 185 if os.path.exists(os.path.join(self.checkout_path, '.svn')): |
183 return scm.SVN.CaptureLocalInfo([], self.checkout_path)['URL'] | 186 return scm.SVN.CaptureLocalInfo([], self.checkout_path)['URL'] |
184 return None | 187 return None |
185 | 188 |
186 def DoesRemoteURLMatch(self, options): | 189 def DoesRemoteURLMatch(self, options): |
187 """Determine whether the remote URL of this checkout is the expected URL.""" | 190 """Determine whether the remote URL of this checkout is the expected URL.""" |
188 if not os.path.exists(self.checkout_path): | 191 if not os.path.exists(self.checkout_path): |
(...skipping 1383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1572 new_command.append('--force') | 1575 new_command.append('--force') |
1573 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1576 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1574 new_command.extend(('--accept', 'theirs-conflict')) | 1577 new_command.extend(('--accept', 'theirs-conflict')) |
1575 elif options.manually_grab_svn_rev: | 1578 elif options.manually_grab_svn_rev: |
1576 new_command.append('--force') | 1579 new_command.append('--force') |
1577 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1580 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1578 new_command.extend(('--accept', 'postpone')) | 1581 new_command.extend(('--accept', 'postpone')) |
1579 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1582 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1580 new_command.extend(('--accept', 'postpone')) | 1583 new_command.extend(('--accept', 'postpone')) |
1581 return new_command | 1584 return new_command |
OLD | NEW |