OLD | NEW |
1 # coding=utf8 | 1 # coding=utf8 |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 """Manages a project checkout. | 5 """Manages a project checkout. |
6 | 6 |
7 Includes support for svn, git-svn and git. | 7 Includes support for svn, git-svn and git. |
8 """ | 8 """ |
9 | 9 |
10 from __future__ import with_statement | 10 from __future__ import with_statement |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 class CheckoutBase(object): | 58 class CheckoutBase(object): |
59 # Set to None to have verbose output. | 59 # Set to None to have verbose output. |
60 VOID = subprocess2.VOID | 60 VOID = subprocess2.VOID |
61 | 61 |
62 def __init__(self, root_dir, project_name, post_processors): | 62 def __init__(self, root_dir, project_name, post_processors): |
63 """ | 63 """ |
64 Args: | 64 Args: |
65 post_processor: list of lambda(checkout, patches) to call on each of the | 65 post_processor: list of lambda(checkout, patches) to call on each of the |
66 modified files. | 66 modified files. |
67 """ | 67 """ |
| 68 super(CheckoutBase, self).__init__() |
68 self.root_dir = root_dir | 69 self.root_dir = root_dir |
69 self.project_name = project_name | 70 self.project_name = project_name |
70 if self.project_name is None: | 71 if self.project_name is None: |
71 self.project_path = self.root_dir | 72 self.project_path = self.root_dir |
72 else: | 73 else: |
73 self.project_path = os.path.join(self.root_dir, self.project_name) | 74 self.project_path = os.path.join(self.root_dir, self.project_name) |
74 # Only used for logging purposes. | 75 # Only used for logging purposes. |
75 self._last_seen_revision = None | 76 self._last_seen_revision = None |
76 self.post_processors = None | 77 self.post_processors = post_processors |
77 assert self.root_dir | 78 assert self.root_dir |
78 assert self.project_path | 79 assert self.project_path |
79 | 80 |
80 def get_settings(self, key): | 81 def get_settings(self, key): |
81 return get_code_review_setting(self.project_path, key) | 82 return get_code_review_setting(self.project_path, key) |
82 | 83 |
83 def prepare(self, revision): | 84 def prepare(self, revision): |
84 """Checks out a clean copy of the tree and removes any local modification. | 85 """Checks out a clean copy of the tree and removes any local modification. |
85 | 86 |
86 This function shouldn't throw unless the remote repository is inaccessible, | 87 This function shouldn't throw unless the remote repository is inaccessible, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 p.filename, '%s%s' % (stdout, getattr(e, 'stdout', None))) | 153 p.filename, '%s%s' % (stdout, getattr(e, 'stdout', None))) |
153 | 154 |
154 def commit(self, commit_message, user): | 155 def commit(self, commit_message, user): |
155 """Stubbed out.""" | 156 """Stubbed out.""" |
156 raise NotImplementedError('RawCheckout can\'t commit') | 157 raise NotImplementedError('RawCheckout can\'t commit') |
157 | 158 |
158 | 159 |
159 class SvnConfig(object): | 160 class SvnConfig(object): |
160 """Parses a svn configuration file.""" | 161 """Parses a svn configuration file.""" |
161 def __init__(self, svn_config_dir=None): | 162 def __init__(self, svn_config_dir=None): |
| 163 super(SvnConfig, self).__init__() |
162 self.svn_config_dir = svn_config_dir | 164 self.svn_config_dir = svn_config_dir |
163 self.default = not bool(self.svn_config_dir) | 165 self.default = not bool(self.svn_config_dir) |
164 if not self.svn_config_dir: | 166 if not self.svn_config_dir: |
165 if sys.platform == 'win32': | 167 if sys.platform == 'win32': |
166 self.svn_config_dir = os.path.join(os.environ['APPDATA'], 'Subversion') | 168 self.svn_config_dir = os.path.join(os.environ['APPDATA'], 'Subversion') |
167 else: | 169 else: |
168 self.svn_config_dir = os.path.join(os.environ['HOME'], '.subversion') | 170 self.svn_config_dir = os.path.join(os.environ['HOME'], '.subversion') |
169 svn_config_file = os.path.join(self.svn_config_dir, 'config') | 171 svn_config_file = os.path.join(self.svn_config_dir, 'config') |
170 parser = ConfigParser.SafeConfigParser() | 172 parser = ConfigParser.SafeConfigParser() |
171 if os.path.isfile(svn_config_file): | 173 if os.path.isfile(svn_config_file): |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 v = v.strip() | 236 v = v.strip() |
235 assert not k in values | 237 assert not k in values |
236 values[k] = v | 238 values[k] = v |
237 return values.get(key, None) | 239 return values.get(key, None) |
238 | 240 |
239 | 241 |
240 class SvnCheckout(CheckoutBase, SvnMixIn): | 242 class SvnCheckout(CheckoutBase, SvnMixIn): |
241 """Manages a subversion checkout.""" | 243 """Manages a subversion checkout.""" |
242 def __init__(self, root_dir, project_name, commit_user, commit_pwd, svn_url, | 244 def __init__(self, root_dir, project_name, commit_user, commit_pwd, svn_url, |
243 post_processors=None): | 245 post_processors=None): |
244 super(SvnCheckout, self).__init__(root_dir, project_name, post_processors) | 246 CheckoutBase.__init__(self, root_dir, project_name, post_processors) |
| 247 SvnMixIn.__init__(self) |
245 self.commit_user = commit_user | 248 self.commit_user = commit_user |
246 self.commit_pwd = commit_pwd | 249 self.commit_pwd = commit_pwd |
247 self.svn_url = svn_url | 250 self.svn_url = svn_url |
248 assert bool(self.commit_user) >= bool(self.commit_pwd) | 251 assert bool(self.commit_user) >= bool(self.commit_pwd) |
249 | 252 |
250 def prepare(self, revision): | 253 def prepare(self, revision): |
251 # Will checkout if the directory is not present. | 254 # Will checkout if the directory is not present. |
252 assert self.svn_url | 255 assert self.svn_url |
253 if not os.path.isdir(self.project_path): | 256 if not os.path.isdir(self.project_path): |
254 logging.info('Checking out %s in %s' % | 257 logging.info('Checking out %s in %s' % |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 return branches, active | 510 return branches, active |
508 | 511 |
509 | 512 |
510 class GitSvnCheckoutBase(GitCheckoutBase, SvnMixIn): | 513 class GitSvnCheckoutBase(GitCheckoutBase, SvnMixIn): |
511 """Base class for git-svn checkout. Not to be used as-is.""" | 514 """Base class for git-svn checkout. Not to be used as-is.""" |
512 def __init__(self, | 515 def __init__(self, |
513 root_dir, project_name, remote_branch, | 516 root_dir, project_name, remote_branch, |
514 commit_user, commit_pwd, | 517 commit_user, commit_pwd, |
515 svn_url, trunk, post_processors=None): | 518 svn_url, trunk, post_processors=None): |
516 """trunk is optional.""" | 519 """trunk is optional.""" |
517 super(GitSvnCheckoutBase, self).__init__( | 520 GitCheckoutBase.__init__( |
518 root_dir, project_name + '.git', remote_branch, post_processors) | 521 self, root_dir, project_name + '.git', remote_branch, post_processors) |
| 522 SvnMixIn.__init__(self) |
519 self.commit_user = commit_user | 523 self.commit_user = commit_user |
520 self.commit_pwd = commit_pwd | 524 self.commit_pwd = commit_pwd |
521 # svn_url in this case is the root of the svn repository. | 525 # svn_url in this case is the root of the svn repository. |
522 self.svn_url = svn_url | 526 self.svn_url = svn_url |
523 self.trunk = trunk | 527 self.trunk = trunk |
524 assert bool(self.commit_user) >= bool(self.commit_pwd) | 528 assert bool(self.commit_user) >= bool(self.commit_pwd) |
525 assert self.svn_url | 529 assert self.svn_url |
526 assert self.trunk | 530 assert self.trunk |
527 self._cache_svn_auth() | 531 self._cache_svn_auth() |
528 | 532 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 self.svn_url, self.project_path, | 683 self.svn_url, self.project_path, |
680 '--quiet'], | 684 '--quiet'], |
681 cwd=self.root_dir, | 685 cwd=self.root_dir, |
682 stderr=subprocess2.STDOUT) | 686 stderr=subprocess2.STDOUT) |
683 return super(GitSvnCheckout, self).prepare(revision) | 687 return super(GitSvnCheckout, self).prepare(revision) |
684 | 688 |
685 | 689 |
686 class ReadOnlyCheckout(object): | 690 class ReadOnlyCheckout(object): |
687 """Converts a checkout into a read-only one.""" | 691 """Converts a checkout into a read-only one.""" |
688 def __init__(self, checkout): | 692 def __init__(self, checkout): |
| 693 super(ReadOnlyCheckout, self).__init__() |
689 self.checkout = checkout | 694 self.checkout = checkout |
690 | 695 |
691 def prepare(self, revision): | 696 def prepare(self, revision): |
692 return self.checkout.prepare(revision) | 697 return self.checkout.prepare(revision) |
693 | 698 |
694 def get_settings(self, key): | 699 def get_settings(self, key): |
695 return self.checkout.get_settings(key) | 700 return self.checkout.get_settings(key) |
696 | 701 |
697 def apply_patch(self, patches): | 702 def apply_patch(self, patches): |
698 return self.checkout.apply_patch(patches) | 703 return self.checkout.apply_patch(patches) |
699 | 704 |
700 def commit(self, message, user): # pylint: disable=R0201 | 705 def commit(self, message, user): # pylint: disable=R0201 |
701 logging.info('Would have committed for %s with message: %s' % ( | 706 logging.info('Would have committed for %s with message: %s' % ( |
702 user, message)) | 707 user, message)) |
703 return 'FAKE' | 708 return 'FAKE' |
704 | 709 |
705 @property | 710 @property |
706 def project_name(self): | 711 def project_name(self): |
707 return self.checkout.project_name | 712 return self.checkout.project_name |
708 | 713 |
709 @property | 714 @property |
710 def project_path(self): | 715 def project_path(self): |
711 return self.checkout.project_path | 716 return self.checkout.project_path |
OLD | NEW |