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

Side by Side Diff: gclient_scm.py

Issue 497053002: Use a regex instead of shlex.split() to get remote url (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: s/re.match/re.search/ Created 6 years, 4 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
« no previous file with comments | « no previous file | no next file » | 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 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
162 def GetActualRemoteURL(self, options): 161 def GetActualRemoteURL(self, options):
163 """Attempt to determine the remote URL for this SCMWrapper.""" 162 """Attempt to determine the remote URL for this SCMWrapper."""
163 def _get_first_remote_url(checkout_path):
164 log = scm.GIT.Capture(
165 ['config', '--local', '--get-regexp', r'remote.*.url'],
166 cwd=checkout_path)
167 return re.search(r'^remote\..*\.url (.*)$', log).group(1)
iannucci 2014/08/22 16:59:00 I think this could just be log.splitlines()[0].sp
168
164 # Git 169 # Git
165 if os.path.exists(os.path.join(self.checkout_path, '.git')): 170 if os.path.exists(os.path.join(self.checkout_path, '.git')):
166 actual_remote_url = shlex.split(scm.GIT.Capture( 171 actual_remote_url = _get_first_remote_url(self.checkout_path)
167 ['config', '--local', '--get-regexp', r'remote.*.url'],
168 cwd=self.checkout_path))[1]
169 172
170 # If a cache_dir is used, obtain the actual remote URL from the cache. 173 # If a cache_dir is used, obtain the actual remote URL from the cache.
171 if getattr(self, 'cache_dir', None): 174 if getattr(self, 'cache_dir', None):
172 url, _ = gclient_utils.SplitUrlRevision(self.url) 175 url, _ = gclient_utils.SplitUrlRevision(self.url)
173 mirror = git_cache.Mirror(url) 176 mirror = git_cache.Mirror(url)
174 if (mirror.exists() and mirror.mirror_path.replace('\\', '/') == 177 if (mirror.exists() and mirror.mirror_path.replace('\\', '/') ==
175 actual_remote_url.replace('\\', '/')): 178 actual_remote_url.replace('\\', '/')):
176 actual_remote_url = shlex.split(scm.GIT.Capture( 179 actual_remote_url = _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 180 return actual_remote_url
180 181
181 # Svn 182 # Svn
182 if os.path.exists(os.path.join(self.checkout_path, '.svn')): 183 if os.path.exists(os.path.join(self.checkout_path, '.svn')):
183 return scm.SVN.CaptureLocalInfo([], self.checkout_path)['URL'] 184 return scm.SVN.CaptureLocalInfo([], self.checkout_path)['URL']
184 return None 185 return None
185 186
186 def DoesRemoteURLMatch(self, options): 187 def DoesRemoteURLMatch(self, options):
187 """Determine whether the remote URL of this checkout is the expected URL.""" 188 """Determine whether the remote URL of this checkout is the expected URL."""
188 if not os.path.exists(self.checkout_path): 189 if not os.path.exists(self.checkout_path):
(...skipping 1383 matching lines...) Expand 10 before | Expand all | Expand 10 after
1572 new_command.append('--force') 1573 new_command.append('--force')
1573 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1574 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1574 new_command.extend(('--accept', 'theirs-conflict')) 1575 new_command.extend(('--accept', 'theirs-conflict'))
1575 elif options.manually_grab_svn_rev: 1576 elif options.manually_grab_svn_rev:
1576 new_command.append('--force') 1577 new_command.append('--force')
1577 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1578 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1578 new_command.extend(('--accept', 'postpone')) 1579 new_command.extend(('--accept', 'postpone'))
1579 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1580 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1580 new_command.extend(('--accept', 'postpone')) 1581 new_command.extend(('--accept', 'postpone'))
1581 return new_command 1582 return new_command
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698