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

Side by Side Diff: gclient_scm.py

Issue 391048: gclient: fix another bug where ssh urls weren't parsed correctly (Closed)
Patch Set: fix per code review Created 11 years, 1 month 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 | « gclient.py ('k') | gclient_utils.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 2009 Google Inc. All Rights Reserved. 1 # Copyright 2009 Google Inc. All Rights Reserved.
2 # 2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); 3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License. 4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at 5 # You may obtain a copy of the License at
6 # 6 #
7 # http://www.apache.org/licenses/LICENSE-2.0 7 # http://www.apache.org/licenses/LICENSE-2.0
8 # 8 #
9 # Unless required by applicable law or agreed to in writing, software 9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, 10 # distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 122
123 All updated files will be appended to file_list. 123 All updated files will be appended to file_list.
124 124
125 Raises: 125 Raises:
126 Error: if can't get URL for relative path. 126 Error: if can't get URL for relative path.
127 """ 127 """
128 128
129 if args: 129 if args:
130 raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args)) 130 raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args))
131 131
132 if self.url.startswith('ssh:'): 132 url, revision = gclient_utils.SplitUrlRevision(self.url)
133 # Make sure ssh://test@example.com/test.git@stable works 133 rev_str = ""
134 regex = r"(ssh://(?:[\w]+@)?[-\w:\.]+/[-\w\.]+)(?:@([\w/]+))?"
135 components = re.search(regex, self.url).groups()
136 else:
137 components = self.url.split("@")
138 url = components[0]
139 revision = None
140 if options.revision: 134 if options.revision:
141 revision = options.revision 135 # Override the revision number.
142 elif len(components) == 2: 136 revision = str(options.revision)
143 revision = components[1] 137 if revision:
138 url = '%s@%s' % (url, revision)
139 rev_str = ' at %s' % revision
144 140
145 if options.verbose: 141 if options.verbose:
146 rev_str = ""
147 if revision:
148 rev_str = ' at %s' % revision
149 print("\n_____ %s%s" % (self.relpath, rev_str)) 142 print("\n_____ %s%s" % (self.relpath, rev_str))
150 143
151 if not os.path.exists(self.checkout_path): 144 if not os.path.exists(self.checkout_path):
152 self._RunGit(['clone', url, self.checkout_path], 145 self._RunGit(['clone', url, self.checkout_path],
153 cwd=self._root_dir, redirect_stdout=False) 146 cwd=self._root_dir, redirect_stdout=False)
154 if revision: 147 if revision:
155 self._RunGit(['reset', '--hard', revision], redirect_stdout=False) 148 self._RunGit(['reset', '--hard', revision], redirect_stdout=False)
156 files = self._RunGit(['ls-files']).split() 149 files = self._RunGit(['ls-files']).split()
157 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) 150 file_list.extend([os.path.join(self.checkout_path, f) for f in files])
158 return 151 return
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 # Only update if git is not controlling the directory. 255 # Only update if git is not controlling the directory.
263 checkout_path = os.path.join(self._root_dir, self.relpath) 256 checkout_path = os.path.join(self._root_dir, self.relpath)
264 git_path = os.path.join(self._root_dir, self.relpath, '.git') 257 git_path = os.path.join(self._root_dir, self.relpath, '.git')
265 if os.path.exists(git_path): 258 if os.path.exists(git_path):
266 print("________ found .git directory; skipping %s" % self.relpath) 259 print("________ found .git directory; skipping %s" % self.relpath)
267 return 260 return
268 261
269 if args: 262 if args:
270 raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args)) 263 raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args))
271 264
272 url = self.url 265 url, revision = gclient_utils.SplitUrlRevision(self.url)
273 components = url.split("@") 266 base_url = url
274 revision = None
275 forced_revision = False 267 forced_revision = False
268 rev_str = ""
276 if options.revision: 269 if options.revision:
277 # Override the revision number. 270 # Override the revision number.
278 url = '%s@%s' % (components[0], str(options.revision)) 271 revision = str(options.revision)
279 revision = options.revision 272 if revision:
280 forced_revision = True 273 forced_revision = True
281 elif len(components) == 2: 274 url = '%s@%s' % (url, revision)
282 revision = components[1]
283 forced_revision = True
284
285 rev_str = ""
286 if revision:
287 rev_str = ' at %s' % revision 275 rev_str = ' at %s' % revision
288 276
289 if not os.path.exists(checkout_path): 277 if not os.path.exists(checkout_path):
290 # We need to checkout. 278 # We need to checkout.
291 command = ['checkout', url, checkout_path] 279 command = ['checkout', url, checkout_path]
292 if revision: 280 if revision:
293 command.extend(['--revision', str(revision)]) 281 command.extend(['--revision', str(revision)])
294 RunSVNAndGetFileList(options, command, self._root_dir, file_list) 282 RunSVNAndGetFileList(options, command, self._root_dir, file_list)
295 return 283 return
296 284
297 # Get the existing scm url and the revision number of the current checkout. 285 # Get the existing scm url and the revision number of the current checkout.
298 from_info = CaptureSVNInfo(os.path.join(checkout_path, '.'), '.') 286 from_info = CaptureSVNInfo(os.path.join(checkout_path, '.'), '.')
299 if not from_info: 287 if not from_info:
300 raise gclient_utils.Error("Can't update/checkout %r if an unversioned " 288 raise gclient_utils.Error("Can't update/checkout %r if an unversioned "
301 "directory is present. Delete the directory " 289 "directory is present. Delete the directory "
302 "and try again." % 290 "and try again." %
303 checkout_path) 291 checkout_path)
304 292
305 if options.manually_grab_svn_rev: 293 if options.manually_grab_svn_rev:
306 # Retrieve the current HEAD version because svn is slow at null updates. 294 # Retrieve the current HEAD version because svn is slow at null updates.
307 if not revision: 295 if not revision:
308 from_info_live = CaptureSVNInfo(from_info['URL'], '.') 296 from_info_live = CaptureSVNInfo(from_info['URL'], '.')
309 revision = str(from_info_live['Revision']) 297 revision = str(from_info_live['Revision'])
310 rev_str = ' at %s' % revision 298 rev_str = ' at %s' % revision
311 299
312 if from_info['URL'] != components[0]: 300 if from_info['URL'] != base_url:
313 to_info = CaptureSVNInfo(url, '.') 301 to_info = CaptureSVNInfo(url, '.')
314 if not to_info.get('Repository Root') or not to_info.get('UUID'): 302 if not to_info.get('Repository Root') or not to_info.get('UUID'):
315 # The url is invalid or the server is not accessible, it's safer to bail 303 # The url is invalid or the server is not accessible, it's safer to bail
316 # out right now. 304 # out right now.
317 raise gclient_utils.Error('This url is unreachable: %s' % url) 305 raise gclient_utils.Error('This url is unreachable: %s' % url)
318 can_switch = ((from_info['Repository Root'] != to_info['Repository Root']) 306 can_switch = ((from_info['Repository Root'] != to_info['Repository Root'])
319 and (from_info['UUID'] == to_info['UUID'])) 307 and (from_info['UUID'] == to_info['UUID']))
320 if can_switch: 308 if can_switch:
321 print("\n_____ relocating %s to a new checkout" % self.relpath) 309 print("\n_____ relocating %s to a new checkout" % self.relpath)
322 # We have different roots, so check if we can switch --relocate. 310 # We have different roots, so check if we can switch --relocate.
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 self.ReplaceAndPrint(line) 469 self.ReplaceAndPrint(line)
482 else: 470 else:
483 if (line.startswith(self.original_prefix) or 471 if (line.startswith(self.original_prefix) or
484 line.startswith(self.working_prefix)): 472 line.startswith(self.working_prefix)):
485 self.ReplaceAndPrint(line) 473 self.ReplaceAndPrint(line)
486 else: 474 else:
487 print line 475 print line
488 476
489 filterer = DiffFilterer(self.relpath) 477 filterer = DiffFilterer(self.relpath)
490 RunSVNAndFilterOutput(command, path, False, False, filterer.Filter) 478 RunSVNAndFilterOutput(command, path, False, False, filterer.Filter)
OLDNEW
« no previous file with comments | « gclient.py ('k') | gclient_utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698