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

Side by Side Diff: ensure_dependencies.py

Issue 6068640302497792: Issue 2311 - Track remote Git branches when required (Closed)
Patch Set: Created April 30, 2015, 5:30 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 def get_revision_id(self, repo, rev=None): 46 def get_revision_id(self, repo, rev=None):
47 command = ["hg", "id", "--repository", repo, "--id"] 47 command = ["hg", "id", "--repository", repo, "--id"]
48 if rev: 48 if rev:
49 command.extend(["--rev", rev]) 49 command.extend(["--rev", rev])
50 50
51 # Ignore stderr output and return code here: if revision lookup failed we 51 # Ignore stderr output and return code here: if revision lookup failed we
52 # should simply return an empty string. 52 # should simply return an empty string.
53 result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess .PIPE).communicate()[0] 53 result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess .PIPE).communicate()[0]
54 return result.strip() 54 return result.strip()
55 55
56 def pull(self, repo): 56 def pull(self, repo, rev):
57 subprocess.check_call(["hg", "pull", "--repository", repo, "--quiet"]) 57 subprocess.check_call(["hg", "pull", "--repository", repo, "--quiet"])
58 58
59 def update(self, repo, rev): 59 def update(self, repo, rev):
60 subprocess.check_call(["hg", "update", "--repository", repo, "--quiet", "--c heck", "--rev", rev]) 60 subprocess.check_call(["hg", "update", "--repository", repo, "--quiet", "--c heck", "--rev", rev])
61 61
62 def ignore(self, target, repo): 62 def ignore(self, target, repo):
63 63
64 if not self.istype(target): 64 if not self.istype(target):
65 65
66 config_path = os.path.join(repo, ".hg", "hgrc") 66 config_path = os.path.join(repo, ".hg", "hgrc")
(...skipping 22 matching lines...) Expand all
89 def clone(self, source, target): 89 def clone(self, source, target):
90 source = source.rstrip("/") 90 source = source.rstrip("/")
91 if not source.endswith(".git"): 91 if not source.endswith(".git"):
92 source += ".git" 92 source += ".git"
93 subprocess.check_call(["git", "clone", "--quiet", source, target]) 93 subprocess.check_call(["git", "clone", "--quiet", source, target])
94 94
95 def get_revision_id(self, repo, rev="HEAD"): 95 def get_revision_id(self, repo, rev="HEAD"):
96 command = ["git", "rev-parse", "--revs-only", rev + '^{commit}'] 96 command = ["git", "rev-parse", "--revs-only", rev + '^{commit}']
97 return subprocess.check_output(command, cwd=repo).strip() 97 return subprocess.check_output(command, cwd=repo).strip()
98 98
99 def pull(self, repo): 99 def pull(self, repo, rev):
100 subprocess.check_call(["git", "fetch", "--quiet", "--all", "--tags"], cwd=re po) 100 subprocess.check_call(["git", "fetch", "--quiet", "--all", "--tags"], cwd=re po)
101 subprocess.check_call(["git", "checkout", rev], cwd=repo)
Sebastian Noack 2015/04/30 17:54:34 Wasn't the problem you try to address here, that b
kzar 2015/04/30 19:31:46 So it turns out the remote branches are fetched, t
Sebastian Noack 2015/04/30 20:53:57 Isn't this call redundant with the one in Git.upda
kzar 2015/05/01 09:43:55 As of Git 1.6.6 [1] checking out a local branch wh
Sebastian Noack 2015/05/04 11:44:31 If I understand the issue correctly, this change i
kzar 2015/05/05 13:33:55 Then you do not understand this change properly. W
Sebastian Noack 2015/05/05 15:08:54 Ok, got it. But this still seems like a silly hack
kzar 2015/05/05 15:26:52 The remote branch has already been fetched, we jus
Sebastian Noack 2015/05/05 16:00:54 I think I'd prefer that one. If something went wro
Sebastian Noack 2015/05/05 16:59:02 But either way, this will only work if you specify
Sebastian Noack 2015/05/05 17:35:05 After thinking a little more about the problem and
kzar 2015/05/06 11:04:44 Done.
101 102
102 def update(self, repo, rev): 103 def update(self, repo, rev):
103 subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo) 104 subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo)
104 105
105 def ignore(self, target, repo): 106 def ignore(self, target, repo):
106 module = os.path.relpath(target, repo) 107 module = os.path.relpath(target, repo)
107 exclude_file = os.path.join(repo, ".git", "info", "exclude") 108 exclude_file = os.path.join(repo, ".git", "info", "exclude")
108 _ensure_line_exists(exclude_file, module) 109 _ensure_line_exists(exclude_file, module)
109 110
110 def postprocess_url(self, url): 111 def postprocess_url(self, url):
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 revision = revisions[type] 223 revision = revisions[type]
223 elif "*" in revisions: 224 elif "*" in revisions:
224 revision = revisions["*"] 225 revision = revisions["*"]
225 else: 226 else:
226 logging.warning("No revision specified for repository %s (type %s), skipping update" % (target, type)) 227 logging.warning("No revision specified for repository %s (type %s), skipping update" % (target, type))
227 return 228 return
228 229
229 resolved_revision = repo_types[type].get_revision_id(target, revision) 230 resolved_revision = repo_types[type].get_revision_id(target, revision)
230 if not resolved_revision: 231 if not resolved_revision:
231 logging.info("Revision %s is unknown, downloading remote changes" % revision ) 232 logging.info("Revision %s is unknown, downloading remote changes" % revision )
232 repo_types[type].pull(target) 233 repo_types[type].pull(target, revision)
233 resolved_revision = repo_types[type].get_revision_id(target, revision) 234 resolved_revision = repo_types[type].get_revision_id(target, revision)
234 if not resolved_revision: 235 if not resolved_revision:
235 raise Exception("Failed to resolve revision %s" % revision) 236 raise Exception("Failed to resolve revision %s" % revision)
236 237
237 current_revision = repo_types[type].get_revision_id(target) 238 current_revision = repo_types[type].get_revision_id(target)
238 if resolved_revision != current_revision: 239 if resolved_revision != current_revision:
239 logging.info("Updating repository %s to revision %s" % (target, resolved_rev ision)) 240 logging.info("Updating repository %s to revision %s" % (target, resolved_rev ision))
240 repo_types[type].update(target, resolved_revision) 241 repo_types[type].update(target, resolved_revision)
241 242
242 def resolve_deps(repodir, level=0, self_update=True, overrideroots=None, skipdep endencies=set()): 243 def resolve_deps(repodir, level=0, self_update=True, overrideroots=None, skipdep endencies=set()):
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 args = parser.parse_args() 304 args = parser.parse_args()
304 305
305 if args.quiet: 306 if args.quiet:
306 logging.disable(logging.INFO) 307 logging.disable(logging.INFO)
307 308
308 repos = args.repos 309 repos = args.repos
309 if not len(repos): 310 if not len(repos):
310 repos = [os.path.dirname(__file__)] 311 repos = [os.path.dirname(__file__)]
311 for repo in repos: 312 for repo in repos:
312 resolve_deps(repo) 313 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