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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 133 |
134 filepath = os.path.join(self.project_path, p.filename) | 134 filepath = os.path.join(self.project_path, p.filename) |
135 if p.is_binary: | 135 if p.is_binary: |
136 with open(filepath, 'wb') as f: | 136 with open(filepath, 'wb') as f: |
137 f.write(p.get()) | 137 f.write(p.get()) |
138 else: | 138 else: |
139 if p.diff_hunks: | 139 if p.diff_hunks: |
140 stdout = subprocess2.check_output( | 140 stdout = subprocess2.check_output( |
141 ['patch', '-p%s' % p.patchlevel], | 141 ['patch', '-p%s' % p.patchlevel], |
142 stdin=p.get(), | 142 stdin=p.get(), |
| 143 stderr=subprocess2.STDOUT, |
143 cwd=self.project_path) | 144 cwd=self.project_path) |
144 elif p.is_new and not os.path.exists(filepath): | 145 elif p.is_new and not os.path.exists(filepath): |
145 # There is only a header. Just create the file. | 146 # There is only a header. Just create the file. |
146 open(filepath, 'w').close() | 147 open(filepath, 'w').close() |
147 for post in (self.post_processors or []): | 148 for post in (self.post_processors or []): |
148 post(self, p) | 149 post(self, p) |
149 except OSError, e: | 150 except OSError, e: |
150 raise PatchApplicationFailed(p.filename, '%s%s' % (stdout, e)) | 151 raise PatchApplicationFailed(p.filename, '%s%s' % (stdout, e)) |
151 except subprocess.CalledProcessError, e: | 152 except subprocess.CalledProcessError, e: |
152 raise PatchApplicationFailed( | 153 raise PatchApplicationFailed( |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 return subprocess2.check_call_out( | 212 return subprocess2.check_call_out( |
212 self._add_svn_flags(args, False), **kwargs) | 213 self._add_svn_flags(args, False), **kwargs) |
213 | 214 |
214 def _check_output_svn(self, args, credentials=True, **kwargs): | 215 def _check_output_svn(self, args, credentials=True, **kwargs): |
215 """Runs svn and throws an exception if the command failed. | 216 """Runs svn and throws an exception if the command failed. |
216 | 217 |
217 Returns the output. | 218 Returns the output. |
218 """ | 219 """ |
219 kwargs.setdefault('cwd', self.project_path) | 220 kwargs.setdefault('cwd', self.project_path) |
220 return subprocess2.check_output( | 221 return subprocess2.check_output( |
221 self._add_svn_flags(args, True, credentials), **kwargs) | 222 self._add_svn_flags(args, True, credentials), |
| 223 stderr=subprocess2.STDOUT, |
| 224 **kwargs) |
222 | 225 |
223 @staticmethod | 226 @staticmethod |
224 def _parse_svn_info(output, key): | 227 def _parse_svn_info(output, key): |
225 """Returns value for key from svn info output. | 228 """Returns value for key from svn info output. |
226 | 229 |
227 Case insensitive. | 230 Case insensitive. |
228 """ | 231 """ |
229 values = {} | 232 values = {} |
230 key = key.lower() | 233 key = key.lower() |
231 for line in output.splitlines(False): | 234 for line in output.splitlines(False): |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 return subprocess2.check_call_out(['git'] + args, **kwargs) | 492 return subprocess2.check_call_out(['git'] + args, **kwargs) |
490 | 493 |
491 def _call_git(self, args, **kwargs): | 494 def _call_git(self, args, **kwargs): |
492 """Like check_call but doesn't throw on failure.""" | 495 """Like check_call but doesn't throw on failure.""" |
493 kwargs.setdefault('cwd', self.project_path) | 496 kwargs.setdefault('cwd', self.project_path) |
494 kwargs.setdefault('stdout', self.VOID) | 497 kwargs.setdefault('stdout', self.VOID) |
495 return subprocess2.call(['git'] + args, **kwargs) | 498 return subprocess2.call(['git'] + args, **kwargs) |
496 | 499 |
497 def _check_output_git(self, args, **kwargs): | 500 def _check_output_git(self, args, **kwargs): |
498 kwargs.setdefault('cwd', self.project_path) | 501 kwargs.setdefault('cwd', self.project_path) |
499 return subprocess2.check_output(['git'] + args, **kwargs) | 502 return subprocess2.check_output( |
| 503 ['git'] + args, stderr=subprocess2.STDOUT, **kwargs) |
500 | 504 |
501 def _branches(self): | 505 def _branches(self): |
502 """Returns the list of branches and the active one.""" | 506 """Returns the list of branches and the active one.""" |
503 out = self._check_output_git(['branch']).splitlines(False) | 507 out = self._check_output_git(['branch']).splitlines(False) |
504 branches = [l[2:] for l in out] | 508 branches = [l[2:] for l in out] |
505 active = None | 509 active = None |
506 for l in out: | 510 for l in out: |
507 if l.startswith('*'): | 511 if l.startswith('*'): |
508 active = l[2:] | 512 active = l[2:] |
509 break | 513 break |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 user, message)) | 711 user, message)) |
708 return 'FAKE' | 712 return 'FAKE' |
709 | 713 |
710 @property | 714 @property |
711 def project_name(self): | 715 def project_name(self): |
712 return self.checkout.project_name | 716 return self.checkout.project_name |
713 | 717 |
714 @property | 718 @property |
715 def project_path(self): | 719 def project_path(self): |
716 return self.checkout.project_path | 720 return self.checkout.project_path |
OLD | NEW |