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

Side by Side Diff: patch.py

Issue 8539016: Fix deleted empty files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 9 years, 1 month 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 | testing_support/patches_data.py » ('j') | 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 """Utility functions to handle patches.""" 5 """Utility functions to handle patches."""
6 6
7 import posixpath 7 import posixpath
8 import os 8 import os
9 import re 9 import re
10 10
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 match = re.match(r'^(rename|copy) to (.+)$', line) 282 match = re.match(r'^(rename|copy) to (.+)$', line)
283 if match: 283 if match:
284 if self.filename != match.group(2): 284 if self.filename != match.group(2):
285 self._fail('Unexpected git diff output name for line %s.' % line) 285 self._fail('Unexpected git diff output name for line %s.' % line)
286 if not last_line.startswith('%s from ' % match.group(1)): 286 if not last_line.startswith('%s from ' % match.group(1)):
287 self._fail( 287 self._fail(
288 'Confused %s from/to git diff for line %s.' % 288 'Confused %s from/to git diff for line %s.' %
289 (match.group(1), line)) 289 (match.group(1), line))
290 return 290 return
291 291
292 # Ignore "deleted file mode 100644" since it's not needed. 292 match = re.match(r'^deleted file mode (\d{6})$', line)
293 if match:
294 # It is necessary to parse it because there may be no hunk, like when the
295 # file was empty.
296 self.is_delete = True
297 return
298
293 match = re.match(r'^new(| file) mode (\d{6})$', line) 299 match = re.match(r'^new(| file) mode (\d{6})$', line)
294 if match: 300 if match:
295 mode = match.group(2) 301 mode = match.group(2)
296 # Only look at owner ACL for executable. 302 # Only look at owner ACL for executable.
297 # TODO(maruel): Add support to remove a property. 303 # TODO(maruel): Add support to remove a property.
298 if bool(int(mode[4]) & 1): 304 if bool(int(mode[4]) & 1):
299 self.svn_properties.append(('svn:executable', '*')) 305 self.svn_properties.append(('svn:executable', '*'))
306 return
300 307
301 match = re.match(r'^--- (.*)$', line) 308 match = re.match(r'^--- (.*)$', line)
302 if match: 309 if match:
303 if last_line[:3] in ('---', '+++'): 310 if last_line[:3] in ('---', '+++'):
304 self._fail('--- and +++ are reversed') 311 self._fail('--- and +++ are reversed')
305 if match.group(1) == '/dev/null': 312 if match.group(1) == '/dev/null':
306 self.is_new = True 313 self.is_new = True
307 elif self.mangle(match.group(1)) != old: 314 elif self.mangle(match.group(1)) != old:
308 # git patches are always well formatted, do not allow random filenames. 315 # git patches are always well formatted, do not allow random filenames.
309 self._fail('Unexpected git diff: %s != %s.' % (old, match.group(1))) 316 self._fail('Unexpected git diff: %s != %s.' % (old, match.group(1)))
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 def __iter__(self): 414 def __iter__(self):
408 for patch in self.patches: 415 for patch in self.patches:
409 yield patch 416 yield patch
410 417
411 def __getitem__(self, key): 418 def __getitem__(self, key):
412 return self.patches[key] 419 return self.patches[key]
413 420
414 @property 421 @property
415 def filenames(self): 422 def filenames(self):
416 return [p.filename for p in self.patches] 423 return [p.filename for p in self.patches]
OLDNEW
« no previous file with comments | « no previous file | testing_support/patches_data.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698