changeset 3997:156cb1cdd7ad

Added handling of copied files diff parsing
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 15 Jun 2013 20:47:41 +0200
parents 267bb347d68c
children 6133e598f4b4
files rhodecode/lib/diffs.py rhodecode/tests/fixtures/hg_diff_copy_file.diff rhodecode/tests/models/test_diff_parsers.py
diffstat 3 files changed, 22 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/lib/diffs.py	Sat Jun 15 14:37:51 2013 +0200
+++ b/rhodecode/lib/diffs.py	Sat Jun 15 20:47:41 2013 +0200
@@ -127,8 +127,9 @@
 DEL_FILENODE = 2
 MOD_FILENODE = 3
 RENAMED_FILENODE = 4
-CHMOD_FILENODE = 5
-BIN_FILENODE = 6
+COPIED_FILENODE = 5
+CHMOD_FILENODE = 6
+BIN_FILENODE = 7
 
 
 class DiffLimitExceeded(Exception):
@@ -179,6 +180,8 @@
         (?:^similarity[ ]index[ ](?P<similarity_index>\d+)%(?:\n|$))?
         (?:^rename[ ]from[ ](?P<rename_from>\S+)\n
            ^rename[ ]to[ ](?P<rename_to>\S+)(?:\n|$))?
+        (?:^copy[ ]from[ ](?P<copy_from>\S+)\n
+           ^copy[ ]to[ ](?P<copy_to>\S+)(?:\n|$))?
         (?:^new[ ]file[ ]mode[ ](?P<new_file_mode>.+)(?:\n|$))?
         (?:^deleted[ ]file[ ]mode[ ](?P<deleted_file_mode>.+)(?:\n|$))?
         (?:^index[ ](?P<a_blob_id>[0-9A-Fa-f]+)
@@ -388,7 +391,12 @@
                     stats['binary'] = True
                     stats['ops'][RENAMED_FILENODE] = ('file renamed from %s to %s'
                                     % (head['rename_from'], head['rename_to']))
-
+                # COPY
+                if head['copy_from'] and head['copy_to']:
+                    op = 'M'
+                    stats['binary'] = True
+                    stats['ops'][COPIED_FILENODE] = ('file copied from %s to %s'
+                                        % (head['copy_from'], head['copy_to']))
                 # FALL BACK: detect missed old style add or remove
                 if op is None:
                     if not head['a_file'] and head['b_file']:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rhodecode/tests/fixtures/hg_diff_copy_file.diff	Sat Jun 15 20:47:41 2013 +0200
@@ -0,0 +1,3 @@
+diff --git a/file1 b/file2
+copy from file1
+copy to file2
--- a/rhodecode/tests/models/test_diff_parsers.py	Sat Jun 15 14:37:51 2013 +0200
+++ b/rhodecode/tests/models/test_diff_parsers.py	Sat Jun 15 20:47:41 2013 +0200
@@ -2,7 +2,7 @@
 import os
 from rhodecode.tests import *
 from rhodecode.lib.diffs import DiffProcessor, NEW_FILENODE, DEL_FILENODE, \
-    MOD_FILENODE, RENAMED_FILENODE, CHMOD_FILENODE, BIN_FILENODE
+    MOD_FILENODE, RENAMED_FILENODE, CHMOD_FILENODE, BIN_FILENODE, COPIED_FILENODE
 
 dn = os.path.dirname
 FIXTURES = os.path.join(dn(dn(os.path.abspath(__file__))), 'fixtures')
@@ -217,6 +217,13 @@
           'binary': False,
           'ops': {MOD_FILENODE: 'modified file'}}),
     ],
+    'hg_diff_copy_file.diff': [
+        ('file2', 'M',
+         {'added': 0,
+          'deleted': 0,
+          'binary': True,
+          'ops': {COPIED_FILENODE: 'file copied from file1 to file2'}}),
+    ]
 #     'large_diff.diff': [
 #         ('.hgignore', 'A', {'deleted': 0, 'binary': False, 'added': 3, 'ops': {1: 'new file 100644'}}),
 #         ('MANIFEST.in', 'A', {'deleted': 0, 'binary': False, 'added': 3, 'ops': {1: 'new file 100644'}}),