Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import ast | 5 import ast |
| 6 import collections | 6 import collections |
| 7 import contextlib | 7 import contextlib |
| 8 import copy | 8 import copy |
| 9 import functools | 9 import functools |
| 10 import itertools | 10 import itertools |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 self.repo = repo | 189 self.repo = repo |
| 190 self.branch = branch | 190 self.branch = branch |
| 191 self.revision = revision | 191 self.revision = revision |
| 192 self.path = path | 192 self.path = path |
| 193 | 193 |
| 194 def __str__(self): | 194 def __str__(self): |
| 195 return ('GitRepoSpec{project_id="%(project_id)s", repo="%(repo)s", ' | 195 return ('GitRepoSpec{project_id="%(project_id)s", repo="%(repo)s", ' |
| 196 'branch="%(branch)s", revision="%(revision)s", ' | 196 'branch="%(branch)s", revision="%(revision)s", ' |
| 197 'path="%(path)s"}' % self.__dict__) | 197 'path="%(path)s"}' % self.__dict__) |
| 198 | 198 |
| 199 def run_git(self, cwd, *args): | |
| 200 _run_cmd([self._git, '--git-dir', os.path.join(cwd, '.git')] + list(args)) | |
| 201 | |
| 199 def checkout(self, context): | 202 def checkout(self, context): |
| 200 dep_dir = self._dep_dir(context) | 203 dep_dir = self._dep_dir(context) |
| 201 logging.info('Freshening repository %s' % dep_dir) | 204 logging.info('Freshening repository %s' % dep_dir) |
| 202 | 205 |
| 203 if not os.path.isdir(dep_dir): | 206 if not os.path.isdir(dep_dir): |
| 204 _run_cmd([self._git, 'clone', self.repo, dep_dir]) | 207 _run_cmd([self._git, 'clone', self.repo, dep_dir]) |
| 205 elif not os.path.isdir(os.path.join(dep_dir, '.git')): | 208 elif not os.path.isdir(os.path.join(dep_dir, '.git')): |
| 206 raise UncleanFilesystemError('%s exists but is not a git repo' % dep_dir) | 209 raise UncleanFilesystemError('%s exists but is not a git repo' % dep_dir) |
| 207 | 210 |
| 208 try: | 211 try: |
| 209 subprocess.check_output([self._git, 'rev-parse', '-q', '--verify', | 212 self.run_git(dep_dir, 'rev-parse', '-q', '--verify', |
| 210 '%s^{commit}' % self.revision], cwd=dep_dir) | 213 '%s^{commit}' % self.revision) |
| 211 except subprocess.CalledProcessError: | 214 except subprocess.CalledProcessError: |
| 212 _run_cmd([self._git, 'fetch'], cwd=dep_dir) | 215 self.run_git(dep_dir, 'fetch') |
| 213 _run_cmd([self._git, 'reset', '-q', '--hard', self.revision], cwd=dep_dir) | 216 self.run_git(dep_dir, 'reset', '-q', '--hard', self.revision) |
| 214 | 217 |
| 215 def check_checkout(self, context): | 218 def check_checkout(self, context): |
| 216 dep_dir = self._dep_dir(context) | 219 dep_dir = self._dep_dir(context) |
| 217 if not os.path.isdir(dep_dir): | 220 if not os.path.isdir(dep_dir): |
| 218 raise UncleanFilesystemError('Dependency %s does not exist' % | 221 raise UncleanFilesystemError('Dependency %s does not exist' % |
| 219 dep_dir) | 222 dep_dir) |
| 220 elif not os.path.isdir(os.path.join(dep_dir, '.git')): | 223 elif not os.path.isdir(os.path.join(dep_dir, '.git')): |
| 221 raise UncleanFilesystemError('Dependency %s is not a git repo' % | 224 raise UncleanFilesystemError('Dependency %s is not a git repo' % |
| 222 dep_dir) | 225 dep_dir) |
| 223 | 226 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 252 for rev in lines: | 255 for rev in lines: |
| 253 info = self._get_commit_info(rev, context) | 256 info = self._get_commit_info(rev, context) |
| 254 updates.append(RepoUpdate( | 257 updates.append(RepoUpdate( |
| 255 GitRepoSpec(self.project_id, self.repo, self.branch, rev, | 258 GitRepoSpec(self.project_id, self.repo, self.branch, rev, |
| 256 self.path), | 259 self.path), |
| 257 commit_infos=(info,))) | 260 commit_infos=(info,))) |
| 258 return updates | 261 return updates |
| 259 | 262 |
| 260 def _raw_updates(self, context, subdir): | 263 def _raw_updates(self, context, subdir): |
| 261 self.checkout(context) | 264 self.checkout(context) |
| 262 _run_cmd([self._git, 'fetch'], cwd=self._dep_dir(context)) | 265 self.run_git(self._dep_dir(context), fetch) |
|
Paweł Hajdan Jr.
2016/03/31 17:35:37
Shouldn't fetch be changed to 'fetch'? Just checki
dnj
2016/03/31 17:47:50
Done.
| |
| 263 args = [self._git, 'rev-list', '--reverse', | 266 args = [self._git, 'rev-list', '--reverse', |
| 264 '%s..origin/%s' % (self.revision, self.branch)] | 267 '%s..origin/%s' % (self.revision, self.branch)] |
| 265 if subdir: | 268 if subdir: |
| 266 # We add proto_file to the list of paths to check because it might contain | 269 # We add proto_file to the list of paths to check because it might contain |
| 267 # other upstream rolls, which we want. | 270 # other upstream rolls, which we want. |
| 268 args.extend(['--', subdir + os.path.sep, self.proto_file(context).path]) | 271 args.extend(['--', subdir + os.path.sep, self.proto_file(context).path]) |
| 269 git = subprocess.Popen( | 272 git = subprocess.Popen( |
| 270 args, stdout=subprocess.PIPE, cwd=self._dep_dir(context)) | 273 args, stdout=subprocess.PIPE, cwd=self._dep_dir(context)) |
| 271 (stdout, _) = git.communicate() | 274 (stdout, _) = git.communicate() |
| 272 return stdout | 275 return stdout |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 731 >>> d = { 'x': 1, 'y': 2 } | 734 >>> d = { 'x': 1, 'y': 2 } |
| 732 >>> sorted(_updated(d, { 'y': 3, 'z': 4 }).items()) | 735 >>> sorted(_updated(d, { 'y': 3, 'z': 4 }).items()) |
| 733 [('x', 1), ('y', 3), ('z', 4)] | 736 [('x', 1), ('y', 3), ('z', 4)] |
| 734 >>> sorted(d.items()) | 737 >>> sorted(d.items()) |
| 735 [('x', 1), ('y', 2)] | 738 [('x', 1), ('y', 2)] |
| 736 """ | 739 """ |
| 737 | 740 |
| 738 d = copy.copy(d) | 741 d = copy.copy(d) |
| 739 d.update(updates) | 742 d.update(updates) |
| 740 return d | 743 return d |
| OLD | NEW |