Alain Leufroy committed 72fc785

[lib] file diff: fix missing diff (closes #122649)


HgView removes the header of the displayed diff assuming that the
content data starts this ``os.linesep+'@@'``. But the newline chars
may be different from the system linesep. By this way the entire
diff is interpreted as the header resulting into an empty diff body.


Use a more clever text-matching tool ``re`` with the pattern
``^@@.*@@$`` which correspond to a hunk header --- the first hunk
corresponds to the end of the diff header.

Comments (0)

Files changed (1)


 import os
+import re
 from cStringIO import StringIO
 import difflib
 from itertools import chain, count
 from hgviewlib.config import HgConfig
 DATE_FMT = '%F %R'
+# match the end of the diff header, assuming that the following line
+# looks like "@@ -25,6 +23,5 @@"
+DIFFHEADERMATCHER = re.compile('^@@.+@@$', re.MULTILINE)
 def diff(repo, ctx1, ctx2=None, files=None):
                     parentctx = self.repo[self._fileparent(fctx)]
                 data = diff(self.repo, ctx, parentctx, files=[filename])
-                # we assume that \n@@ marks the end of the diff header
-                data = ''.join(data.partition(os.linesep + '@@')[1:]).lstrip()
+                match =
+                if match is not None:
+                    datastart = match.start()
+                else:
+                    datastart = 0
+                data = data[datastart:]
             elif flag == '':
                 data = ''
             else: # file renamed