| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 Loading... | |
| 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, rev): | 56 def pull(self, repo): |
| 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 Loading... | |
| 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, rev): | 99 def pull(self, repo): |
| 100 # Fetch tracked branches, new tags and the list of available remote branches | |
| 100 subprocess.check_call(["git", "fetch", "--quiet", "--all", "--tags"], cwd=re po) | 101 subprocess.check_call(["git", "fetch", "--quiet", "--all", "--tags"], cwd=re po) |
| 101 subprocess.check_call(["git", "checkout", rev], cwd=repo) | 102 # Next we need to ensure all remote branches are tracked |
|
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.
| |
| 103 newly_tracked = False | |
| 104 remotes = subprocess.check_output(["git", "branch", "--remotes"], cwd=repo) | |
| 105 for match in re.finditer(r"^\s*(origin/(\S+))$", remotes, re.M): | |
| 106 remote, local = match.groups() | |
| 107 with open(os.devnull, "wb") as devnull: | |
| 108 if subprocess.call(["git", "branch", "--track", local, remote], | |
| 109 cwd=repo, stdout=devnull, stderr=devnull) == 0: | |
| 110 newly_tracked = True | |
| 111 # Finally fetch any newly tracked remote branches | |
| 112 if newly_tracked: | |
| 113 subprocess.check_call(["git", "fetch", "--quiet", "origin"], cwd=repo) | |
| 102 | 114 |
| 103 def update(self, repo, rev): | 115 def update(self, repo, rev): |
| 104 subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo) | 116 subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo) |
| 105 | 117 |
| 106 def ignore(self, target, repo): | 118 def ignore(self, target, repo): |
| 107 module = os.path.relpath(target, repo) | 119 module = os.path.relpath(target, repo) |
| 108 exclude_file = os.path.join(repo, ".git", "info", "exclude") | 120 exclude_file = os.path.join(repo, ".git", "info", "exclude") |
| 109 _ensure_line_exists(exclude_file, module) | 121 _ensure_line_exists(exclude_file, module) |
| 110 | 122 |
| 111 def postprocess_url(self, url): | 123 def postprocess_url(self, url): |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 if spec: | 173 if spec: |
| 162 result[key] = spec | 174 result[key] = spec |
| 163 return result | 175 return result |
| 164 except IOError, e: | 176 except IOError, e: |
| 165 if e.errno != errno.ENOENT: | 177 if e.errno != errno.ENOENT: |
| 166 raise | 178 raise |
| 167 return None | 179 return None |
| 168 | 180 |
| 169 def safe_join(path, subpath): | 181 def safe_join(path, subpath): |
| 170 # This has been inspired by Flask's safe_join() function | 182 # This has been inspired by Flask's safe_join() function |
| 171 forbidden = set([os.sep, os.altsep]) - set([posixpath.sep, None]) | 183 forbidden = {os.sep, os.altsep} - {posixpath.sep, None} |
| 172 if any(sep in subpath for sep in forbidden): | 184 if any(sep in subpath for sep in forbidden): |
| 173 raise Exception("Illegal directory separator in dependency path %s" % subpat h) | 185 raise Exception("Illegal directory separator in dependency path %s" % subpat h) |
| 174 | 186 |
| 175 normpath = posixpath.normpath(subpath) | 187 normpath = posixpath.normpath(subpath) |
| 176 if posixpath.isabs(normpath): | 188 if posixpath.isabs(normpath): |
| 177 raise Exception("Dependency path %s cannot be absolute" % subpath) | 189 raise Exception("Dependency path %s cannot be absolute" % subpath) |
| 178 if normpath == posixpath.pardir or normpath.startswith(posixpath.pardir + posi xpath.sep): | 190 if normpath == posixpath.pardir or normpath.startswith(posixpath.pardir + posi xpath.sep): |
| 179 raise Exception("Dependency path %s has to be inside the repository" % subpa th) | 191 raise Exception("Dependency path %s has to be inside the repository" % subpa th) |
| 180 return os.path.join(path, *normpath.split(posixpath.sep)) | 192 return os.path.join(path, *normpath.split(posixpath.sep)) |
| 181 | 193 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 revision = revisions[type] | 235 revision = revisions[type] |
| 224 elif "*" in revisions: | 236 elif "*" in revisions: |
| 225 revision = revisions["*"] | 237 revision = revisions["*"] |
| 226 else: | 238 else: |
| 227 logging.warning("No revision specified for repository %s (type %s), skipping update" % (target, type)) | 239 logging.warning("No revision specified for repository %s (type %s), skipping update" % (target, type)) |
| 228 return | 240 return |
| 229 | 241 |
| 230 resolved_revision = repo_types[type].get_revision_id(target, revision) | 242 resolved_revision = repo_types[type].get_revision_id(target, revision) |
| 231 if not resolved_revision: | 243 if not resolved_revision: |
| 232 logging.info("Revision %s is unknown, downloading remote changes" % revision ) | 244 logging.info("Revision %s is unknown, downloading remote changes" % revision ) |
| 233 repo_types[type].pull(target, revision) | 245 repo_types[type].pull(target) |
| 234 resolved_revision = repo_types[type].get_revision_id(target, revision) | 246 resolved_revision = repo_types[type].get_revision_id(target, revision) |
| 235 if not resolved_revision: | 247 if not resolved_revision: |
| 236 raise Exception("Failed to resolve revision %s" % revision) | 248 raise Exception("Failed to resolve revision %s" % revision) |
| 237 | 249 |
| 238 current_revision = repo_types[type].get_revision_id(target) | 250 current_revision = repo_types[type].get_revision_id(target) |
| 239 if resolved_revision != current_revision: | 251 if resolved_revision != current_revision: |
| 240 logging.info("Updating repository %s to revision %s" % (target, resolved_rev ision)) | 252 logging.info("Updating repository %s to revision %s" % (target, resolved_rev ision)) |
| 241 repo_types[type].update(target, resolved_revision) | 253 repo_types[type].update(target, resolved_revision) |
| 242 | 254 |
| 243 def resolve_deps(repodir, level=0, self_update=True, overrideroots=None, skipdep endencies=set()): | 255 def resolve_deps(repodir, level=0, self_update=True, overrideroots=None, skipdep endencies=set()): |
| 244 config = read_deps(repodir) | 256 config = read_deps(repodir) |
| 245 if config is None: | 257 if config is None: |
| 246 if level == 0: | 258 if level == 0: |
| 247 logging.warning("No dependencies file in directory %s, nothing to do...\n% s" % (repodir, USAGE)) | 259 logging.warning("No dependencies file in directory %s, nothing to do...\n% s" % (repodir, USAGE)) |
| 248 return | 260 return |
| 249 if level >= 10: | 261 if level >= 10: |
| 250 logging.warning("Too much subrepository nesting, ignoring %s" % repo) | 262 logging.warning("Too much subrepository nesting, ignoring %s" % repo) |
| 263 return | |
| 251 | 264 |
| 252 if overrideroots is not None: | 265 if overrideroots is not None: |
| 253 config["_root"] = overrideroots | 266 config["_root"] = overrideroots |
| 254 | 267 |
| 255 for dir, revisions in config.iteritems(): | 268 for dir, revisions in config.iteritems(): |
| 256 if dir.startswith("_") or revisions["_source"] in skipdependencies: | 269 if dir.startswith("_") or revisions["_source"] in skipdependencies: |
| 257 continue | 270 continue |
| 258 target = safe_join(repodir, dir) | 271 target = safe_join(repodir, dir) |
| 259 ensure_repo(repodir, target, config.get("_root", {}), revisions["_source"]) | 272 ensure_repo(repodir, target, config.get("_root", {}), revisions["_source"]) |
| 260 update_repo(target, revisions) | 273 update_repo(target, revisions) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 args = parser.parse_args() | 317 args = parser.parse_args() |
| 305 | 318 |
| 306 if args.quiet: | 319 if args.quiet: |
| 307 logging.disable(logging.INFO) | 320 logging.disable(logging.INFO) |
| 308 | 321 |
| 309 repos = args.repos | 322 repos = args.repos |
| 310 if not len(repos): | 323 if not len(repos): |
| 311 repos = [os.path.dirname(__file__)] | 324 repos = [os.path.dirname(__file__)] |
| 312 for repo in repos: | 325 for repo in repos: |
| 313 resolve_deps(repo) | 326 resolve_deps(repo) |
| LEFT | RIGHT |