# HG changeset patch # User Mads Kiilerich # Date 1418647656 -3600 # Node ID 11d6d1cec6674bbb9c31716693643eedba50e236 # Parent 9740ec3be07accbf89e583278712cdf4f8cf8636 diff: fix diff of renamed files with whitespace in their names Before, header parsing would fail. diff -r 9740ec3be07a -r 11d6d1cec667 kallithea/lib/diffs.py --- a/kallithea/lib/diffs.py Mon Dec 15 13:47:36 2014 +0100 +++ b/kallithea/lib/diffs.py Mon Dec 15 13:47:36 2014 +0100 @@ -157,11 +157,12 @@ _chunk_re = re.compile(r'^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)') _newline_marker = re.compile(r'^\\ No newline at end of file') _git_header_re = re.compile(r""" - #^diff[ ]--git + # has already been split on this: + # ^diff[ ]--git [ ]a/(?P.+?)[ ]b/(?P.+?)\n (?:^similarity[ ]index[ ](?P\d+)%\n - ^rename[ ]from[ ](?P\S+)\n - ^rename[ ]to[ ](?P\S+)(?:\n|$))? + ^rename[ ]from[ ](?P.+)\n + ^rename[ ]to[ ](?P.+)(?:\n|$))? (?:^old[ ]mode[ ](?P\d+)\n ^new[ ]mode[ ](?P\d+)(?:\n|$))? (?:^new[ ]file[ ]mode[ ](?P.+)(?:\n|$))? @@ -173,15 +174,16 @@ (?:^\+\+\+[ ](b/(?P.+)|/dev/null)(?:\n|$))? """, re.VERBOSE | re.MULTILINE) _hg_header_re = re.compile(r""" - #^diff[ ]--git + # has already been split on this: + # ^diff[ ]--git [ ]a/(?P.+?)[ ]b/(?P.+?)\n (?:^old[ ]mode[ ](?P\d+)\n ^new[ ]mode[ ](?P\d+)(?:\n|$))? (?:^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|$))? + (?:^rename[ ]from[ ](?P.+)\n + ^rename[ ]to[ ](?P.+)(?:\n|$))? + (?:^copy[ ]from[ ](?P.+)\n + ^copy[ ]to[ ](?P.+)(?:\n|$))? (?:^new[ ]file[ ]mode[ ](?P.+)(?:\n|$))? (?:^deleted[ ]file[ ]mode[ ](?P.+)(?:\n|$))? (?:^index[ ](?P[0-9A-Fa-f]+) diff -r 9740ec3be07a -r 11d6d1cec667 kallithea/tests/fixtures/hg_diff_rename_space_cr.diff --- a/kallithea/tests/fixtures/hg_diff_rename_space_cr.diff Mon Dec 15 13:47:36 2014 +0100 +++ b/kallithea/tests/fixtures/hg_diff_rename_space_cr.diff Mon Dec 15 13:47:36 2014 +0100 @@ -1,12 +1,12 @@ -diff --git a/ohno b/ohyes -rename from ohno -rename to ohyes ---- a/ohno -+++ b/ohyes +diff --git a/oh no b/oh yes +rename from oh no +rename to oh yes +--- a/oh no ++++ b/oh yes @@ -1,5 +1,6 @@ 1 -2 + 2 --3 +-3 +2 +3 4 diff -r 9740ec3be07a -r 11d6d1cec667 kallithea/tests/models/test_diff_parsers.py --- a/kallithea/tests/models/test_diff_parsers.py Mon Dec 15 13:47:36 2014 +0100 +++ b/kallithea/tests/models/test_diff_parsers.py Mon Dec 15 13:47:36 2014 +0100 @@ -248,11 +248,11 @@ MOD_FILENODE: 'modified file'}}), ], 'hg_diff_rename_space_cr.diff': [ - ('ohyes', 'R', + ('oh yes', 'R', {'added': 4, 'deleted': 2, 'binary': False, - 'ops': {RENAMED_FILENODE: 'file renamed from ohno to ohyes'}}), + 'ops': {RENAMED_FILENODE: 'file renamed from oh no to oh yes'}}), ], }