blob: 30887575593c8fe1255af09bbaa76340c37714b4 [file] [log] [blame]
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +00001# coding=utf8
maruel@chromium.org9799a072012-01-11 00:26:25 +00002# Copyright (c) 2012 The Chromium Authors. All rights reserved.
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +00003# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5"""Manages a project checkout.
6
7Includes support for svn, git-svn and git.
8"""
9
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +000010import ConfigParser
11import fnmatch
12import logging
13import os
14import re
maruel@chromium.org5e975632011-09-29 18:07:06 +000015import shutil
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +000016import subprocess
17import sys
18import tempfile
19
20import patch
21import scm
22import subprocess2
23
24
csharp@chromium.org9af0a112013-03-20 20:21:35 +000025if sys.platform in ('cygwin', 'win32'):
26 # Disable timeouts on Windows since we can't have shells with timeouts.
27 GLOBAL_TIMEOUT = None
28 FETCH_TIMEOUT = None
29else:
30 # Default timeout of 15 minutes.
31 GLOBAL_TIMEOUT = 15*60
32 # Use a larger timeout for checkout since it can be a genuinely slower
33 # operation.
34 FETCH_TIMEOUT = 30*60
35
36
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +000037def get_code_review_setting(path, key,
38 codereview_settings_file='codereview.settings'):
39 """Parses codereview.settings and return the value for the key if present.
40
41 Don't cache the values in case the file is changed."""
42 # TODO(maruel): Do not duplicate code.
43 settings = {}
44 try:
45 settings_file = open(os.path.join(path, codereview_settings_file), 'r')
46 try:
47 for line in settings_file.readlines():
48 if not line or line.startswith('#'):
49 continue
50 if not ':' in line:
51 # Invalid file.
52 return None
53 k, v = line.split(':', 1)
54 settings[k.strip()] = v.strip()
55 finally:
56 settings_file.close()
maruel@chromium.org004fb712011-06-21 20:02:16 +000057 except IOError:
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +000058 return None
59 return settings.get(key, None)
60
61
maruel@chromium.org4dd9f722012-10-01 16:23:03 +000062def align_stdout(stdout):
63 """Returns the aligned output of multiple stdouts."""
64 output = ''
65 for item in stdout:
66 item = item.strip()
67 if not item:
68 continue
69 output += ''.join(' %s\n' % line for line in item.splitlines())
70 return output
71
72
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +000073class PatchApplicationFailed(Exception):
74 """Patch failed to be applied."""
maruel@chromium.org34f68552012-05-09 19:18:36 +000075 def __init__(self, p, status):
76 super(PatchApplicationFailed, self).__init__(p, status)
77 self.patch = p
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +000078 self.status = status
79
maruel@chromium.org34f68552012-05-09 19:18:36 +000080 @property
81 def filename(self):
82 if self.patch:
83 return self.patch.filename
84
85 def __str__(self):
86 out = []
87 if self.filename:
88 out.append('Failed to apply patch for %s:' % self.filename)
89 if self.status:
90 out.append(self.status)
maruel@chromium.orgcb5667a2012-10-23 19:42:10 +000091 if self.patch:
92 out.append('Patch: %s' % self.patch.dump())
maruel@chromium.org34f68552012-05-09 19:18:36 +000093 return '\n'.join(out)
94
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +000095
96class CheckoutBase(object):
97 # Set to None to have verbose output.
98 VOID = subprocess2.VOID
99
maruel@chromium.org6ed8b502011-06-12 01:05:35 +0000100 def __init__(self, root_dir, project_name, post_processors):
101 """
102 Args:
103 post_processor: list of lambda(checkout, patches) to call on each of the
104 modified files.
105 """
maruel@chromium.orga5129fb2011-06-20 18:36:25 +0000106 super(CheckoutBase, self).__init__()
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000107 self.root_dir = root_dir
108 self.project_name = project_name
maruel@chromium.org3cdb7f32011-05-05 16:37:24 +0000109 if self.project_name is None:
110 self.project_path = self.root_dir
111 else:
112 self.project_path = os.path.join(self.root_dir, self.project_name)
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000113 # Only used for logging purposes.
114 self._last_seen_revision = None
maruel@chromium.orga5129fb2011-06-20 18:36:25 +0000115 self.post_processors = post_processors
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000116 assert self.root_dir
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000117 assert self.project_path
maruel@chromium.org0aca0f92012-10-01 16:39:45 +0000118 assert os.path.isabs(self.project_path)
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000119
120 def get_settings(self, key):
121 return get_code_review_setting(self.project_path, key)
122
maruel@chromium.org51919772011-06-12 01:27:42 +0000123 def prepare(self, revision):
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000124 """Checks out a clean copy of the tree and removes any local modification.
125
126 This function shouldn't throw unless the remote repository is inaccessible,
127 there is no free disk space or hard issues like that.
maruel@chromium.org51919772011-06-12 01:27:42 +0000128
129 Args:
130 revision: The revision it should sync to, SCM specific.
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000131 """
132 raise NotImplementedError()
133
hinoka@google.com998deaf2014-02-22 00:26:39 +0000134 def apply_patch(self, patches, post_processors=None, verbose=False,
135 name=None, email=None):
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000136 """Applies a patch and returns the list of modified files.
137
138 This function should throw patch.UnsupportedPatchFormat or
139 PatchApplicationFailed when relevant.
maruel@chromium.org8a1396c2011-04-22 00:14:24 +0000140
141 Args:
142 patches: patch.PatchSet object.
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000143 """
144 raise NotImplementedError()
145
146 def commit(self, commit_message, user):
147 """Commits the patch upstream, while impersonating 'user'."""
148 raise NotImplementedError()
149
maruel@chromium.orgbc32ad12012-07-26 13:22:47 +0000150 def revisions(self, rev1, rev2):
151 """Returns the count of revisions from rev1 to rev2, e.g. len(]rev1, rev2]).
152
153 If rev2 is None, it means 'HEAD'.
154
155 Returns None if there is no link between the two.
156 """
157 raise NotImplementedError()
158
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000159
160class RawCheckout(CheckoutBase):
161 """Used to apply a patch locally without any intent to commit it.
162
163 To be used by the try server.
164 """
maruel@chromium.org51919772011-06-12 01:27:42 +0000165 def prepare(self, revision):
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000166 """Stubbed out."""
167 pass
168
hinoka@google.com998deaf2014-02-22 00:26:39 +0000169 def apply_patch(self, patches, post_processors=None, verbose=False,
170 name=None, email=None):
maruel@chromium.org8a1396c2011-04-22 00:14:24 +0000171 """Ignores svn properties."""
maruel@chromium.orgb1d1a782011-09-29 14:13:55 +0000172 post_processors = post_processors or self.post_processors or []
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000173 for p in patches:
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000174 stdout = []
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000175 try:
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000176 filepath = os.path.join(self.project_path, p.filename)
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000177 if p.is_delete:
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000178 os.remove(filepath)
179 stdout.append('Deleted.')
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000180 else:
181 dirname = os.path.dirname(p.filename)
182 full_dir = os.path.join(self.project_path, dirname)
183 if dirname and not os.path.isdir(full_dir):
184 os.makedirs(full_dir)
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000185 stdout.append('Created missing directory %s.' % dirname)
maruel@chromium.org4869bcf2011-06-04 01:14:32 +0000186
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000187 if p.is_binary:
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000188 content = p.get()
maruel@chromium.org4869bcf2011-06-04 01:14:32 +0000189 with open(filepath, 'wb') as f:
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000190 f.write(content)
191 stdout.append('Added binary file %d bytes.' % len(content))
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000192 else:
maruel@chromium.org5e975632011-09-29 18:07:06 +0000193 if p.source_filename:
194 if not p.is_new:
195 raise PatchApplicationFailed(
maruel@chromium.org34f68552012-05-09 19:18:36 +0000196 p,
maruel@chromium.org5e975632011-09-29 18:07:06 +0000197 'File has a source filename specified but is not new')
198 # Copy the file first.
199 if os.path.isfile(filepath):
200 raise PatchApplicationFailed(
maruel@chromium.org34f68552012-05-09 19:18:36 +0000201 p, 'File exist but was about to be overwriten')
maruel@chromium.org5e975632011-09-29 18:07:06 +0000202 shutil.copy2(
203 os.path.join(self.project_path, p.source_filename), filepath)
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000204 stdout.append('Copied %s -> %s' % (p.source_filename, p.filename))
maruel@chromium.org58fe6622011-06-03 20:59:27 +0000205 if p.diff_hunks:
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000206 cmd = ['patch', '-u', '--binary', '-p%s' % p.patchlevel]
207 if verbose:
208 cmd.append('--verbose')
groby@chromium.org23279942013-07-12 19:32:33 +0000209 env = os.environ.copy()
210 env['TMPDIR'] = tempfile.mkdtemp(prefix='crpatch')
211 try:
212 stdout.append(
213 subprocess2.check_output(
214 cmd,
215 stdin=p.get(False),
216 stderr=subprocess2.STDOUT,
217 cwd=self.project_path,
218 timeout=GLOBAL_TIMEOUT,
219 env=env))
220 finally:
221 shutil.rmtree(env['TMPDIR'])
maruel@chromium.org4869bcf2011-06-04 01:14:32 +0000222 elif p.is_new and not os.path.exists(filepath):
maruel@chromium.org58fe6622011-06-03 20:59:27 +0000223 # There is only a header. Just create the file.
maruel@chromium.org4869bcf2011-06-04 01:14:32 +0000224 open(filepath, 'w').close()
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000225 stdout.append('Created an empty file.')
maruel@chromium.orgb1d1a782011-09-29 14:13:55 +0000226 for post in post_processors:
maruel@chromium.org8a1396c2011-04-22 00:14:24 +0000227 post(self, p)
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000228 if verbose:
229 print p.filename
230 print align_stdout(stdout)
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000231 except OSError, e:
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000232 raise PatchApplicationFailed(p, '%s%s' % (align_stdout(stdout), e))
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000233 except subprocess.CalledProcessError, e:
234 raise PatchApplicationFailed(
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000235 p,
236 'While running %s;\n%s%s' % (
237 ' '.join(e.cmd),
238 align_stdout(stdout),
239 align_stdout([getattr(e, 'stdout', '')])))
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000240
241 def commit(self, commit_message, user):
242 """Stubbed out."""
243 raise NotImplementedError('RawCheckout can\'t commit')
244
maruel@chromium.orgbc32ad12012-07-26 13:22:47 +0000245 def revisions(self, _rev1, _rev2):
246 return None
247
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000248
249class SvnConfig(object):
250 """Parses a svn configuration file."""
251 def __init__(self, svn_config_dir=None):
maruel@chromium.orga5129fb2011-06-20 18:36:25 +0000252 super(SvnConfig, self).__init__()
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000253 self.svn_config_dir = svn_config_dir
254 self.default = not bool(self.svn_config_dir)
255 if not self.svn_config_dir:
256 if sys.platform == 'win32':
257 self.svn_config_dir = os.path.join(os.environ['APPDATA'], 'Subversion')
258 else:
259 self.svn_config_dir = os.path.join(os.environ['HOME'], '.subversion')
260 svn_config_file = os.path.join(self.svn_config_dir, 'config')
261 parser = ConfigParser.SafeConfigParser()
262 if os.path.isfile(svn_config_file):
263 parser.read(svn_config_file)
264 else:
265 parser.add_section('auto-props')
266 self.auto_props = dict(parser.items('auto-props'))
267
268
269class SvnMixIn(object):
270 """MixIn class to add svn commands common to both svn and git-svn clients."""
271 # These members need to be set by the subclass.
272 commit_user = None
273 commit_pwd = None
274 svn_url = None
275 project_path = None
276 # Override at class level when necessary. If used, --non-interactive is
277 # implied.
278 svn_config = SvnConfig()
279 # Set to True when non-interactivity is necessary but a custom subversion
280 # configuration directory is not necessary.
281 non_interactive = False
282
maruel@chromium.org9842a0c2011-05-30 20:41:54 +0000283 def _add_svn_flags(self, args, non_interactive, credentials=True):
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000284 args = ['svn'] + args
285 if not self.svn_config.default:
286 args.extend(['--config-dir', self.svn_config.svn_config_dir])
287 if not self.svn_config.default or self.non_interactive or non_interactive:
288 args.append('--non-interactive')
maruel@chromium.org9842a0c2011-05-30 20:41:54 +0000289 if credentials:
290 if self.commit_user:
291 args.extend(['--username', self.commit_user])
292 if self.commit_pwd:
293 args.extend(['--password', self.commit_pwd])
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000294 return args
295
296 def _check_call_svn(self, args, **kwargs):
297 """Runs svn and throws an exception if the command failed."""
298 kwargs.setdefault('cwd', self.project_path)
299 kwargs.setdefault('stdout', self.VOID)
csharp@chromium.org9af0a112013-03-20 20:21:35 +0000300 kwargs.setdefault('timeout', GLOBAL_TIMEOUT)
maruel@chromium.org0bcd1d32011-04-26 15:55:49 +0000301 return subprocess2.check_call_out(
maruel@chromium.org44b21b92012-11-08 19:37:08 +0000302 self._add_svn_flags(args, False), **kwargs)
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000303
maruel@chromium.org9842a0c2011-05-30 20:41:54 +0000304 def _check_output_svn(self, args, credentials=True, **kwargs):
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000305 """Runs svn and throws an exception if the command failed.
306
307 Returns the output.
308 """
309 kwargs.setdefault('cwd', self.project_path)
maruel@chromium.org9842a0c2011-05-30 20:41:54 +0000310 return subprocess2.check_output(
maruel@chromium.org87e6d332011-09-09 19:01:28 +0000311 self._add_svn_flags(args, True, credentials),
312 stderr=subprocess2.STDOUT,
csharp@chromium.org9af0a112013-03-20 20:21:35 +0000313 timeout=GLOBAL_TIMEOUT,
maruel@chromium.org87e6d332011-09-09 19:01:28 +0000314 **kwargs)
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000315
316 @staticmethod
317 def _parse_svn_info(output, key):
318 """Returns value for key from svn info output.
319
320 Case insensitive.
321 """
322 values = {}
323 key = key.lower()
324 for line in output.splitlines(False):
325 if not line:
326 continue
327 k, v = line.split(':', 1)
328 k = k.strip().lower()
329 v = v.strip()
330 assert not k in values
331 values[k] = v
332 return values.get(key, None)
333
334
335class SvnCheckout(CheckoutBase, SvnMixIn):
336 """Manages a subversion checkout."""
maruel@chromium.org6ed8b502011-06-12 01:05:35 +0000337 def __init__(self, root_dir, project_name, commit_user, commit_pwd, svn_url,
338 post_processors=None):
maruel@chromium.orga5129fb2011-06-20 18:36:25 +0000339 CheckoutBase.__init__(self, root_dir, project_name, post_processors)
340 SvnMixIn.__init__(self)
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000341 self.commit_user = commit_user
342 self.commit_pwd = commit_pwd
343 self.svn_url = svn_url
344 assert bool(self.commit_user) >= bool(self.commit_pwd)
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000345
maruel@chromium.org51919772011-06-12 01:27:42 +0000346 def prepare(self, revision):
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000347 # Will checkout if the directory is not present.
maruel@chromium.org3cdb7f32011-05-05 16:37:24 +0000348 assert self.svn_url
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000349 if not os.path.isdir(self.project_path):
350 logging.info('Checking out %s in %s' %
351 (self.project_name, self.project_path))
maruel@chromium.org51919772011-06-12 01:27:42 +0000352 return self._revert(revision)
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000353
hinoka@google.com998deaf2014-02-22 00:26:39 +0000354 def apply_patch(self, patches, post_processors=None, verbose=False,
355 name=None, email=None):
maruel@chromium.orgb1d1a782011-09-29 14:13:55 +0000356 post_processors = post_processors or self.post_processors or []
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000357 for p in patches:
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000358 stdout = []
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000359 try:
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000360 filepath = os.path.join(self.project_path, p.filename)
maruel@chromium.org9842a0c2011-05-30 20:41:54 +0000361 # It is important to use credentials=False otherwise credentials could
362 # leak in the error message. Credentials are not necessary here for the
363 # following commands anyway.
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000364 if p.is_delete:
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000365 stdout.append(self._check_output_svn(
366 ['delete', p.filename, '--force'], credentials=False))
367 stdout.append('Deleted.')
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000368 else:
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000369 # svn add while creating directories otherwise svn add on the
370 # contained files will silently fail.
371 # First, find the root directory that exists.
372 dirname = os.path.dirname(p.filename)
373 dirs_to_create = []
374 while (dirname and
375 not os.path.isdir(os.path.join(self.project_path, dirname))):
376 dirs_to_create.append(dirname)
377 dirname = os.path.dirname(dirname)
378 for dir_to_create in reversed(dirs_to_create):
379 os.mkdir(os.path.join(self.project_path, dir_to_create))
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000380 stdout.append(
381 self._check_output_svn(
382 ['add', dir_to_create, '--force'], credentials=False))
383 stdout.append('Created missing directory %s.' % dir_to_create)
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000384
385 if p.is_binary:
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000386 content = p.get()
maruel@chromium.org4869bcf2011-06-04 01:14:32 +0000387 with open(filepath, 'wb') as f:
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000388 f.write(content)
389 stdout.append('Added binary file %d bytes.' % len(content))
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000390 else:
maruel@chromium.org5e975632011-09-29 18:07:06 +0000391 if p.source_filename:
392 if not p.is_new:
393 raise PatchApplicationFailed(
maruel@chromium.org34f68552012-05-09 19:18:36 +0000394 p,
maruel@chromium.org5e975632011-09-29 18:07:06 +0000395 'File has a source filename specified but is not new')
396 # Copy the file first.
397 if os.path.isfile(filepath):
398 raise PatchApplicationFailed(
maruel@chromium.org34f68552012-05-09 19:18:36 +0000399 p, 'File exist but was about to be overwriten')
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000400 stdout.append(
401 self._check_output_svn(
402 ['copy', p.source_filename, p.filename]))
403 stdout.append('Copied %s -> %s' % (p.source_filename, p.filename))
maruel@chromium.org58fe6622011-06-03 20:59:27 +0000404 if p.diff_hunks:
maruel@chromium.orgec4a9182012-09-28 20:39:45 +0000405 cmd = [
406 'patch',
407 '-p%s' % p.patchlevel,
408 '--forward',
409 '--force',
410 '--no-backup-if-mismatch',
411 ]
groby@chromium.org23279942013-07-12 19:32:33 +0000412 env = os.environ.copy()
413 env['TMPDIR'] = tempfile.mkdtemp(prefix='crpatch')
414 try:
415 stdout.append(
416 subprocess2.check_output(
417 cmd,
418 stdin=p.get(False),
419 cwd=self.project_path,
420 timeout=GLOBAL_TIMEOUT,
421 env=env))
422 finally:
423 shutil.rmtree(env['TMPDIR'])
424
maruel@chromium.org4869bcf2011-06-04 01:14:32 +0000425 elif p.is_new and not os.path.exists(filepath):
426 # There is only a header. Just create the file if it doesn't
427 # exist.
428 open(filepath, 'w').close()
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000429 stdout.append('Created an empty file.')
maruel@chromium.org3da83172012-05-07 16:17:20 +0000430 if p.is_new and not p.source_filename:
431 # Do not run it if p.source_filename is defined, since svn copy was
432 # using above.
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000433 stdout.append(
434 self._check_output_svn(
435 ['add', p.filename, '--force'], credentials=False))
maruel@chromium.orgd7ca6162012-08-29 17:22:22 +0000436 for name, value in p.svn_properties:
437 if value is None:
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000438 stdout.append(
439 self._check_output_svn(
440 ['propdel', '--quiet', name, p.filename],
441 credentials=False))
442 stdout.append('Property %s deleted.' % name)
maruel@chromium.orgd7ca6162012-08-29 17:22:22 +0000443 else:
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000444 stdout.append(
445 self._check_output_svn(
446 ['propset', name, value, p.filename], credentials=False))
447 stdout.append('Property %s=%s' % (name, value))
maruel@chromium.org9842a0c2011-05-30 20:41:54 +0000448 for prop, values in self.svn_config.auto_props.iteritems():
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000449 if fnmatch.fnmatch(p.filename, prop):
maruel@chromium.org9842a0c2011-05-30 20:41:54 +0000450 for value in values.split(';'):
451 if '=' not in value:
maruel@chromium.orge1a03762012-09-24 15:28:52 +0000452 params = [value, '.']
maruel@chromium.org9842a0c2011-05-30 20:41:54 +0000453 else:
454 params = value.split('=', 1)
maruel@chromium.orge1a03762012-09-24 15:28:52 +0000455 if params[1] == '*':
456 # Works around crbug.com/150960 on Windows.
457 params[1] = '.'
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000458 stdout.append(
459 self._check_output_svn(
460 ['propset'] + params + [p.filename], credentials=False))
461 stdout.append('Property (auto) %s' % '='.join(params))
maruel@chromium.orgb1d1a782011-09-29 14:13:55 +0000462 for post in post_processors:
maruel@chromium.org8a1396c2011-04-22 00:14:24 +0000463 post(self, p)
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000464 if verbose:
465 print p.filename
466 print align_stdout(stdout)
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000467 except OSError, e:
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000468 raise PatchApplicationFailed(p, '%s%s' % (align_stdout(stdout), e))
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000469 except subprocess.CalledProcessError, e:
470 raise PatchApplicationFailed(
maruel@chromium.org34f68552012-05-09 19:18:36 +0000471 p,
maruel@chromium.org9842a0c2011-05-30 20:41:54 +0000472 'While running %s;\n%s%s' % (
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000473 ' '.join(e.cmd),
474 align_stdout(stdout),
475 align_stdout([getattr(e, 'stdout', '')])))
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000476
477 def commit(self, commit_message, user):
478 logging.info('Committing patch for %s' % user)
479 assert self.commit_user
maruel@chromium.org1bf50972011-05-05 19:57:21 +0000480 assert isinstance(commit_message, unicode)
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000481 handle, commit_filename = tempfile.mkstemp(text=True)
482 try:
maruel@chromium.org1bf50972011-05-05 19:57:21 +0000483 # Shouldn't assume default encoding is UTF-8. But really, if you are using
484 # anything else, you are living in another world.
485 os.write(handle, commit_message.encode('utf-8'))
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000486 os.close(handle)
487 # When committing, svn won't update the Revision metadata of the checkout,
488 # so if svn commit returns "Committed revision 3.", svn info will still
489 # return "Revision: 2". Since running svn update right after svn commit
490 # creates a race condition with other committers, this code _must_ parse
491 # the output of svn commit and use a regexp to grab the revision number.
492 # Note that "Committed revision N." is localized but subprocess2 forces
493 # LANGUAGE=en.
494 args = ['commit', '--file', commit_filename]
495 # realauthor is parsed by a server-side hook.
496 if user and user != self.commit_user:
497 args.extend(['--with-revprop', 'realauthor=%s' % user])
498 out = self._check_output_svn(args)
499 finally:
500 os.remove(commit_filename)
501 lines = filter(None, out.splitlines())
502 match = re.match(r'^Committed revision (\d+).$', lines[-1])
503 if not match:
504 raise PatchApplicationFailed(
505 None,
506 'Couldn\'t make sense out of svn commit message:\n' + out)
507 return int(match.group(1))
508
maruel@chromium.org51919772011-06-12 01:27:42 +0000509 def _revert(self, revision):
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000510 """Reverts local modifications or checks out if the directory is not
511 present. Use depot_tools's functionality to do this.
512 """
513 flags = ['--ignore-externals']
maruel@chromium.org51919772011-06-12 01:27:42 +0000514 if revision:
515 flags.extend(['--revision', str(revision)])
maruel@chromium.org6e904b42012-12-19 14:21:14 +0000516 if os.path.isdir(self.project_path):
517 # This may remove any part (or all) of the checkout.
518 scm.SVN.Revert(self.project_path, no_ignore=True)
519
520 if os.path.isdir(self.project_path):
521 # Revive files that were deleted in scm.SVN.Revert().
csharp@chromium.org9af0a112013-03-20 20:21:35 +0000522 self._check_call_svn(['update', '--force'] + flags,
523 timeout=FETCH_TIMEOUT)
maruel@chromium.org6e904b42012-12-19 14:21:14 +0000524 else:
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000525 logging.info(
526 'Directory %s is not present, checking it out.' % self.project_path)
527 self._check_call_svn(
csharp@chromium.org9af0a112013-03-20 20:21:35 +0000528 ['checkout', self.svn_url, self.project_path] + flags, cwd=None,
529 timeout=FETCH_TIMEOUT)
maruel@chromium.org51919772011-06-12 01:27:42 +0000530 return self._get_revision()
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000531
maruel@chromium.org51919772011-06-12 01:27:42 +0000532 def _get_revision(self):
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000533 out = self._check_output_svn(['info', '.'])
maruel@chromium.org51919772011-06-12 01:27:42 +0000534 revision = int(self._parse_svn_info(out, 'revision'))
535 if revision != self._last_seen_revision:
536 logging.info('Updated to revision %d' % revision)
537 self._last_seen_revision = revision
538 return revision
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000539
maruel@chromium.orgbc32ad12012-07-26 13:22:47 +0000540 def revisions(self, rev1, rev2):
541 """Returns the number of actual commits, not just the difference between
542 numbers.
543 """
544 rev2 = rev2 or 'HEAD'
545 # Revision range is inclusive and ordering doesn't matter, they'll appear in
546 # the order specified.
547 try:
548 out = self._check_output_svn(
549 ['log', '-q', self.svn_url, '-r', '%s:%s' % (rev1, rev2)])
550 except subprocess.CalledProcessError:
551 return None
552 # Ignore the '----' lines.
553 return len([l for l in out.splitlines() if l.startswith('r')]) - 1
554
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000555
rmistry@google.com3b5efdf2013-09-05 11:59:40 +0000556class GitCheckout(CheckoutBase):
557 """Manages a git checkout."""
558 def __init__(self, root_dir, project_name, remote_branch, git_url,
hinoka@google.comd067d812014-02-21 02:23:14 +0000559 commit_user, post_processors=None, base_ref=None):
rmistry@google.com3b5efdf2013-09-05 11:59:40 +0000560 super(GitCheckout, self).__init__(root_dir, project_name, post_processors)
hinoka@google.comd067d812014-02-21 02:23:14 +0000561 self.base_ref = base_ref
rmistry@google.com3b5efdf2013-09-05 11:59:40 +0000562 self.git_url = git_url
563 self.commit_user = commit_user
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000564 self.remote_branch = remote_branch
rmistry@google.com3b5efdf2013-09-05 11:59:40 +0000565 # The working branch where patches will be applied. It will track the
566 # remote branch.
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000567 self.working_branch = 'working_branch'
rmistry@google.com3b5efdf2013-09-05 11:59:40 +0000568 # There is no reason to not hardcode origin.
agable@chromium.org7dc11442014-03-12 22:37:32 +0000569 self.pull_remote = 'origin'
570 self.push_remote = 'upstream'
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000571
maruel@chromium.org51919772011-06-12 01:27:42 +0000572 def prepare(self, revision):
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000573 """Resets the git repository in a clean state.
574
575 Checks it out if not present and deletes the working branch.
576 """
rmistry@google.combb050f62013-10-03 16:53:54 +0000577 assert self.git_url
agable@chromium.org7dc11442014-03-12 22:37:32 +0000578 assert self.remote_branch
579
580 self._check_call_git(
581 ['cache', 'populate', self.git_url], timeout=FETCH_TIMEOUT, cwd=None)
582 cache_path = self._check_output_git(
583 ['cache', 'exists', self.git_url], cwd=None).strip()
rmistry@google.com3b5efdf2013-09-05 11:59:40 +0000584
585 if not os.path.isdir(self.project_path):
586 # Clone the repo if the directory is not present.
rmistry@google.com3b5efdf2013-09-05 11:59:40 +0000587 self._check_call_git(
agable@chromium.org7dc11442014-03-12 22:37:32 +0000588 ['clone', '--shared', cache_path, self.project_path],
rmistry@google.com3b5efdf2013-09-05 11:59:40 +0000589 cwd=None, timeout=FETCH_TIMEOUT)
agable@chromium.org7dc11442014-03-12 22:37:32 +0000590 self._call_git(
591 ['config', 'remote.%s.url' % self.push_remote, self.git_url],
592 cwd=self.project_path)
rmistry@google.com3b5efdf2013-09-05 11:59:40 +0000593
agable@chromium.org7dc11442014-03-12 22:37:32 +0000594 if not revision:
595 revision = self.remote_branch
rmistry@google.com3b5efdf2013-09-05 11:59:40 +0000596
agable@chromium.org7dc11442014-03-12 22:37:32 +0000597 if not re.match(r'[0-9a-f]{40}$', revision, flags=re.IGNORECASE):
598 self._check_call_git(['fetch', self.pull_remote, revision])
599 revision = self.pull_remote + '/' + revision
600
601 self._check_call_git(['checkout', '--force', '--quiet', revision])
602 self._call_git(['clean', '-fdx'])
603
604 branches, _ = self._branches()
605 if self.working_branch in branches:
606 self._call_git(['branch', '-D', self.working_branch])
607
rmistry@google.com3b5efdf2013-09-05 11:59:40 +0000608 return self._get_head_commit_hash()
609
rmistry@google.com3b5efdf2013-09-05 11:59:40 +0000610 def _get_head_commit_hash(self):
rmistry@google.com11145db2013-10-03 12:43:40 +0000611 """Gets the current revision (in unicode) from the local branch."""
612 return unicode(self._check_output_git(['rev-parse', 'HEAD']).strip())
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000613
agable@chromium.org7dc11442014-03-12 22:37:32 +0000614 def apply_patch(self, patches, post_processors=None, verbose=False,
hinoka@google.com998deaf2014-02-22 00:26:39 +0000615 name=None, email=None):
rmistry@google.com3b5efdf2013-09-05 11:59:40 +0000616 """Applies a patch on 'working_branch' and switches to it.
maruel@chromium.org8a1396c2011-04-22 00:14:24 +0000617
618 Also commits the changes on the local branch.
619
620 Ignores svn properties and raise an exception on unexpected ones.
621 """
maruel@chromium.orgb1d1a782011-09-29 14:13:55 +0000622 post_processors = post_processors or self.post_processors or []
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000623 # It this throws, the checkout is corrupted. Maybe worth deleting it and
624 # trying again?
maruel@chromium.org3cdb7f32011-05-05 16:37:24 +0000625 if self.remote_branch:
626 self._check_call_git(
agable@chromium.orgfa3c3882014-03-19 02:37:46 +0000627 ['checkout', '-b', self.working_branch,
agable@chromium.orge569f502014-03-18 21:27:59 +0000628 '-t', '%s/%s' % (self.pull_remote, self.remote_branch),
rmistry@google.com3b5efdf2013-09-05 11:59:40 +0000629 '--quiet'])
630
maruel@chromium.org5e975632011-09-29 18:07:06 +0000631 for index, p in enumerate(patches):
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000632 stdout = []
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000633 try:
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000634 filepath = os.path.join(self.project_path, p.filename)
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000635 if p.is_delete:
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000636 if (not os.path.exists(filepath) and
maruel@chromium.org5e975632011-09-29 18:07:06 +0000637 any(p1.source_filename == p.filename for p1 in patches[0:index])):
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000638 # The file was already deleted if a prior patch with file rename
639 # was already processed because 'git apply' did it for us.
maruel@chromium.org5e975632011-09-29 18:07:06 +0000640 pass
641 else:
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000642 stdout.append(self._check_output_git(['rm', p.filename]))
643 stdout.append('Deleted.')
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000644 else:
645 dirname = os.path.dirname(p.filename)
646 full_dir = os.path.join(self.project_path, dirname)
647 if dirname and not os.path.isdir(full_dir):
648 os.makedirs(full_dir)
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000649 stdout.append('Created missing directory %s.' % dirname)
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000650 if p.is_binary:
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000651 content = p.get()
652 with open(filepath, 'wb') as f:
653 f.write(content)
654 stdout.append('Added binary file %d bytes' % len(content))
655 cmd = ['add', p.filename]
656 if verbose:
657 cmd.append('--verbose')
658 stdout.append(self._check_output_git(cmd))
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000659 else:
maruel@chromium.org58fe6622011-06-03 20:59:27 +0000660 # No need to do anything special with p.is_new or if not
661 # p.diff_hunks. git apply manages all that already.
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000662 cmd = ['apply', '--index', '-p%s' % p.patchlevel]
663 if verbose:
664 cmd.append('--verbose')
665 stdout.append(self._check_output_git(cmd, stdin=p.get(True)))
666 for name, value in p.svn_properties:
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000667 # Ignore some known auto-props flags through .subversion/config,
668 # bails out on the other ones.
669 # TODO(maruel): Read ~/.subversion/config and detect the rules that
670 # applies here to figure out if the property will be correctly
671 # handled.
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000672 stdout.append('Property %s=%s' % (name, value))
maruel@chromium.orgd7ca6162012-08-29 17:22:22 +0000673 if not name in (
maruel@chromium.org9799a072012-01-11 00:26:25 +0000674 'svn:eol-style', 'svn:executable', 'svn:mime-type'):
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000675 raise patch.UnsupportedPatchFormat(
676 p.filename,
677 'Cannot apply svn property %s to file %s.' % (
maruel@chromium.orgd7ca6162012-08-29 17:22:22 +0000678 name, p.filename))
maruel@chromium.orgb1d1a782011-09-29 14:13:55 +0000679 for post in post_processors:
maruel@chromium.org8a1396c2011-04-22 00:14:24 +0000680 post(self, p)
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000681 if verbose:
682 print p.filename
683 print align_stdout(stdout)
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000684 except OSError, e:
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000685 raise PatchApplicationFailed(p, '%s%s' % (align_stdout(stdout), e))
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000686 except subprocess.CalledProcessError, e:
687 raise PatchApplicationFailed(
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000688 p,
689 'While running %s;\n%s%s' % (
690 ' '.join(e.cmd),
691 align_stdout(stdout),
692 align_stdout([getattr(e, 'stdout', '')])))
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000693 # Once all the patches are processed and added to the index, commit the
694 # index.
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000695 cmd = ['commit', '-m', 'Committed patch']
hinoka@google.com998deaf2014-02-22 00:26:39 +0000696 if name and email:
hinoka@google.combe6b3082014-02-22 02:20:14 +0000697 cmd = ['-c', 'user.email=%s' % email, '-c', 'user.name=%s' % name] + cmd
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000698 if verbose:
699 cmd.append('--verbose')
700 self._check_call_git(cmd)
hinoka@google.comd067d812014-02-21 02:23:14 +0000701 if self.base_ref:
702 base_ref = self.base_ref
703 else:
agable@chromium.org7dc11442014-03-12 22:37:32 +0000704 base_ref = '%s/%s' % (self.pull_remote, self.remote_branch)
rmistry@google.com3b5efdf2013-09-05 11:59:40 +0000705 found_files = self._check_output_git(
hinoka@google.comd067d812014-02-21 02:23:14 +0000706 ['diff', base_ref,
rmistry@google.com3b5efdf2013-09-05 11:59:40 +0000707 '--name-only']).splitlines(False)
708 assert sorted(patches.filenames) == sorted(found_files), (
709 sorted(patches.filenames), sorted(found_files))
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000710
711 def commit(self, commit_message, user):
rmistry@google.com3b5efdf2013-09-05 11:59:40 +0000712 """Commits, updates the commit message and pushes."""
rmistry@google.combb050f62013-10-03 16:53:54 +0000713 assert self.commit_user
maruel@chromium.org1bf50972011-05-05 19:57:21 +0000714 assert isinstance(commit_message, unicode)
rmistry@google.com3b5efdf2013-09-05 11:59:40 +0000715 current_branch = self._check_output_git(
716 ['rev-parse', '--abbrev-ref', 'HEAD']).strip()
717 assert current_branch == self.working_branch
agable@chromium.org7dc11442014-03-12 22:37:32 +0000718
rmistry@google.com3b5efdf2013-09-05 11:59:40 +0000719 commit_cmd = ['commit', '--amend', '-m', commit_message]
720 if user and user != self.commit_user:
721 # We do not have the first or last name of the user, grab the username
722 # from the email and call it the original author's name.
723 # TODO(rmistry): Do not need the below if user is already in
724 # "Name <email>" format.
725 name = user.split('@')[0]
726 commit_cmd.extend(['--author', '%s <%s>' % (name, user)])
727 self._check_call_git(commit_cmd)
728
729 # Push to the remote repository.
730 self._check_call_git(
agable@chromium.org7dc11442014-03-12 22:37:32 +0000731 ['push', self.push_remote,
732 '%s:%s' % (self.working_branch, self.remote_branch),
rmistry@google.com3b5efdf2013-09-05 11:59:40 +0000733 '--force', '--quiet'])
734 # Get the revision after the push.
735 revision = self._get_head_commit_hash()
agable@chromium.org7dc11442014-03-12 22:37:32 +0000736 # Switch back to the remote_branch.
737 self._check_call_git(['cache', 'populate', self.git_url])
738 self._check_call_git(['fetch', self.pull_remote])
739 self._check_call_git(['checkout', '--force', '--quiet',
740 '%s/%s' % (self.pull_remote, self.remote_branch)])
rmistry@google.com3b5efdf2013-09-05 11:59:40 +0000741 # Delete the working branch since we are done with it.
742 self._check_call_git(['branch', '-D', self.working_branch])
743
744 return revision
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000745
746 def _check_call_git(self, args, **kwargs):
747 kwargs.setdefault('cwd', self.project_path)
748 kwargs.setdefault('stdout', self.VOID)
csharp@chromium.org9af0a112013-03-20 20:21:35 +0000749 kwargs.setdefault('timeout', GLOBAL_TIMEOUT)
maruel@chromium.org44b21b92012-11-08 19:37:08 +0000750 return subprocess2.check_call_out(['git'] + args, **kwargs)
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000751
752 def _call_git(self, args, **kwargs):
753 """Like check_call but doesn't throw on failure."""
754 kwargs.setdefault('cwd', self.project_path)
755 kwargs.setdefault('stdout', self.VOID)
csharp@chromium.org9af0a112013-03-20 20:21:35 +0000756 kwargs.setdefault('timeout', GLOBAL_TIMEOUT)
maruel@chromium.org44b21b92012-11-08 19:37:08 +0000757 return subprocess2.call(['git'] + args, **kwargs)
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000758
759 def _check_output_git(self, args, **kwargs):
760 kwargs.setdefault('cwd', self.project_path)
csharp@chromium.org9af0a112013-03-20 20:21:35 +0000761 kwargs.setdefault('timeout', GLOBAL_TIMEOUT)
maruel@chromium.org87e6d332011-09-09 19:01:28 +0000762 return subprocess2.check_output(
maruel@chromium.org44b21b92012-11-08 19:37:08 +0000763 ['git'] + args, stderr=subprocess2.STDOUT, **kwargs)
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000764
765 def _branches(self):
766 """Returns the list of branches and the active one."""
767 out = self._check_output_git(['branch']).splitlines(False)
768 branches = [l[2:] for l in out]
769 active = None
770 for l in out:
771 if l.startswith('*'):
772 active = l[2:]
773 break
774 return branches, active
775
maruel@chromium.orgbc32ad12012-07-26 13:22:47 +0000776 def revisions(self, rev1, rev2):
777 """Returns the number of actual commits between both hash."""
778 self._fetch_remote()
779
agable@chromium.org7dc11442014-03-12 22:37:32 +0000780 rev2 = rev2 or '%s/%s' % (self.pull_remote, self.remote_branch)
maruel@chromium.orgbc32ad12012-07-26 13:22:47 +0000781 # Revision range is ]rev1, rev2] and ordering matters.
782 try:
783 out = self._check_output_git(
784 ['log', '--format="%H"' , '%s..%s' % (rev1, rev2)])
785 except subprocess.CalledProcessError:
786 return None
787 return len(out.splitlines())
788
789 def _fetch_remote(self):
790 """Fetches the remote without rebasing."""
rmistry@google.com3b5efdf2013-09-05 11:59:40 +0000791 # git fetch is always verbose even with -q, so redirect its output.
agable@chromium.org7dc11442014-03-12 22:37:32 +0000792 self._check_output_git(['fetch', self.pull_remote, self.remote_branch],
csharp@chromium.org9af0a112013-03-20 20:21:35 +0000793 timeout=FETCH_TIMEOUT)
maruel@chromium.orgbc32ad12012-07-26 13:22:47 +0000794
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000795
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000796class ReadOnlyCheckout(object):
797 """Converts a checkout into a read-only one."""
maruel@chromium.orgb1d1a782011-09-29 14:13:55 +0000798 def __init__(self, checkout, post_processors=None):
maruel@chromium.orga5129fb2011-06-20 18:36:25 +0000799 super(ReadOnlyCheckout, self).__init__()
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000800 self.checkout = checkout
maruel@chromium.orgb1d1a782011-09-29 14:13:55 +0000801 self.post_processors = (post_processors or []) + (
802 self.checkout.post_processors or [])
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000803
maruel@chromium.org51919772011-06-12 01:27:42 +0000804 def prepare(self, revision):
805 return self.checkout.prepare(revision)
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000806
807 def get_settings(self, key):
808 return self.checkout.get_settings(key)
809
hinoka@google.com998deaf2014-02-22 00:26:39 +0000810 def apply_patch(self, patches, post_processors=None, verbose=False,
811 name=None, email=None):
maruel@chromium.orgb1d1a782011-09-29 14:13:55 +0000812 return self.checkout.apply_patch(
maruel@chromium.org4dd9f722012-10-01 16:23:03 +0000813 patches, post_processors or self.post_processors, verbose)
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000814
815 def commit(self, message, user): # pylint: disable=R0201
816 logging.info('Would have committed for %s with message: %s' % (
817 user, message))
818 return 'FAKE'
819
maruel@chromium.orgbc32ad12012-07-26 13:22:47 +0000820 def revisions(self, rev1, rev2):
821 return self.checkout.revisions(rev1, rev2)
822
maruel@chromium.orgdfaecd22011-04-21 00:33:31 +0000823 @property
824 def project_name(self):
825 return self.checkout.project_name
826
827 @property
828 def project_path(self):
829 return self.checkout.project_path