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

Delta Between Two Patch Sets: ensure_dependencies.py

Issue 4542760560361472: Issue 2310 - Handle alternative syntax of Git SSH URLs (Closed)
Left Patch Set: Moved postprocess_url function into VC abstraction classes. Created April 30, 2015, 1:24 p.m.
Right Patch Set: Avoid looking up postprocess_url function twice. Created April 30, 2015, 2:41 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo) 103 subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo)
104 104
105 def ignore(self, target, repo): 105 def ignore(self, target, repo):
106 module = os.path.relpath(target, repo) 106 module = os.path.relpath(target, repo)
107 exclude_file = os.path.join(repo, ".git", "info", "exclude") 107 exclude_file = os.path.join(repo, ".git", "info", "exclude")
108 _ensure_line_exists(exclude_file, module) 108 _ensure_line_exists(exclude_file, module)
109 109
110 def postprocess_url(self, url): 110 def postprocess_url(self, url):
111 # Handle alternative syntax of SSH URLS 111 # Handle alternative syntax of SSH URLS
112 if "@" in url and ":" in url and not urlparse.urlsplit(url).scheme: 112 if "@" in url and ":" in url and not urlparse.urlsplit(url).scheme:
113 return "ssh://" + url.replace(":", "/", 1) 113 return "ssh://" + url.replace(":", "/", 1)
Sebastian Noack 2015/04/30 13:34:36 How does git URLs specify ports?
kzar 2015/04/30 14:45:29 Apparently they can't, you have to specify non-sta
114 return url 114 return url
115 115
116 repo_types = OrderedDict(( 116 repo_types = OrderedDict((
117 ("hg", Mercurial()), 117 ("hg", Mercurial()),
118 ("git", Git()), 118 ("git", Git()),
119 )) 119 ))
120 120
121 def parse_spec(path, line): 121 def parse_spec(path, line):
122 if "=" not in line: 122 if "=" not in line:
123 logging.warning("Invalid line in file %s: %s" % (path, line)) 123 logging.warning("Invalid line in file %s: %s" % (path, line))
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 return 189 return
190 190
191 parenttype = get_repo_type(parentrepo) 191 parenttype = get_repo_type(parentrepo)
192 type = None 192 type = None
193 for key in roots: 193 for key in roots:
194 if key == parenttype or (key in repo_types and type is None): 194 if key == parenttype or (key in repo_types and type is None):
195 type = key 195 type = key
196 if type is None: 196 if type is None:
197 raise Exception("No valid source found to create %s" % target) 197 raise Exception("No valid source found to create %s" % target)
198 198
199 root = repo_types[type].postprocess_url(roots[type]) 199 postprocess_url = repo_types[type].postprocess_url
Sebastian Noack 2015/04/30 13:34:36 Nit, don't repeat yourself: postprocess_url = r
kzar 2015/04/30 14:45:29 Done.
Wladimir Palant 2015/04/30 15:48:30 Rather questionable advise in this context IMHO.
Sebastian Noack 2015/04/30 17:58:28 How is caching one variable lookup + one item look
Wladimir Palant 2015/04/30 18:34:07 If it provides a negligible performance gain while
Sebastian Noack 2015/04/30 18:43:31 I didn't even mention performance. "Don't repeat y
200 sourcename = repo_types[type].postprocess_url(sourcename) 200 root = postprocess_url(roots[type])
201 sourcename = postprocess_url(sourcename)
201 202
202 if os.path.exists(root): 203 if os.path.exists(root):
203 url = os.path.join(root, sourcename) 204 url = os.path.join(root, sourcename)
204 else: 205 else:
205 url = urlparse.urljoin(root, sourcename) 206 url = urlparse.urljoin(root, sourcename)
206 207
207 logging.info("Cloning repository %s into %s" % (url, target)) 208 logging.info("Cloning repository %s into %s" % (url, target))
208 repo_types[type].clone(url, target) 209 repo_types[type].clone(url, target)
209 210
210 for repo in repo_types.itervalues(): 211 for repo in repo_types.itervalues():
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 args = parser.parse_args() 303 args = parser.parse_args()
303 304
304 if args.quiet: 305 if args.quiet:
305 logging.disable(logging.INFO) 306 logging.disable(logging.INFO)
306 307
307 repos = args.repos 308 repos = args.repos
308 if not len(repos): 309 if not len(repos):
309 repos = [os.path.dirname(__file__)] 310 repos = [os.path.dirname(__file__)]
310 for repo in repos: 311 for repo in repos:
311 resolve_deps(repo) 312 resolve_deps(repo)
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld