Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: gclient_scm.py

Issue 228793002: gclient: Fix cache_dir functionality (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Replace path separator for Windows case Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gclient.py ('k') | tests/gclient_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 133
134 if not command in commands: 134 if not command in commands:
135 raise gclient_utils.Error('Unknown command %s' % command) 135 raise gclient_utils.Error('Unknown command %s' % command)
136 136
137 if not command in dir(self): 137 if not command in dir(self):
138 raise gclient_utils.Error('Command %s not implemented in %s wrapper' % ( 138 raise gclient_utils.Error('Command %s not implemented in %s wrapper' % (
139 command, self.__class__.__name__)) 139 command, self.__class__.__name__))
140 140
141 return getattr(self, command)(options, args, file_list) 141 return getattr(self, command)(options, args, file_list)
142 142
143 def GetActualRemoteURL(self): 143 def GetActualRemoteURL(self, options):
144 """Attempt to determine the remote URL for this SCMWrapper.""" 144 """Attempt to determine the remote URL for this SCMWrapper."""
145 # Git
145 if os.path.exists(os.path.join(self.checkout_path, '.git')): 146 if os.path.exists(os.path.join(self.checkout_path, '.git')):
146 return shlex.split(scm.GIT.Capture( 147 actual_remote_url = shlex.split(scm.GIT.Capture(
147 ['config', '--local', '--get-regexp', r'remote.*.url'], 148 ['config', '--local', '--get-regexp', r'remote.*.url'],
148 self.checkout_path))[1] 149 self.checkout_path))[1]
150
151 # If a cache_dir is used, obtain the actual remote URL from the cache.
152 if getattr(self, 'cache_dir', None):
153 try:
154 full_cache_dir = self._Run(['cache', 'exists', '--cache-dir',
155 self.cache_dir, self.url],
156 options, cwd=self._root_dir).strip()
157 except subprocess2.CalledProcessError:
158 full_cache_dir = None
159 if (full_cache_dir.replace('\\', '/') ==
160 actual_remote_url.replace('\\', '/')):
161 actual_remote_url = shlex.split(scm.GIT.Capture(
162 ['config', '--local', '--get-regexp', r'remote.*.url'],
163 os.path.join(self._root_dir, full_cache_dir)))[1]
164 return actual_remote_url
165
166 # Svn
149 if os.path.exists(os.path.join(self.checkout_path, '.svn')): 167 if os.path.exists(os.path.join(self.checkout_path, '.svn')):
150 return scm.SVN.CaptureLocalInfo([], self.checkout_path)['URL'] 168 return scm.SVN.CaptureLocalInfo([], self.checkout_path)['URL']
151 return None 169 return None
152 170
153 def DoesRemoteURLMatch(self): 171 def DoesRemoteURLMatch(self, options):
154 """Determine whether the remote URL of this checkout is the expected URL.""" 172 """Determine whether the remote URL of this checkout is the expected URL."""
155 if not os.path.exists(self.checkout_path): 173 if not os.path.exists(self.checkout_path):
156 # A checkout which doesn't exist can't be broken. 174 # A checkout which doesn't exist can't be broken.
157 return True 175 return True
158 176
159 actual_remote_url = self.GetActualRemoteURL() 177 actual_remote_url = self.GetActualRemoteURL(options)
160 if actual_remote_url: 178 if actual_remote_url:
161 return (gclient_utils.SplitUrlRevision(actual_remote_url)[0].rstrip('/') 179 return (gclient_utils.SplitUrlRevision(actual_remote_url)[0].rstrip('/')
162 == gclient_utils.SplitUrlRevision(self.url)[0].rstrip('/')) 180 == gclient_utils.SplitUrlRevision(self.url)[0].rstrip('/'))
163 else: 181 else:
164 # This may occur if the self.checkout_path exists but does not contain a 182 # This may occur if the self.checkout_path exists but does not contain a
165 # valid git or svn checkout. 183 # valid git or svn checkout.
166 return False 184 return False
167 185
168 186
169 class GitWrapper(SCMWrapper): 187 class GitWrapper(SCMWrapper):
(...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1426 new_command.append('--force') 1444 new_command.append('--force')
1427 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1445 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1428 new_command.extend(('--accept', 'theirs-conflict')) 1446 new_command.extend(('--accept', 'theirs-conflict'))
1429 elif options.manually_grab_svn_rev: 1447 elif options.manually_grab_svn_rev:
1430 new_command.append('--force') 1448 new_command.append('--force')
1431 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1449 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1432 new_command.extend(('--accept', 'postpone')) 1450 new_command.extend(('--accept', 'postpone'))
1433 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1451 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1434 new_command.extend(('--accept', 'postpone')) 1452 new_command.extend(('--accept', 'postpone'))
1435 return new_command 1453 return new_command
OLDNEW
« no previous file with comments | « gclient.py ('k') | tests/gclient_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698