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

Unified Diff: patch.py

Issue 7847005: Add automatic is_new=True on git copy or rename. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 9 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/patch_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: patch.py
diff --git a/patch.py b/patch.py
index 888e10095a7e25d68eb791f81f6141df5bceb941..8b0407fab0aaec979a2d66b5a86d1b4484e1c820 100644
--- a/patch.py
+++ b/patch.py
@@ -221,6 +221,7 @@ class FilePatchDiff(FilePatchBase):
if old not in (self.filename, 'dev/null'):
# Copy or rename.
self.source_filename = old
+ self.is_new = True
last_line = ''
@@ -275,9 +276,10 @@ class FilePatchDiff(FilePatchBase):
if match:
if last_line[:3] in ('---', '+++'):
self._fail('--- and +++ are reversed')
- self.is_new = match.group(1) == '/dev/null'
- # TODO(maruel): Use self.source_file.
- if self.mangle(match.group(1)) not in (old, 'dev/null'):
+ if match.group(1) == '/dev/null':
+ self.is_new = True
+ elif self.mangle(match.group(1)) != old:
+ # git patches are always well formatted, do not allow random filenames.
self._fail('Unexpected git diff: %s != %s.' % (old, match.group(1)))
if not lines or not lines[0].startswith('+++'):
self._fail('Missing git diff output name.')
@@ -287,7 +289,6 @@ class FilePatchDiff(FilePatchBase):
if match:
if not last_line.startswith('---'):
self._fail('Unexpected git diff: --- not following +++.')
- # TODO(maruel): new == self.filename.
if '/dev/null' == match.group(1):
self.is_delete = True
elif self.filename != self.mangle(match.group(1)):
@@ -327,10 +328,12 @@ class FilePatchDiff(FilePatchBase):
if match:
if last_line[:3] in ('---', '+++'):
self._fail('--- and +++ are reversed')
- self.is_new = match.group(1) == '/dev/null'
- if (self.mangle(match.group(1)) != self.filename and
- match.group(1) != '/dev/null'):
+ if match.group(1) == '/dev/null':
+ self.is_new = True
+ elif self.mangle(match.group(1)) != self.filename:
+ # guess the source filename.
self.source_filename = match.group(1)
+ self.is_new = True
if not lines or not lines[0].startswith('+++'):
self._fail('Nothing after header.')
return
« no previous file with comments | « no previous file | tests/patch_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698