Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: checkout.py

Issue 6993033: Do no delete file if they exist, even if p.is_new is True. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 try: 116 try:
117 stdout = '' 117 stdout = ''
118 filename = os.path.join(self.project_path, p.filename) 118 filename = os.path.join(self.project_path, p.filename)
119 if p.is_delete: 119 if p.is_delete:
120 os.remove(filename) 120 os.remove(filename)
121 else: 121 else:
122 dirname = os.path.dirname(p.filename) 122 dirname = os.path.dirname(p.filename)
123 full_dir = os.path.join(self.project_path, dirname) 123 full_dir = os.path.join(self.project_path, dirname)
124 if dirname and not os.path.isdir(full_dir): 124 if dirname and not os.path.isdir(full_dir):
125 os.makedirs(full_dir) 125 os.makedirs(full_dir)
126
127 filepath = os.path.join(self.project_path, p.filename)
126 if p.is_binary: 128 if p.is_binary:
127 with open(os.path.join(filename), 'wb') as f: 129 with open(filepath, 'wb') as f:
128 f.write(p.get()) 130 f.write(p.get())
129 else: 131 else:
130 if p.diff_hunks: 132 if p.diff_hunks:
131 stdout = subprocess2.check_output( 133 stdout = subprocess2.check_output(
132 ['patch', '-p%s' % p.patchlevel], 134 ['patch', '-p%s' % p.patchlevel],
133 stdin=p.get(), 135 stdin=p.get(),
134 cwd=self.project_path) 136 cwd=self.project_path)
135 elif p.is_new: 137 elif p.is_new and not os.path.exists(filepath):
136 # There is only a header. Just create the file. 138 # There is only a header. Just create the file.
137 open(os.path.join(self.project_path, p.filename), 'w').close() 139 open(filepath, 'w').close()
138 for post in post_processor: 140 for post in post_processor:
139 post(self, p) 141 post(self, p)
140 except OSError, e: 142 except OSError, e:
141 raise PatchApplicationFailed(p.filename, '%s%s' % (stdout, e)) 143 raise PatchApplicationFailed(p.filename, '%s%s' % (stdout, e))
142 except subprocess.CalledProcessError, e: 144 except subprocess.CalledProcessError, e:
143 raise PatchApplicationFailed( 145 raise PatchApplicationFailed(
144 p.filename, '%s%s' % (stdout, getattr(e, 'stdout', None))) 146 p.filename, '%s%s' % (stdout, getattr(e, 'stdout', None)))
145 147
146 def commit(self, commit_message, user): 148 def commit(self, commit_message, user):
147 """Stubbed out.""" 149 """Stubbed out."""
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 dirs_to_create = [] 271 dirs_to_create = []
270 while (dirname and 272 while (dirname and
271 not os.path.isdir(os.path.join(self.project_path, dirname))): 273 not os.path.isdir(os.path.join(self.project_path, dirname))):
272 dirs_to_create.append(dirname) 274 dirs_to_create.append(dirname)
273 dirname = os.path.dirname(dirname) 275 dirname = os.path.dirname(dirname)
274 for dir_to_create in reversed(dirs_to_create): 276 for dir_to_create in reversed(dirs_to_create):
275 os.mkdir(os.path.join(self.project_path, dir_to_create)) 277 os.mkdir(os.path.join(self.project_path, dir_to_create))
276 stdout += self._check_output_svn( 278 stdout += self._check_output_svn(
277 ['add', dir_to_create, '--force'], credentials=False) 279 ['add', dir_to_create, '--force'], credentials=False)
278 280
281 filepath = os.path.join(self.project_path, p.filename)
279 if p.is_binary: 282 if p.is_binary:
280 with open(os.path.join(self.project_path, p.filename), 'wb') as f: 283 with open(filepath, 'wb') as f:
281 f.write(p.get()) 284 f.write(p.get())
282 else: 285 else:
283 if p.diff_hunks: 286 if p.diff_hunks:
284 cmd = ['patch', '-p%s' % p.patchlevel, '--forward', '--force'] 287 cmd = ['patch', '-p%s' % p.patchlevel, '--forward', '--force']
285 stdout += subprocess2.check_output( 288 stdout += subprocess2.check_output(
286 cmd, stdin=p.get(), cwd=self.project_path) 289 cmd, stdin=p.get(), cwd=self.project_path)
287 elif p.is_new: 290 elif p.is_new and not os.path.exists(filepath):
288 # There is only a header. Just create the file. 291 # There is only a header. Just create the file if it doesn't
289 open(os.path.join(self.project_path, p.filename), 'w').close() 292 # exist.
293 open(filepath, 'w').close()
290 if p.is_new: 294 if p.is_new:
291 stdout += self._check_output_svn( 295 stdout += self._check_output_svn(
292 ['add', p.filename, '--force'], credentials=False) 296 ['add', p.filename, '--force'], credentials=False)
293 for prop in p.svn_properties: 297 for prop in p.svn_properties:
294 stdout += self._check_output_svn( 298 stdout += self._check_output_svn(
295 ['propset', prop[0], prop[1], p.filename], credentials=False) 299 ['propset', prop[0], prop[1], p.filename], credentials=False)
296 for prop, values in self.svn_config.auto_props.iteritems(): 300 for prop, values in self.svn_config.auto_props.iteritems():
297 if fnmatch.fnmatch(p.filename, prop): 301 if fnmatch.fnmatch(p.filename, prop):
298 for value in values.split(';'): 302 for value in values.split(';'):
299 if '=' not in value: 303 if '=' not in value:
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 user, message)) 671 user, message))
668 return 'FAKE' 672 return 'FAKE'
669 673
670 @property 674 @property
671 def project_name(self): 675 def project_name(self):
672 return self.checkout.project_name 676 return self.checkout.project_name
673 677
674 @property 678 @property
675 def project_path(self): 679 def project_path(self):
676 return self.checkout.project_path 680 return self.checkout.project_path
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698