# HG changeset patch # User Marcin Kuzminski # Date 1371322061 -7200 # Node ID 156cb1cdd7ad380f9ad2eaf1f30e4f15d3d5ffc6 # Parent 267bb347d68cac089197e769bd83e3acebce671f Added handling of copied files diff parsing diff -r 267bb347d68c -r 156cb1cdd7ad rhodecode/lib/diffs.py --- 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\d+)%(?:\n|$))? (?:^rename[ ]from[ ](?P\S+)\n ^rename[ ]to[ ](?P\S+)(?:\n|$))? + (?:^copy[ ]from[ ](?P\S+)\n + ^copy[ ]to[ ](?P\S+)(?:\n|$))? (?:^new[ ]file[ ]mode[ ](?P.+)(?:\n|$))? (?:^deleted[ ]file[ ]mode[ ](?P.+)(?:\n|$))? (?:^index[ ](?P[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']: diff -r 267bb347d68c -r 156cb1cdd7ad rhodecode/tests/fixtures/hg_diff_copy_file.diff --- /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 diff -r 267bb347d68c -r 156cb1cdd7ad rhodecode/tests/models/test_diff_parsers.py --- 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'}}),