Commit 8baaea7b authored by maruel@chromium.org's avatar maruel@chromium.org

Add automatic is_new=True on git copy or rename.

R=dpranke@chromium.org
BUG=
TEST=


Review URL: http://codereview.chromium.org/7847005

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@100140 0039d316-1c4b-4281-b951-d872f2087c98
parent a19047cd
...@@ -221,6 +221,7 @@ class FilePatchDiff(FilePatchBase): ...@@ -221,6 +221,7 @@ class FilePatchDiff(FilePatchBase):
if old not in (self.filename, 'dev/null'): if old not in (self.filename, 'dev/null'):
# Copy or rename. # Copy or rename.
self.source_filename = old self.source_filename = old
self.is_new = True
last_line = '' last_line = ''
...@@ -275,9 +276,10 @@ class FilePatchDiff(FilePatchBase): ...@@ -275,9 +276,10 @@ class FilePatchDiff(FilePatchBase):
if match: if match:
if last_line[:3] in ('---', '+++'): if last_line[:3] in ('---', '+++'):
self._fail('--- and +++ are reversed') self._fail('--- and +++ are reversed')
self.is_new = match.group(1) == '/dev/null' if match.group(1) == '/dev/null':
# TODO(maruel): Use self.source_file. self.is_new = True
if self.mangle(match.group(1)) not in (old, 'dev/null'): 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))) self._fail('Unexpected git diff: %s != %s.' % (old, match.group(1)))
if not lines or not lines[0].startswith('+++'): if not lines or not lines[0].startswith('+++'):
self._fail('Missing git diff output name.') self._fail('Missing git diff output name.')
...@@ -287,7 +289,6 @@ class FilePatchDiff(FilePatchBase): ...@@ -287,7 +289,6 @@ class FilePatchDiff(FilePatchBase):
if match: if match:
if not last_line.startswith('---'): if not last_line.startswith('---'):
self._fail('Unexpected git diff: --- not following +++.') self._fail('Unexpected git diff: --- not following +++.')
# TODO(maruel): new == self.filename.
if '/dev/null' == match.group(1): if '/dev/null' == match.group(1):
self.is_delete = True self.is_delete = True
elif self.filename != self.mangle(match.group(1)): elif self.filename != self.mangle(match.group(1)):
...@@ -327,10 +328,12 @@ class FilePatchDiff(FilePatchBase): ...@@ -327,10 +328,12 @@ class FilePatchDiff(FilePatchBase):
if match: if match:
if last_line[:3] in ('---', '+++'): if last_line[:3] in ('---', '+++'):
self._fail('--- and +++ are reversed') self._fail('--- and +++ are reversed')
self.is_new = match.group(1) == '/dev/null' if match.group(1) == '/dev/null':
if (self.mangle(match.group(1)) != self.filename and self.is_new = True
match.group(1) != '/dev/null'): elif self.mangle(match.group(1)) != self.filename:
# guess the source filename.
self.source_filename = match.group(1) self.source_filename = match.group(1)
self.is_new = True
if not lines or not lines[0].startswith('+++'): if not lines or not lines[0].startswith('+++'):
self._fail('Nothing after header.') self._fail('Nothing after header.')
return return
......
...@@ -459,7 +459,7 @@ class PatchTest(unittest.TestCase): ...@@ -459,7 +459,7 @@ class PatchTest(unittest.TestCase):
p = patch.FilePatchDiff('tools/run_local_server.sh', GIT_RENAME, []) p = patch.FilePatchDiff('tools/run_local_server.sh', GIT_RENAME, [])
self._check_patch(p, 'tools/run_local_server.sh', GIT_RENAME, self._check_patch(p, 'tools/run_local_server.sh', GIT_RENAME,
is_git_diff=True, patchlevel=1, is_git_diff=True, patchlevel=1,
source_filename='tools/run_local_server.PY') source_filename='tools/run_local_server.PY', is_new=True)
def testGitRenamePartial(self): def testGitRenamePartial(self):
p = patch.FilePatchDiff( p = patch.FilePatchDiff(
...@@ -467,12 +467,12 @@ class PatchTest(unittest.TestCase): ...@@ -467,12 +467,12 @@ class PatchTest(unittest.TestCase):
self._check_patch( self._check_patch(
p, 'chromeos/views/webui_menu_widget.h', GIT_RENAME_PARTIAL, p, 'chromeos/views/webui_menu_widget.h', GIT_RENAME_PARTIAL,
source_filename='chromeos/views/DOMui_menu_widget.h', is_git_diff=True, source_filename='chromeos/views/DOMui_menu_widget.h', is_git_diff=True,
patchlevel=1) patchlevel=1, is_new=True)
def testGitCopy(self): def testGitCopy(self):
p = patch.FilePatchDiff('pp', GIT_COPY, []) p = patch.FilePatchDiff('pp', GIT_COPY, [])
self._check_patch(p, 'pp', GIT_COPY, is_git_diff=True, patchlevel=1, self._check_patch(p, 'pp', GIT_COPY, is_git_diff=True, patchlevel=1,
source_filename='PRESUBMIT.py') source_filename='PRESUBMIT.py', is_new=True)
def testOnlyHeader(self): def testOnlyHeader(self):
diff = '--- file_a\n+++ file_a\n' diff = '--- file_a\n+++ file_a\n'
...@@ -503,7 +503,7 @@ class PatchTest(unittest.TestCase): ...@@ -503,7 +503,7 @@ class PatchTest(unittest.TestCase):
diff = '--- file_a\n+++ file_b\n' diff = '--- file_a\n+++ file_b\n'
p = patch.FilePatchDiff('file_b', diff, []) p = patch.FilePatchDiff('file_b', diff, [])
# Should it be marked as new? # Should it be marked as new?
self._check_patch(p, 'file_b', diff, source_filename='file_a') self._check_patch(p, 'file_b', diff, source_filename='file_a', is_new=True)
def testGitCopyPartial(self): def testGitCopyPartial(self):
diff = ( diff = (
...@@ -523,7 +523,8 @@ class PatchTest(unittest.TestCase): ...@@ -523,7 +523,8 @@ class PatchTest(unittest.TestCase):
p = patch.FilePatchDiff('wtf2', diff, []) p = patch.FilePatchDiff('wtf2', diff, [])
# Should it be marked as new? # Should it be marked as new?
self._check_patch( self._check_patch(
p, 'wtf2', diff, source_filename='wtf', is_git_diff=True, patchlevel=1) p, 'wtf2', diff, source_filename='wtf', is_git_diff=True, patchlevel=1,
is_new=True)
def testGitExe(self): def testGitExe(self):
diff = ( diff = (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment