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

Side by Side Diff: ensure_dependencies.py

Issue 29329559: Noissue - Avoid "detached head" when using Git branches (Closed)
Patch Set: Name parameters consistently Created Nov. 10, 2015, 12:20 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 command.extend(["--rev", rev]) 59 command.extend(["--rev", rev])
60 60
61 # Ignore stderr output and return code here: if revision lookup failed we 61 # Ignore stderr output and return code here: if revision lookup failed we
62 # should simply return an empty string. 62 # should simply return an empty string.
63 result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess .PIPE).communicate()[0] 63 result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess .PIPE).communicate()[0]
64 return result.strip() 64 return result.strip()
65 65
66 def pull(self, repo): 66 def pull(self, repo):
67 subprocess.check_call(["hg", "pull", "--repository", repo, "--quiet"]) 67 subprocess.check_call(["hg", "pull", "--repository", repo, "--quiet"])
68 68
69 def update(self, repo, rev): 69 def update(self, repo, rev, revname):
70 subprocess.check_call(["hg", "update", "--repository", repo, "--quiet", "--c heck", "--rev", rev]) 70 subprocess.check_call(["hg", "update", "--repository", repo, "--quiet", "--c heck", "--rev", rev])
71 71
72 def ignore(self, target, repo): 72 def ignore(self, target, repo):
73 73
74 if not self.istype(target): 74 if not self.istype(target):
75 75
76 config_path = os.path.join(repo, ".hg", "hgrc") 76 config_path = os.path.join(repo, ".hg", "hgrc")
77 ignore_path = os.path.abspath(os.path.join(repo, ".hg", "dependencies")) 77 ignore_path = os.path.abspath(os.path.join(repo, ".hg", "dependencies"))
78 78
79 config = RawConfigParser() 79 config = RawConfigParser()
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 for match in re.finditer(r"^\s*(origin/(\S+))$", remotes, re.M): 115 for match in re.finditer(r"^\s*(origin/(\S+))$", remotes, re.M):
116 remote, local = match.groups() 116 remote, local = match.groups()
117 with open(os.devnull, "wb") as devnull: 117 with open(os.devnull, "wb") as devnull:
118 if subprocess.call(["git", "branch", "--track", local, remote], 118 if subprocess.call(["git", "branch", "--track", local, remote],
119 cwd=repo, stdout=devnull, stderr=devnull) == 0: 119 cwd=repo, stdout=devnull, stderr=devnull) == 0:
120 newly_tracked = True 120 newly_tracked = True
121 # Finally fetch any newly tracked remote branches 121 # Finally fetch any newly tracked remote branches
122 if newly_tracked: 122 if newly_tracked:
123 subprocess.check_call(["git", "fetch", "--quiet", "origin"], cwd=repo) 123 subprocess.check_call(["git", "fetch", "--quiet", "origin"], cwd=repo)
124 124
125 def update(self, repo, rev): 125 def update(self, repo, rev, revname):
126 subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo) 126 subprocess.check_call(["git", "checkout", "--quiet", revname], cwd=repo)
127 127
128 def ignore(self, target, repo): 128 def ignore(self, target, repo):
129 module = os.path.sep + os.path.relpath(target, repo) 129 module = os.path.sep + os.path.relpath(target, repo)
130 exclude_file = os.path.join(repo, ".git", "info", "exclude") 130 exclude_file = os.path.join(repo, ".git", "info", "exclude")
131 _ensure_line_exists(exclude_file, module) 131 _ensure_line_exists(exclude_file, module)
132 132
133 def postprocess_url(self, url): 133 def postprocess_url(self, url):
134 # Handle alternative syntax of SSH URLS 134 # Handle alternative syntax of SSH URLS
135 if "@" in url and ":" in url and not urlparse.urlsplit(url).scheme: 135 if "@" in url and ":" in url and not urlparse.urlsplit(url).scheme:
136 return "ssh://" + url.replace(":", "/", 1) 136 return "ssh://" + url.replace(":", "/", 1)
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 return 273 return
274 274
275 if not resolved_revision: 275 if not resolved_revision:
276 logging.info("Revision %s is unknown, downloading remote changes" % revisi on) 276 logging.info("Revision %s is unknown, downloading remote changes" % revisi on)
277 repo_types[type].pull(target) 277 repo_types[type].pull(target)
278 resolved_revision = repo_types[type].get_revision_id(target, revision) 278 resolved_revision = repo_types[type].get_revision_id(target, revision)
279 if not resolved_revision: 279 if not resolved_revision:
280 raise Exception("Failed to resolve revision %s" % revision) 280 raise Exception("Failed to resolve revision %s" % revision)
281 281
282 logging.info("Updating repository %s to revision %s" % (target, resolved_rev ision)) 282 logging.info("Updating repository %s to revision %s" % (target, resolved_rev ision))
283 repo_types[type].update(target, resolved_revision) 283 repo_types[type].update(target, resolved_revision, revision)
284 284
285 def resolve_deps(repodir, level=0, self_update=True, overrideroots=None, skipdep endencies=set()): 285 def resolve_deps(repodir, level=0, self_update=True, overrideroots=None, skipdep endencies=set()):
286 config = read_deps(repodir) 286 config = read_deps(repodir)
287 if config is None: 287 if config is None:
288 if level == 0: 288 if level == 0:
289 logging.warning("No dependencies file in directory %s, nothing to do...\n% s" % (repodir, USAGE)) 289 logging.warning("No dependencies file in directory %s, nothing to do...\n% s" % (repodir, USAGE))
290 return 290 return
291 if level >= 10: 291 if level >= 10:
292 logging.warning("Too much subrepository nesting, ignoring %s" % repo) 292 logging.warning("Too much subrepository nesting, ignoring %s" % repo)
293 return 293 return
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 args = parser.parse_args() 362 args = parser.parse_args()
363 363
364 if args.quiet: 364 if args.quiet:
365 logging.disable(logging.INFO) 365 logging.disable(logging.INFO)
366 366
367 repos = args.repos 367 repos = args.repos
368 if not len(repos): 368 if not len(repos):
369 repos = [os.path.dirname(__file__)] 369 repos = [os.path.dirname(__file__)]
370 for repo in repos: 370 for repo in repos:
371 resolve_deps(repo) 371 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