annotate rhodecode/lib/diffs.py @ 2887:b78e6f7f3ab9 beta

Change the translated term for 'fork', its now translated as '复刻'. (Thanks Hanlei Qin <qinhanlei@gmail.com>)
author xpol
date Tue, 02 Oct 2012 13:48:03 +0800
parents ab75def5c15d
children 5fba3778431c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 rhodecode.lib.diffs
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 ~~~~~~~~~~~~~~~~~~~
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 Set of diffing helpers, previously part of vcs
1781
089c81cf04d9 fixes #326 some html special chars where not escaped in diffs + code garden in helpers
Marcin Kuzminski <marcin@python-works.com>
parents: 1772
diff changeset
7
089c81cf04d9 fixes #326 some html special chars where not escaped in diffs + code garden in helpers
Marcin Kuzminski <marcin@python-works.com>
parents: 1772
diff changeset
8
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 :created_on: Dec 4, 2011
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 :author: marcink
1824
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1789
diff changeset
11 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
1781
089c81cf04d9 fixes #326 some html special chars where not escaped in diffs + code garden in helpers
Marcin Kuzminski <marcin@python-works.com>
parents: 1772
diff changeset
12 :original copyright: 2007-2008 by Armin Ronacher
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13 :license: GPLv3, see COPYING for more details.
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15 # This program is free software: you can redistribute it and/or modify
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16 # it under the terms of the GNU General Public License as published by
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 # the Free Software Foundation, either version 3 of the License, or
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 # (at your option) any later version.
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 #
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 # This program is distributed in the hope that it will be useful,
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 # GNU General Public License for more details.
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 #
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 # You should have received a copy of the GNU General Public License
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 # along with this program. If not, see <http://www.gnu.org/licenses/>.
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28 import re
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 import difflib
1789
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
30 import markupsafe
2355
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
31
1789
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
32 from itertools import tee, imap
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33
2355
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
34 from mercurial import patch
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
35 from mercurial.mdiff import diffopts
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
36 from mercurial.bundlerepo import bundlerepository
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
37
1789
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
38 from pylons.i18n.translation import _
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39
2552
e8650fbc4d4e Moved BytesIO into compat because of py25 compatibility issue
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
40 from rhodecode.lib.compat import BytesIO
2684
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2567
diff changeset
41 from rhodecode.lib.vcs.utils.hgcompat import localrepo
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents: 1894
diff changeset
42 from rhodecode.lib.vcs.exceptions import VCSError
2233
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2084
diff changeset
43 from rhodecode.lib.vcs.nodes import FileNode, SubModuleNode
2684
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2567
diff changeset
44 from rhodecode.lib.vcs.backends.base import EmptyChangeset
2233
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2084
diff changeset
45 from rhodecode.lib.helpers import escape
2684
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2567
diff changeset
46 from rhodecode.lib.utils import make_ui
2843
ab75def5c15d fixes #567 diff non-unicode encoding missmatch
Marcin Kuzminski <marcin@python-works.com>
parents: 2801
diff changeset
47 from rhodecode.lib.utils2 import safe_unicode
1789
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
48
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
49
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
50 def wrap_to_table(str_):
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
51 return '''<table class="code-difftable">
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
52 <tr class="line no-comment">
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
53 <td class="lineno new"></td>
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
54 <td class="code no-comment"><pre>%s</pre></td>
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
55 </tr>
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
56 </table>''' % str_
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
57
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
58
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
59 def wrapped_diff(filenode_old, filenode_new, cut_off_limit=None,
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
60 ignore_whitespace=True, line_context=3,
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
61 enable_comments=False):
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
62 """
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
63 returns a wrapped diff into a table, checks for cut_off_limit and presents
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
64 proper message
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
65 """
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
66
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
67 if filenode_old is None:
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
68 filenode_old = FileNode(filenode_new.path, '', EmptyChangeset())
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
69
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
70 if filenode_old.is_binary or filenode_new.is_binary:
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
71 diff = wrap_to_table(_('binary file'))
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
72 stats = (0, 0)
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
73 size = 0
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
74
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
75 elif cut_off_limit != -1 and (cut_off_limit is None or
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
76 (filenode_old.size < cut_off_limit and filenode_new.size < cut_off_limit)):
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
77
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
78 f_gitdiff = get_gitdiff(filenode_old, filenode_new,
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
79 ignore_whitespace=ignore_whitespace,
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
80 context=line_context)
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
81 diff_processor = DiffProcessor(f_gitdiff, format='gitdiff')
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
82
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
83 diff = diff_processor.as_html(enable_comments=enable_comments)
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
84 stats = diff_processor.stat()
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
85 size = len(diff or '')
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
86 else:
2340
93243e162068 typo fix ref #461
Marcin Kuzminski <marcin@python-works.com>
parents: 2233
diff changeset
87 diff = wrap_to_table(_('Changeset was too big and was cut off, use '
1789
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
88 'diff menu to display this diff'))
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
89 stats = (0, 0)
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
90 size = 0
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
91 if not diff:
2233
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2084
diff changeset
92 submodules = filter(lambda o: isinstance(o, SubModuleNode),
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2084
diff changeset
93 [filenode_new, filenode_old])
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2084
diff changeset
94 if submodules:
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2084
diff changeset
95 diff = wrap_to_table(escape('Submodule %r' % submodules[0]))
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2084
diff changeset
96 else:
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2084
diff changeset
97 diff = wrap_to_table(_('No changes detected'))
1789
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
98
2084
feb0fccdcf83 fixed vcs issue with last_changeset for filenodes
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
99 cs1 = filenode_old.changeset.raw_id
feb0fccdcf83 fixed vcs issue with last_changeset for filenodes
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
100 cs2 = filenode_new.changeset.raw_id
1789
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
101
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
102 return size, cs1, cs2, diff, stats
1781
089c81cf04d9 fixes #326 some html special chars where not escaped in diffs + code garden in helpers
Marcin Kuzminski <marcin@python-works.com>
parents: 1772
diff changeset
103
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
104
1768
5610fd9b6803 added line context control to diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
105 def get_gitdiff(filenode_old, filenode_new, ignore_whitespace=True, context=3):
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
106 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
107 Returns git style diff between given ``filenode_old`` and ``filenode_new``.
1781
089c81cf04d9 fixes #326 some html special chars where not escaped in diffs + code garden in helpers
Marcin Kuzminski <marcin@python-works.com>
parents: 1772
diff changeset
108
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
109 :param ignore_whitespace: ignore whitespaces in diff
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
110 """
1894
0cbc3fb540b0 adapt codes to latest vcs
Marcin Kuzminski <marcin@python-works.com>
parents: 1883
diff changeset
111 # make sure we pass in default context
0cbc3fb540b0 adapt codes to latest vcs
Marcin Kuzminski <marcin@python-works.com>
parents: 1883
diff changeset
112 context = context or 3
2233
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2084
diff changeset
113 submodules = filter(lambda o: isinstance(o, SubModuleNode),
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2084
diff changeset
114 [filenode_new, filenode_old])
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2084
diff changeset
115 if submodules:
07fce1930417 fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2084
diff changeset
116 return ''
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
117
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
118 for filenode in (filenode_old, filenode_new):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
119 if not isinstance(filenode, FileNode):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
120 raise VCSError("Given object should be FileNode object, not %s"
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
121 % filenode.__class__)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
122
1894
0cbc3fb540b0 adapt codes to latest vcs
Marcin Kuzminski <marcin@python-works.com>
parents: 1883
diff changeset
123 repo = filenode_new.changeset.repository
0cbc3fb540b0 adapt codes to latest vcs
Marcin Kuzminski <marcin@python-works.com>
parents: 1883
diff changeset
124 old_raw_id = getattr(filenode_old.changeset, 'raw_id', repo.EMPTY_CHANGESET)
0cbc3fb540b0 adapt codes to latest vcs
Marcin Kuzminski <marcin@python-works.com>
parents: 1883
diff changeset
125 new_raw_id = getattr(filenode_new.changeset, 'raw_id', repo.EMPTY_CHANGESET)
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
126
1883
69d3c4450944 fix for latest vcs
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
127 vcs_gitdiff = repo.get_diff(old_raw_id, new_raw_id, filenode_new.path,
1768
5610fd9b6803 added line context control to diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
128 ignore_whitespace, context)
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
129 return vcs_gitdiff
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
130
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
131
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
132 class DiffProcessor(object):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
133 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
134 Give it a unified diff and it returns a list of the files that were
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
135 mentioned in the diff together with a dict of meta information that
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
136 can be used to render it in a HTML template.
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
137 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
138 _chunk_re = re.compile(r'@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)')
2567
5fe0f744bec0 fixed issue #492 missing `\ No newline at end of file` test at the end of new chunk
Marcin Kuzminski <marcin@python-works.com>
parents: 2566
diff changeset
139 _newline_marker = '\\ No newline at end of file\n'
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
140
2385
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
141 def __init__(self, diff, differ='diff', format='gitdiff'):
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
142 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
143 :param diff: a text in diff format or generator
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
144 :param format: format of diff passed, `udiff` or `gitdiff`
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
145 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
146 if isinstance(diff, basestring):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
147 diff = [diff]
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
148
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
149 self.__udiff = diff
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
150 self.__format = format
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
151 self.adds = 0
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
152 self.removes = 0
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
153
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
154 if isinstance(self.__udiff, basestring):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
155 self.lines = iter(self.__udiff.splitlines(1))
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
156
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
157 elif self.__format == 'gitdiff':
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
158 udiff_copy = self.copy_iterator()
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
159 self.lines = imap(self.escaper, self._parse_gitdiff(udiff_copy))
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
160 else:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
161 udiff_copy = self.copy_iterator()
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
162 self.lines = imap(self.escaper, udiff_copy)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
163
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
164 # Select a differ.
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
165 if differ == 'difflib':
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
166 self.differ = self._highlight_line_difflib
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
167 else:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
168 self.differ = self._highlight_line_udiff
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
169
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
170 def escaper(self, string):
1781
089c81cf04d9 fixes #326 some html special chars where not escaped in diffs + code garden in helpers
Marcin Kuzminski <marcin@python-works.com>
parents: 1772
diff changeset
171 return markupsafe.escape(string)
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
172
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
173 def copy_iterator(self):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
174 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
175 make a fresh copy of generator, we should not iterate thru
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
176 an original as it's needed for repeating operations on
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
177 this instance of DiffProcessor
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
178 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
179 self.__udiff, iterator_copy = tee(self.__udiff)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
180 return iterator_copy
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
181
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
182 def _extract_rev(self, line1, line2):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
183 """
2385
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
184 Extract the operation (A/M/D), filename and revision hint from a line.
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
185 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
186
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
187 try:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
188 if line1.startswith('--- ') and line2.startswith('+++ '):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
189 l1 = line1[4:].split(None, 1)
1787
d4a7b6c82efe code garden for changeset ranges and comments
Marcin Kuzminski <marcin@python-works.com>
parents: 1781
diff changeset
190 old_filename = (l1[0].replace('a/', '', 1)
d4a7b6c82efe code garden for changeset ranges and comments
Marcin Kuzminski <marcin@python-works.com>
parents: 1781
diff changeset
191 if len(l1) >= 1 else None)
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
192 old_rev = l1[1] if len(l1) == 2 else 'old'
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
193
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
194 l2 = line2[4:].split(None, 1)
1787
d4a7b6c82efe code garden for changeset ranges and comments
Marcin Kuzminski <marcin@python-works.com>
parents: 1781
diff changeset
195 new_filename = (l2[0].replace('b/', '', 1)
d4a7b6c82efe code garden for changeset ranges and comments
Marcin Kuzminski <marcin@python-works.com>
parents: 1781
diff changeset
196 if len(l1) >= 1 else None)
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
197 new_rev = l2[1] if len(l2) == 2 else 'new'
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
198
1787
d4a7b6c82efe code garden for changeset ranges and comments
Marcin Kuzminski <marcin@python-works.com>
parents: 1781
diff changeset
199 filename = (old_filename
d4a7b6c82efe code garden for changeset ranges and comments
Marcin Kuzminski <marcin@python-works.com>
parents: 1781
diff changeset
200 if old_filename != '/dev/null' else new_filename)
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
201
2385
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
202 operation = 'D' if new_filename == '/dev/null' else None
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
203 if not operation:
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
204 operation = 'M' if old_filename != '/dev/null' else 'A'
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
205
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
206 return operation, filename, new_rev, old_rev
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
207 except (ValueError, IndexError):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
208 pass
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
209
2385
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
210 return None, None, None, None
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
211
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
212 def _parse_gitdiff(self, diffiterator):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
213 def line_decoder(l):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
214 if l.startswith('+') and not l.startswith('+++'):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
215 self.adds += 1
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
216 elif l.startswith('-') and not l.startswith('---'):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
217 self.removes += 1
2843
ab75def5c15d fixes #567 diff non-unicode encoding missmatch
Marcin Kuzminski <marcin@python-works.com>
parents: 2801
diff changeset
218 return safe_unicode(l)
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
219
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
220 output = list(diffiterator)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
221 size = len(output)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
222
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
223 if size == 2:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
224 l = []
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
225 l.extend([output[0]])
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
226 l.extend(output[1].splitlines(1))
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
227 return map(line_decoder, l)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
228 elif size == 1:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
229 return map(line_decoder, output[0].splitlines(1))
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
230 elif size == 0:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
231 return []
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
232
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
233 raise Exception('wrong size of diff %s' % size)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
234
1781
089c81cf04d9 fixes #326 some html special chars where not escaped in diffs + code garden in helpers
Marcin Kuzminski <marcin@python-works.com>
parents: 1772
diff changeset
235 def _highlight_line_difflib(self, line, next_):
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
236 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
237 Highlight inline changes in both lines.
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
238 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
239
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
240 if line['action'] == 'del':
1781
089c81cf04d9 fixes #326 some html special chars where not escaped in diffs + code garden in helpers
Marcin Kuzminski <marcin@python-works.com>
parents: 1772
diff changeset
241 old, new = line, next_
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
242 else:
1781
089c81cf04d9 fixes #326 some html special chars where not escaped in diffs + code garden in helpers
Marcin Kuzminski <marcin@python-works.com>
parents: 1772
diff changeset
243 old, new = next_, line
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
244
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
245 oldwords = re.split(r'(\W)', old['line'])
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
246 newwords = re.split(r'(\W)', new['line'])
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
247
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
248 sequence = difflib.SequenceMatcher(None, oldwords, newwords)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
249
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
250 oldfragments, newfragments = [], []
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
251 for tag, i1, i2, j1, j2 in sequence.get_opcodes():
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
252 oldfrag = ''.join(oldwords[i1:i2])
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
253 newfrag = ''.join(newwords[j1:j2])
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
254 if tag != 'equal':
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
255 if oldfrag:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
256 oldfrag = '<del>%s</del>' % oldfrag
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
257 if newfrag:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
258 newfrag = '<ins>%s</ins>' % newfrag
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
259 oldfragments.append(oldfrag)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
260 newfragments.append(newfrag)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
261
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
262 old['line'] = "".join(oldfragments)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
263 new['line'] = "".join(newfragments)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
264
1781
089c81cf04d9 fixes #326 some html special chars where not escaped in diffs + code garden in helpers
Marcin Kuzminski <marcin@python-works.com>
parents: 1772
diff changeset
265 def _highlight_line_udiff(self, line, next_):
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
266 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
267 Highlight inline changes in both lines.
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
268 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
269 start = 0
1781
089c81cf04d9 fixes #326 some html special chars where not escaped in diffs + code garden in helpers
Marcin Kuzminski <marcin@python-works.com>
parents: 1772
diff changeset
270 limit = min(len(line['line']), len(next_['line']))
089c81cf04d9 fixes #326 some html special chars where not escaped in diffs + code garden in helpers
Marcin Kuzminski <marcin@python-works.com>
parents: 1772
diff changeset
271 while start < limit and line['line'][start] == next_['line'][start]:
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
272 start += 1
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
273 end = -1
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
274 limit -= start
1781
089c81cf04d9 fixes #326 some html special chars where not escaped in diffs + code garden in helpers
Marcin Kuzminski <marcin@python-works.com>
parents: 1772
diff changeset
275 while -end <= limit and line['line'][end] == next_['line'][end]:
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
276 end -= 1
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
277 end += 1
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
278 if start or end:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
279 def do(l):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
280 last = end + len(l['line'])
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
281 if l['action'] == 'add':
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
282 tag = 'ins'
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
283 else:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
284 tag = 'del'
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
285 l['line'] = '%s<%s>%s</%s>%s' % (
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
286 l['line'][:start],
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
287 tag,
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
288 l['line'][start:last],
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
289 tag,
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
290 l['line'][last:]
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
291 )
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
292 do(line)
1781
089c81cf04d9 fixes #326 some html special chars where not escaped in diffs + code garden in helpers
Marcin Kuzminski <marcin@python-works.com>
parents: 1772
diff changeset
293 do(next_)
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
294
2385
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
295 def _parse_udiff(self, inline_diff=True):
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
296 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
297 Parse the diff an return data for the template.
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
298 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
299 lineiter = self.lines
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
300 files = []
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
301 try:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
302 line = lineiter.next()
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
303 while 1:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
304 # continue until we found the old file
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
305 if not line.startswith('--- '):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
306 line = lineiter.next()
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
307 continue
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
308
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
309 chunks = []
2385
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
310 stats = [0, 0]
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
311 operation, filename, old_rev, new_rev = \
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
312 self._extract_rev(line, lineiter.next())
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
313 files.append({
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
314 'filename': filename,
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
315 'old_revision': old_rev,
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
316 'new_revision': new_rev,
2385
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
317 'chunks': chunks,
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
318 'operation': operation,
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
319 'stats': stats,
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
320 })
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
321
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
322 line = lineiter.next()
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
323 while line:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
324 match = self._chunk_re.match(line)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
325 if not match:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
326 break
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
327
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
328 lines = []
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
329 chunks.append(lines)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
330
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
331 old_line, old_end, new_line, new_end = \
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
332 [int(x or 1) for x in match.groups()[:-1]]
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
333 old_line -= 1
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
334 new_line -= 1
2359
a264d898ca08 Alwas show initial context on html diffs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2340
diff changeset
335 gr = match.groups()
a264d898ca08 Alwas show initial context on html diffs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2340
diff changeset
336 context = len(gr) == 5
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
337 old_end += old_line
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
338 new_end += new_line
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
339
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
340 if context:
2359
a264d898ca08 Alwas show initial context on html diffs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2340
diff changeset
341 # skip context only if it's first line
a264d898ca08 Alwas show initial context on html diffs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2340
diff changeset
342 if int(gr[0]) > 1:
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
343 lines.append({
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
344 'old_lineno': '...',
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
345 'new_lineno': '...',
1789
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
346 'action': 'context',
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
347 'line': line,
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
348 })
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
349
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
350 line = lineiter.next()
2567
5fe0f744bec0 fixed issue #492 missing `\ No newline at end of file` test at the end of new chunk
Marcin Kuzminski <marcin@python-works.com>
parents: 2566
diff changeset
351
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
352 while old_line < old_end or new_line < new_end:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
353 if line:
2567
5fe0f744bec0 fixed issue #492 missing `\ No newline at end of file` test at the end of new chunk
Marcin Kuzminski <marcin@python-works.com>
parents: 2566
diff changeset
354 command = line[0]
5fe0f744bec0 fixed issue #492 missing `\ No newline at end of file` test at the end of new chunk
Marcin Kuzminski <marcin@python-works.com>
parents: 2566
diff changeset
355 if command in ['+', '-', ' ']:
5fe0f744bec0 fixed issue #492 missing `\ No newline at end of file` test at the end of new chunk
Marcin Kuzminski <marcin@python-works.com>
parents: 2566
diff changeset
356 #only modify the line if it's actually a diff
5fe0f744bec0 fixed issue #492 missing `\ No newline at end of file` test at the end of new chunk
Marcin Kuzminski <marcin@python-works.com>
parents: 2566
diff changeset
357 # thing
5fe0f744bec0 fixed issue #492 missing `\ No newline at end of file` test at the end of new chunk
Marcin Kuzminski <marcin@python-works.com>
parents: 2566
diff changeset
358 line = line[1:]
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
359 else:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
360 command = ' '
2567
5fe0f744bec0 fixed issue #492 missing `\ No newline at end of file` test at the end of new chunk
Marcin Kuzminski <marcin@python-works.com>
parents: 2566
diff changeset
361
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
362 affects_old = affects_new = False
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
363
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
364 # ignore those if we don't expect them
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
365 if command in '#@':
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
366 continue
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
367 elif command == '+':
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
368 affects_new = True
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
369 action = 'add'
2385
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
370 stats[0] += 1
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
371 elif command == '-':
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
372 affects_old = True
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
373 action = 'del'
2385
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
374 stats[1] += 1
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
375 else:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
376 affects_old = affects_new = True
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
377 action = 'unmod'
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
378
2567
5fe0f744bec0 fixed issue #492 missing `\ No newline at end of file` test at the end of new chunk
Marcin Kuzminski <marcin@python-works.com>
parents: 2566
diff changeset
379 if line != self._newline_marker:
2360
c15c3430df74 fixed issue with git's `no new line..` messages inside diff block. It might sometimes happen that showed html diff was short one line because of this
Marcin Kuzminski <marcin@python-works.com>
parents: 2359
diff changeset
380 old_line += affects_old
c15c3430df74 fixed issue with git's `no new line..` messages inside diff block. It might sometimes happen that showed html diff was short one line because of this
Marcin Kuzminski <marcin@python-works.com>
parents: 2359
diff changeset
381 new_line += affects_new
c15c3430df74 fixed issue with git's `no new line..` messages inside diff block. It might sometimes happen that showed html diff was short one line because of this
Marcin Kuzminski <marcin@python-works.com>
parents: 2359
diff changeset
382 lines.append({
c15c3430df74 fixed issue with git's `no new line..` messages inside diff block. It might sometimes happen that showed html diff was short one line because of this
Marcin Kuzminski <marcin@python-works.com>
parents: 2359
diff changeset
383 'old_lineno': affects_old and old_line or '',
c15c3430df74 fixed issue with git's `no new line..` messages inside diff block. It might sometimes happen that showed html diff was short one line because of this
Marcin Kuzminski <marcin@python-works.com>
parents: 2359
diff changeset
384 'new_lineno': affects_new and new_line or '',
c15c3430df74 fixed issue with git's `no new line..` messages inside diff block. It might sometimes happen that showed html diff was short one line because of this
Marcin Kuzminski <marcin@python-works.com>
parents: 2359
diff changeset
385 'action': action,
c15c3430df74 fixed issue with git's `no new line..` messages inside diff block. It might sometimes happen that showed html diff was short one line because of this
Marcin Kuzminski <marcin@python-works.com>
parents: 2359
diff changeset
386 'line': line
c15c3430df74 fixed issue with git's `no new line..` messages inside diff block. It might sometimes happen that showed html diff was short one line because of this
Marcin Kuzminski <marcin@python-works.com>
parents: 2359
diff changeset
387 })
c15c3430df74 fixed issue with git's `no new line..` messages inside diff block. It might sometimes happen that showed html diff was short one line because of this
Marcin Kuzminski <marcin@python-works.com>
parents: 2359
diff changeset
388
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
389 line = lineiter.next()
2567
5fe0f744bec0 fixed issue #492 missing `\ No newline at end of file` test at the end of new chunk
Marcin Kuzminski <marcin@python-works.com>
parents: 2566
diff changeset
390 if line == self._newline_marker:
5fe0f744bec0 fixed issue #492 missing `\ No newline at end of file` test at the end of new chunk
Marcin Kuzminski <marcin@python-works.com>
parents: 2566
diff changeset
391 # we need to append to lines, since this is not
5fe0f744bec0 fixed issue #492 missing `\ No newline at end of file` test at the end of new chunk
Marcin Kuzminski <marcin@python-works.com>
parents: 2566
diff changeset
392 # counted in the line specs of diff
5fe0f744bec0 fixed issue #492 missing `\ No newline at end of file` test at the end of new chunk
Marcin Kuzminski <marcin@python-works.com>
parents: 2566
diff changeset
393 lines.append({
5fe0f744bec0 fixed issue #492 missing `\ No newline at end of file` test at the end of new chunk
Marcin Kuzminski <marcin@python-works.com>
parents: 2566
diff changeset
394 'old_lineno': '...',
5fe0f744bec0 fixed issue #492 missing `\ No newline at end of file` test at the end of new chunk
Marcin Kuzminski <marcin@python-works.com>
parents: 2566
diff changeset
395 'new_lineno': '...',
5fe0f744bec0 fixed issue #492 missing `\ No newline at end of file` test at the end of new chunk
Marcin Kuzminski <marcin@python-works.com>
parents: 2566
diff changeset
396 'action': 'context',
5fe0f744bec0 fixed issue #492 missing `\ No newline at end of file` test at the end of new chunk
Marcin Kuzminski <marcin@python-works.com>
parents: 2566
diff changeset
397 'line': line
5fe0f744bec0 fixed issue #492 missing `\ No newline at end of file` test at the end of new chunk
Marcin Kuzminski <marcin@python-works.com>
parents: 2566
diff changeset
398 })
2391
91fae60bf2b6 merge with beta
Marcin Kuzminski <marcin@python-works.com>
parents: 2364 2385
diff changeset
399
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
400 except StopIteration:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
401 pass
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
402
2385
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
403 sorter = lambda info: {'A': 0, 'M': 1, 'D': 2}.get(info['operation'])
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
404 if inline_diff is False:
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
405 return sorted(files, key=sorter)
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
406
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
407 # highlight inline changes
2385
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
408 for diff_data in files:
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
409 for chunk in diff_data['chunks']:
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
410 lineiter = iter(chunk)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
411 try:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
412 while 1:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
413 line = lineiter.next()
2566
d097d4bb0437 fix strikethrough issues on `No new line at end of file`
Marcin Kuzminski <marcin@python-works.com>
parents: 2552
diff changeset
414 if line['action'] not in ['unmod', 'context']:
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
415 nextline = lineiter.next()
2360
c15c3430df74 fixed issue with git's `no new line..` messages inside diff block. It might sometimes happen that showed html diff was short one line because of this
Marcin Kuzminski <marcin@python-works.com>
parents: 2359
diff changeset
416 if nextline['action'] in ['unmod', 'context'] or \
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
417 nextline['action'] == line['action']:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
418 continue
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
419 self.differ(line, nextline)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
420 except StopIteration:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
421 pass
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
422
2385
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
423 return sorted(files, key=sorter)
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
424
2385
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
425 def prepare(self, inline_diff=True):
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
426 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
427 Prepare the passed udiff for HTML rendering. It'l return a list
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
428 of dicts
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
429 """
2385
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
430 return self._parse_udiff(inline_diff=inline_diff)
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
431
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
432 def _safe_id(self, idstring):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
433 """Make a string safe for including in an id attribute.
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
434
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
435 The HTML spec says that id attributes 'must begin with
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
436 a letter ([A-Za-z]) and may be followed by any number
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
437 of letters, digits ([0-9]), hyphens ("-"), underscores
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
438 ("_"), colons (":"), and periods (".")'. These regexps
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
439 are slightly over-zealous, in that they remove colons
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
440 and periods unnecessarily.
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
441
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
442 Whitespace is transformed into underscores, and then
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
443 anything which is not a hyphen or a character that
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
444 matches \w (alphanumerics and underscore) is removed.
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
445
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
446 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
447 # Transform all whitespace to underscore
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
448 idstring = re.sub(r'\s', "_", '%s' % idstring)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
449 # Remove everything that is not a hyphen or a member of \w
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
450 idstring = re.sub(r'(?!-)\W', "", idstring).lower()
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
451 return idstring
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
452
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
453 def raw_diff(self):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
454 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
455 Returns raw string as udiff
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
456 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
457 udiff_copy = self.copy_iterator()
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
458 if self.__format == 'gitdiff':
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
459 udiff_copy = self._parse_gitdiff(udiff_copy)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
460 return u''.join(udiff_copy)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
461
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
462 def as_html(self, table_class='code-difftable', line_class='line',
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
463 new_lineno_class='lineno old', old_lineno_class='lineno new',
2385
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
464 code_class='code', enable_comments=False, diff_lines=None):
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
465 """
2349
0edbffa9e2e2 fixed bug with inline changes highlighter.
Marcin Kuzminski <marcin@python-works.com>
parents: 2347
diff changeset
466 Return given diff as html table with customized css classes
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
467 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
468 def _link_to_if(condition, label, url):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
469 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
470 Generates a link if condition is meet or just the label if not.
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
471 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
472
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
473 if condition:
1789
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
474 return '''<a href="%(url)s">%(label)s</a>''' % {
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
475 'url': url,
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
476 'label': label
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
477 }
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
478 else:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
479 return label
2385
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
480 if diff_lines is None:
a455b2c79c85 Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents: 2360
diff changeset
481 diff_lines = self.prepare()
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
482 _html_empty = True
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
483 _html = []
1789
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
484 _html.append('''<table class="%(table_class)s">\n''' % {
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
485 'table_class': table_class
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
486 })
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
487 for diff in diff_lines:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
488 for line in diff['chunks']:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
489 _html_empty = False
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
490 for change in line:
1789
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
491 _html.append('''<tr class="%(lc)s %(action)s">\n''' % {
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
492 'lc': line_class,
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
493 'action': change['action']
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
494 })
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
495 anchor_old_id = ''
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
496 anchor_new_id = ''
1789
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
497 anchor_old = "%(filename)s_o%(oldline_no)s" % {
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
498 'filename': self._safe_id(diff['filename']),
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
499 'oldline_no': change['old_lineno']
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
500 }
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
501 anchor_new = "%(filename)s_n%(oldline_no)s" % {
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
502 'filename': self._safe_id(diff['filename']),
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
503 'oldline_no': change['new_lineno']
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
504 }
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
505 cond_old = (change['old_lineno'] != '...' and
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
506 change['old_lineno'])
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
507 cond_new = (change['new_lineno'] != '...' and
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
508 change['new_lineno'])
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
509 if cond_old:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
510 anchor_old_id = 'id="%s"' % anchor_old
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
511 if cond_new:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
512 anchor_new_id = 'id="%s"' % anchor_new
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
513 ###########################################################
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
514 # OLD LINE NUMBER
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
515 ###########################################################
1789
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
516 _html.append('''\t<td %(a_id)s class="%(olc)s">''' % {
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
517 'a_id': anchor_old_id,
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
518 'olc': old_lineno_class
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
519 })
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
520
1789
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
521 _html.append('''%(link)s''' % {
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
522 'link': _link_to_if(True, change['old_lineno'],
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
523 '#%s' % anchor_old)
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
524 })
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
525 _html.append('''</td>\n''')
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
526 ###########################################################
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
527 # NEW LINE NUMBER
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
528 ###########################################################
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
529
1789
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
530 _html.append('''\t<td %(a_id)s class="%(nlc)s">''' % {
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
531 'a_id': anchor_new_id,
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
532 'nlc': new_lineno_class
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
533 })
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
534
1789
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
535 _html.append('''%(link)s''' % {
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
536 'link': _link_to_if(True, change['new_lineno'],
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
537 '#%s' % anchor_new)
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
538 })
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
539 _html.append('''</td>\n''')
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
540 ###########################################################
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
541 # CODE
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
542 ###########################################################
1787
d4a7b6c82efe code garden for changeset ranges and comments
Marcin Kuzminski <marcin@python-works.com>
parents: 1781
diff changeset
543 comments = '' if enable_comments else 'no-comment'
1789
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
544 _html.append('''\t<td class="%(cc)s %(inc)s">''' % {
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
545 'cc': code_class,
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
546 'inc': comments
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
547 })
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
548 _html.append('''\n\t\t<pre>%(code)s</pre>\n''' % {
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
549 'code': change['line']
17caf4efe15c implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents: 1787
diff changeset
550 })
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
551 _html.append('''\t</td>''')
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
552 _html.append('''\n</tr>\n''')
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
553 _html.append('''</table>''')
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
554 if _html_empty:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
555 return None
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
556 return ''.join(_html)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
557
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
558 def stat(self):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
559 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
560 Returns tuple of added, and removed lines for this instance
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
561 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
562 return self.adds, self.removes
2337
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2233
diff changeset
563
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2233
diff changeset
564
2362
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2361
diff changeset
565 class InMemoryBundleRepo(bundlerepository):
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2361
diff changeset
566 def __init__(self, ui, path, bundlestream):
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2361
diff changeset
567 self._tempparent = None
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2361
diff changeset
568 localrepo.localrepository.__init__(self, ui, path)
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2361
diff changeset
569 self.ui.setconfig('phases', 'publish', False)
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2361
diff changeset
570
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2361
diff changeset
571 self.bundle = bundlestream
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2361
diff changeset
572
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2361
diff changeset
573 # dict with the mapping 'filename' -> position in the bundle
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2361
diff changeset
574 self.bundlefilespos = {}
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2361
diff changeset
575
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2361
diff changeset
576
2355
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
577 def differ(org_repo, org_ref, other_repo, other_ref, discovery_data=None):
2337
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2233
diff changeset
578 """
2478
8eab81115660 white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 2431
diff changeset
579 General differ between branches, bookmarks or separate but releated
2349
0edbffa9e2e2 fixed bug with inline changes highlighter.
Marcin Kuzminski <marcin@python-works.com>
parents: 2347
diff changeset
580 repositories
2337
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2233
diff changeset
581
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2233
diff changeset
582 :param org_repo:
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2233
diff changeset
583 :type org_repo:
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2233
diff changeset
584 :param org_ref:
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2233
diff changeset
585 :type org_ref:
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2233
diff changeset
586 :param other_repo:
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2233
diff changeset
587 :type other_repo:
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2233
diff changeset
588 :param other_ref:
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2233
diff changeset
589 :type other_ref:
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2233
diff changeset
590 """
2355
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
591
2364
9d61aad859bc code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2362
diff changeset
592 bundlerepo = None
9d61aad859bc code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2362
diff changeset
593 ignore_whitespace = False
2337
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2233
diff changeset
594 context = 3
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2233
diff changeset
595 org_repo = org_repo.scm_instance._repo
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2233
diff changeset
596 other_repo = other_repo.scm_instance._repo
2355
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
597 opts = diffopts(git=True, ignorews=ignore_whitespace, context=context)
2337
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2233
diff changeset
598 org_ref = org_ref[1]
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2233
diff changeset
599 other_ref = other_ref[1]
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2233
diff changeset
600
2355
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
601 if org_repo != other_repo:
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
602
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
603 common, incoming, rheads = discovery_data
2684
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2567
diff changeset
604 other_repo_peer = localrepo.locallegacypeer(other_repo.local())
2355
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
605 # create a bundle (uncompressed if other repo is not local)
2684
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2567
diff changeset
606 if other_repo_peer.capable('getbundle') and incoming:
2355
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
607 # disable repo hooks here since it's just bundle !
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
608 # patch and reset hooks section of UI config to not run any
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
609 # hooks on fetching archives with subrepos
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
610 for k, _ in other_repo.ui.configitems('hooks'):
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
611 other_repo.ui.setconfig('hooks', k, None)
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
612
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
613 unbundle = other_repo.getbundle('incoming', common=common,
2801
69420c48a0e6 fixes #550 mercurial repositories comparision failed when origin repo had
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
614 heads=None)
2355
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
615
2552
e8650fbc4d4e Moved BytesIO into compat because of py25 compatibility issue
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
616 buf = BytesIO()
2355
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
617 while True:
2364
9d61aad859bc code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2362
diff changeset
618 chunk = unbundle._stream.read(1024 * 4)
2355
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
619 if not chunk:
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
620 break
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
621 buf.write(chunk)
2337
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2233
diff changeset
622
2355
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
623 buf.seek(0)
2364
9d61aad859bc code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2362
diff changeset
624 # replace chunked _stream with data that can do tell() and seek()
2355
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
625 unbundle._stream = buf
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
626
2362
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2361
diff changeset
627 ui = make_ui('db')
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2361
diff changeset
628 bundlerepo = InMemoryBundleRepo(ui, path=org_repo.root,
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2361
diff changeset
629 bundlestream=unbundle)
2431
60dfc369df1d Improved cross-repo diff using bundlerepo
Marcin Kuzminski <marcin@python-works.com>
parents: 2391
diff changeset
630
60dfc369df1d Improved cross-repo diff using bundlerepo
Marcin Kuzminski <marcin@python-works.com>
parents: 2391
diff changeset
631 return ''.join(patch.diff(bundlerepo or org_repo,
60dfc369df1d Improved cross-repo diff using bundlerepo
Marcin Kuzminski <marcin@python-works.com>
parents: 2391
diff changeset
632 node1=org_repo[org_ref].node(),
60dfc369df1d Improved cross-repo diff using bundlerepo
Marcin Kuzminski <marcin@python-works.com>
parents: 2391
diff changeset
633 node2=other_repo[other_ref].node(),
2364
9d61aad859bc code garden
Marcin Kuzminski <marcin@python-works.com>
parents: 2362
diff changeset
634 opts=opts))
2355
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
635 else:
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
636 return ''.join(patch.diff(org_repo, node1=org_ref, node2=other_ref,
29a8096820dc added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents: 2349
diff changeset
637 opts=opts))