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

problem:

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.

solution:

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.
authorAlain Leufroy <alain.leufroy@logilab.fr>
changeset72fc7853ff59
branchstable
phasepublic
hiddenno
parent revision#79c3cb579632 dirty patch to allow execution in py2exe executable (closes #122101)
child revision#30fdc10d8ebf qt: set window titles for file views
files modified by this revision
hgviewlib/hggraph.py
# HG changeset patch
# User Alain Leufroy <alain.leufroy@logilab.fr>
# Date 1363265918 -3600
# Thu Mar 14 13:58:38 2013 +0100
# Branch stable
# Node ID 72fc7853ff59e718df2063a348ca9eda03759461
# Parent 79c3cb579632225493adef4b47fc8de7af91595e
[lib] file diff: fix missing diff (closes #122649)

problem:

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.

solution:

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.

diff --git a/hgviewlib/hggraph.py b/hgviewlib/hggraph.py
@@ -17,10 +17,11 @@
1  Based on graphlog's algorithm, with inspiration stolen to TortoiseHg
2  revision grapher.
3  """
4 
5  import os
6 +import re
7  from cStringIO import StringIO
8  import difflib
9  from itertools import chain, count
10  from time import strftime, localtime
11  from functools import partial
@@ -33,10 +34,13 @@
12 
13  from hgviewlib.util import tounicode, isbfile, first_known_precursors, build_repo
14  from hgviewlib.config import HgConfig
15 
16  DATE_FMT = '%F %R'
17 +# match the end of the diff header, assuming that the following line
18 +# looks like "@@ -25,6 +23,5 @@"
19 +DIFFHEADERMATCHER = re.compile('^@@.+@@$', re.MULTILINE)
20 
21  def diff(repo, ctx1, ctx2=None, files=None):
22      """
23      Compute the diff of ``files`` between the 2 contexts ``ctx1`` and ``ctx2``.
24 
@@ -529,12 +533,16 @@
25                  if isinstance(mode, int):
26                      parentctx = self.repo.changectx(mode)
27                  else:
28                      parentctx = self.repo[self._fileparent(fctx)]
29                  data = diff(self.repo, ctx, parentctx, files=[filename])
30 -                # we assume that \n@@ marks the end of the diff header
31 -                data = ''.join(data.partition(os.linesep + '@@')[1:]).lstrip()
32 +                match = DIFFHEADERMATCHER.search(data)
33 +                if match is not None:
34 +                    datastart = match.start()
35 +                else:
36 +                    datastart = 0
37 +                data = data[datastart:]
38              elif flag == '':
39                  data = ''
40              else: # file renamed
41                  oldname, node = flag
42                  newdata = fctx.data().splitlines()