Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: ensure_dependencies.py

Issue 4542760560361472: Issue 2310 - Handle alternative syntax of Git SSH URLs (Closed)
Patch Set: Moved logic into postprocessing function Created April 30, 2015, 12:35 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # coding: utf-8 2 # coding: utf-8
3 3
4 # This Source Code Form is subject to the terms of the Mozilla Public 4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this 5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 7
8 import sys 8 import sys
9 import os 9 import os
10 import posixpath 10 import posixpath
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 if normpath == posixpath.pardir or normpath.startswith(posixpath.pardir + posi xpath.sep): 168 if normpath == posixpath.pardir or normpath.startswith(posixpath.pardir + posi xpath.sep):
169 raise Exception("Dependency path %s has to be inside the repository" % subpa th) 169 raise Exception("Dependency path %s has to be inside the repository" % subpa th)
170 return os.path.join(path, *normpath.split(posixpath.sep)) 170 return os.path.join(path, *normpath.split(posixpath.sep))
171 171
172 def get_repo_type(repo): 172 def get_repo_type(repo):
173 for name, repotype in repo_types.iteritems(): 173 for name, repotype in repo_types.iteritems():
174 if repotype.istype(repo): 174 if repotype.istype(repo):
175 return name 175 return name
176 return None 176 return None
177 177
178 def postprocess_url(url, type):
179 # Handle alternative syntax of Git SSH URLS
180 if (type == "git" and "@" in url and ":" in url and not urlparse.urlsplit(url) .scheme):
Sebastian Noack 2015/04/30 13:08:28 No explicit VCS switches please. We already have a
kzar 2015/04/30 13:27:12 Done.
181 return "ssh://" + url.replace(":", "/", 1)
182 return url
183
178 def ensure_repo(parentrepo, target, roots, sourcename): 184 def ensure_repo(parentrepo, target, roots, sourcename):
179 if os.path.exists(target): 185 if os.path.exists(target):
180 return 186 return
181 187
182 parenttype = get_repo_type(parentrepo) 188 parenttype = get_repo_type(parentrepo)
183 type = None 189 type = None
184 for key in roots: 190 for key in roots:
185 if key == parenttype or (key in repo_types and type is None): 191 if key == parenttype or (key in repo_types and type is None):
186 type = key 192 type = key
187 if type is None: 193 if type is None:
188 raise Exception("No valid source found to create %s" % target) 194 raise Exception("No valid source found to create %s" % target)
189 195
190 if os.path.exists(roots[type]): 196 root = postprocess_url(roots[type], type)
191 url = os.path.join(roots[type], sourcename) 197 sourcename = postprocess_url(sourcename, type)
198
199 if os.path.exists(root):
200 url = os.path.join(root, sourcename)
192 else: 201 else:
193 url = urlparse.urljoin(roots[type], sourcename) 202 url = urlparse.urljoin(root, sourcename)
194 203
195 logging.info("Cloning repository %s into %s" % (url, target)) 204 logging.info("Cloning repository %s into %s" % (url, target))
196 repo_types[type].clone(url, target) 205 repo_types[type].clone(url, target)
197 206
198 for repo in repo_types.itervalues(): 207 for repo in repo_types.itervalues():
199 if repo.istype(parentrepo): 208 if repo.istype(parentrepo):
200 repo.ignore(target, parentrepo) 209 repo.ignore(target, parentrepo)
201 210
202 def update_repo(target, revisions): 211 def update_repo(target, revisions):
203 type = get_repo_type(target) 212 type = get_repo_type(target)
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 args = parser.parse_args() 299 args = parser.parse_args()
291 300
292 if args.quiet: 301 if args.quiet:
293 logging.disable(logging.INFO) 302 logging.disable(logging.INFO)
294 303
295 repos = args.repos 304 repos = args.repos
296 if not len(repos): 305 if not len(repos):
297 repos = [os.path.dirname(__file__)] 306 repos = [os.path.dirname(__file__)]
298 for repo in repos: 307 for repo in repos:
299 resolve_deps(repo) 308 resolve_deps(repo)
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