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

Side by Side Diff: checkout.py

Issue 319673003: Verify our assumptions about SCM commands deleting files from checkout (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 6 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
« 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) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 import ConfigParser 10 import ConfigParser
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 167
168 def apply_patch(self, patches, post_processors=None, verbose=False): 168 def apply_patch(self, patches, post_processors=None, verbose=False):
169 """Ignores svn properties.""" 169 """Ignores svn properties."""
170 post_processors = post_processors or self.post_processors or [] 170 post_processors = post_processors or self.post_processors or []
171 for p in patches: 171 for p in patches:
172 stdout = [] 172 stdout = []
173 try: 173 try:
174 filepath = os.path.join(self.project_path, p.filename) 174 filepath = os.path.join(self.project_path, p.filename)
175 if p.is_delete: 175 if p.is_delete:
176 os.remove(filepath) 176 os.remove(filepath)
177 assert(not os.path.exists(filepath))
jochen (gone - plz use gerrit) 2014/06/05 13:33:26 this won't work if filepath is a directory, right?
177 stdout.append('Deleted.') 178 stdout.append('Deleted.')
178 else: 179 else:
179 dirname = os.path.dirname(p.filename) 180 dirname = os.path.dirname(p.filename)
180 full_dir = os.path.join(self.project_path, dirname) 181 full_dir = os.path.join(self.project_path, dirname)
181 if dirname and not os.path.isdir(full_dir): 182 if dirname and not os.path.isdir(full_dir):
182 os.makedirs(full_dir) 183 os.makedirs(full_dir)
183 stdout.append('Created missing directory %s.' % dirname) 184 stdout.append('Created missing directory %s.' % dirname)
184 185
185 if p.is_binary: 186 if p.is_binary:
186 content = p.get() 187 content = p.get()
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 for p in patches: 355 for p in patches:
355 stdout = [] 356 stdout = []
356 try: 357 try:
357 filepath = os.path.join(self.project_path, p.filename) 358 filepath = os.path.join(self.project_path, p.filename)
358 # It is important to use credentials=False otherwise credentials could 359 # It is important to use credentials=False otherwise credentials could
359 # leak in the error message. Credentials are not necessary here for the 360 # leak in the error message. Credentials are not necessary here for the
360 # following commands anyway. 361 # following commands anyway.
361 if p.is_delete: 362 if p.is_delete:
362 stdout.append(self._check_output_svn( 363 stdout.append(self._check_output_svn(
363 ['delete', p.filename, '--force'], credentials=False)) 364 ['delete', p.filename, '--force'], credentials=False))
365 assert(not os.path.exists(filepath))
364 stdout.append('Deleted.') 366 stdout.append('Deleted.')
365 else: 367 else:
366 # svn add while creating directories otherwise svn add on the 368 # svn add while creating directories otherwise svn add on the
367 # contained files will silently fail. 369 # contained files will silently fail.
368 # First, find the root directory that exists. 370 # First, find the root directory that exists.
369 dirname = os.path.dirname(p.filename) 371 dirname = os.path.dirname(p.filename)
370 dirs_to_create = [] 372 dirs_to_create = []
371 while (dirname and 373 while (dirname and
372 not os.path.isdir(os.path.join(self.project_path, dirname))): 374 not os.path.isdir(os.path.join(self.project_path, dirname))):
373 dirs_to_create.append(dirname) 375 dirs_to_create.append(dirname)
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 try: 649 try:
648 filepath = os.path.join(self.project_path, p.filename) 650 filepath = os.path.join(self.project_path, p.filename)
649 if p.is_delete: 651 if p.is_delete:
650 if (not os.path.exists(filepath) and 652 if (not os.path.exists(filepath) and
651 any(p1.source_filename == p.filename for p1 in patches[0:index])): 653 any(p1.source_filename == p.filename for p1 in patches[0:index])):
652 # The file was already deleted if a prior patch with file rename 654 # The file was already deleted if a prior patch with file rename
653 # was already processed because 'git apply' did it for us. 655 # was already processed because 'git apply' did it for us.
654 pass 656 pass
655 else: 657 else:
656 stdout.append(self._check_output_git(['rm', p.filename])) 658 stdout.append(self._check_output_git(['rm', p.filename]))
659 assert(not os.path.exists(filepath))
657 stdout.append('Deleted.') 660 stdout.append('Deleted.')
658 else: 661 else:
659 dirname = os.path.dirname(p.filename) 662 dirname = os.path.dirname(p.filename)
660 full_dir = os.path.join(self.project_path, dirname) 663 full_dir = os.path.join(self.project_path, dirname)
661 if dirname and not os.path.isdir(full_dir): 664 if dirname and not os.path.isdir(full_dir):
662 os.makedirs(full_dir) 665 os.makedirs(full_dir)
663 stdout.append('Created missing directory %s.' % dirname) 666 stdout.append('Created missing directory %s.' % dirname)
664 if p.is_binary: 667 if p.is_binary:
665 content = p.get() 668 content = p.get()
666 with open(filepath, 'wb') as f: 669 with open(filepath, 'wb') as f:
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 def revisions(self, rev1, rev2): 829 def revisions(self, rev1, rev2):
827 return self.checkout.revisions(rev1, rev2) 830 return self.checkout.revisions(rev1, rev2)
828 831
829 @property 832 @property
830 def project_name(self): 833 def project_name(self):
831 return self.checkout.project_name 834 return self.checkout.project_name
832 835
833 @property 836 @property
834 def project_path(self): 837 def project_path(self):
835 return self.checkout.project_path 838 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