Mercurial > kallithea
annotate rhodecode/lib/diffs.py @ 2300:edfff9f37916 rhodecode-0.0.1.3.6
merge with beta
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 17 May 2012 14:27:51 +0200 |
parents | 07fce1930417 |
children | f8c953c6b040 93243e162068 |
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 |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
31 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
|
32 |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
33 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
|
34 |
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
|
35 from rhodecode.lib.vcs.exceptions import VCSError |
2233
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2084
diff
changeset
|
36 from rhodecode.lib.vcs.nodes import FileNode, SubModuleNode |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2084
diff
changeset
|
37 from rhodecode.lib.helpers import escape |
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 rhodecode.lib.utils import EmptyChangeset |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
39 |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
40 |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
41 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
|
42 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
|
43 <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
|
44 <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
|
45 <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
|
46 </tr> |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
47 </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
|
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 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
|
51 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
|
52 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
|
53 """ |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
54 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
|
55 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
|
56 """ |
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 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
|
59 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
|
60 |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
61 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
|
62 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
|
63 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
|
64 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
|
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 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
|
67 (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
|
68 |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
69 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
|
70 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
|
71 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
|
72 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
|
73 |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
74 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
|
75 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
|
76 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
|
77 else: |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
78 diff = wrap_to_table(_('Changeset was to big and was cut off, use ' |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
79 '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
|
80 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
|
81 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
|
82 if not diff: |
2233
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2084
diff
changeset
|
83 submodules = filter(lambda o: isinstance(o, SubModuleNode), |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2084
diff
changeset
|
84 [filenode_new, filenode_old]) |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2084
diff
changeset
|
85 if submodules: |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2084
diff
changeset
|
86 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
|
87 else: |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2084
diff
changeset
|
88 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
|
89 |
2084
feb0fccdcf83
fixed vcs issue with last_changeset for filenodes
Marcin Kuzminski <marcin@python-works.com>
parents:
2007
diff
changeset
|
90 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
|
91 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
|
92 |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
93 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
|
94 |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
95 |
1768
5610fd9b6803
added line context control to diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
1753
diff
changeset
|
96 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
|
97 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
98 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
|
99 |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
100 :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
|
101 """ |
1894
0cbc3fb540b0
adapt codes to latest vcs
Marcin Kuzminski <marcin@python-works.com>
parents:
1883
diff
changeset
|
102 # make sure we pass in default context |
0cbc3fb540b0
adapt codes to latest vcs
Marcin Kuzminski <marcin@python-works.com>
parents:
1883
diff
changeset
|
103 context = context or 3 |
2233
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2084
diff
changeset
|
104 submodules = filter(lambda o: isinstance(o, SubModuleNode), |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2084
diff
changeset
|
105 [filenode_new, filenode_old]) |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2084
diff
changeset
|
106 if submodules: |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2084
diff
changeset
|
107 return '' |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
108 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
109 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
|
110 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
|
111 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
|
112 % filenode.__class__) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
113 |
1894
0cbc3fb540b0
adapt codes to latest vcs
Marcin Kuzminski <marcin@python-works.com>
parents:
1883
diff
changeset
|
114 repo = filenode_new.changeset.repository |
0cbc3fb540b0
adapt codes to latest vcs
Marcin Kuzminski <marcin@python-works.com>
parents:
1883
diff
changeset
|
115 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
|
116 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
|
117 |
1883
69d3c4450944
fix for latest vcs
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
118 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
|
119 ignore_whitespace, context) |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
120 return vcs_gitdiff |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
121 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
122 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
123 class DiffProcessor(object): |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
124 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
125 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
|
126 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
|
127 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
|
128 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
129 _chunk_re = re.compile(r'@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)') |
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 def __init__(self, diff, differ='diff', format='udiff'): |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
132 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
133 :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
|
134 :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
|
135 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
136 if isinstance(diff, basestring): |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
137 diff = [diff] |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
138 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
139 self.__udiff = diff |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
140 self.__format = format |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
141 self.adds = 0 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
142 self.removes = 0 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
143 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
144 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
|
145 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
|
146 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
147 elif self.__format == 'gitdiff': |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
148 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
|
149 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
|
150 else: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
151 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
|
152 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
|
153 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
154 # Select a differ. |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
155 if differ == 'difflib': |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
156 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
|
157 else: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
158 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
|
159 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
160 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
|
161 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
|
162 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
163 def copy_iterator(self): |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
164 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
165 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
|
166 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
|
167 this instance of DiffProcessor |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
168 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
169 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
|
170 return iterator_copy |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
171 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
172 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
|
173 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
174 Extract the filename and revision hint from a line. |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
175 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
176 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
177 try: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
178 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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
184 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
|
185 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
|
186 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
|
187 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
|
188 |
1787
d4a7b6c82efe
code garden for changeset ranges and comments
Marcin Kuzminski <marcin@python-works.com>
parents:
1781
diff
changeset
|
189 filename = (old_filename |
d4a7b6c82efe
code garden for changeset ranges and comments
Marcin Kuzminski <marcin@python-works.com>
parents:
1781
diff
changeset
|
190 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
|
191 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
192 return filename, new_rev, old_rev |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
193 except (ValueError, IndexError): |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
194 pass |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
195 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
196 return None, None, None |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
197 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
198 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
|
199 def line_decoder(l): |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
200 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
|
201 self.adds += 1 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
202 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
|
203 self.removes += 1 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
204 return l.decode('utf8', 'replace') |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
205 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
206 output = list(diffiterator) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
207 size = len(output) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
208 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
209 if size == 2: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
210 l = [] |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
211 l.extend([output[0]]) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
212 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
|
213 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
|
214 elif size == 1: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
215 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
|
216 elif size == 0: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
217 return [] |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
218 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
219 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
|
220 |
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
|
221 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
|
222 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
223 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
|
224 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
225 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
226 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
|
227 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
|
228 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
|
229 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
|
230 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
231 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
|
232 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
|
233 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
234 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
|
235 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
236 oldfragments, newfragments = [], [] |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
237 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
|
238 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
|
239 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
|
240 if tag != 'equal': |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
241 if oldfrag: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
242 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
|
243 if newfrag: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
244 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
|
245 oldfragments.append(oldfrag) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
246 newfragments.append(newfrag) |
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 old['line'] = "".join(oldfragments) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
249 new['line'] = "".join(newfragments) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
250 |
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
|
251 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
|
252 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
253 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
|
254 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
255 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
|
256 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
|
257 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
|
258 start += 1 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
259 end = -1 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
260 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
|
261 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
|
262 end -= 1 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
263 end += 1 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
264 if start or end: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
265 def do(l): |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
266 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
|
267 if l['action'] == 'add': |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
268 tag = 'ins' |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
269 else: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
270 tag = 'del' |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
271 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
|
272 l['line'][:start], |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
273 tag, |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
274 l['line'][start:last], |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
275 tag, |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
276 l['line'][last:] |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
277 ) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
278 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
|
279 do(next_) |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
280 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
281 def _parse_udiff(self): |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
282 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
283 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
|
284 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
285 lineiter = self.lines |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
286 files = [] |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
287 try: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
288 line = lineiter.next() |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
289 # skip first context |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
290 skipfirst = True |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
291 while 1: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
292 # 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
|
293 if not line.startswith('--- '): |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
294 line = lineiter.next() |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
295 continue |
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 chunks = [] |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
298 filename, old_rev, new_rev = \ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
299 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
|
300 files.append({ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
301 'filename': filename, |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
302 'old_revision': old_rev, |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
303 'new_revision': new_rev, |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
304 'chunks': chunks |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
305 }) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
306 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
307 line = lineiter.next() |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
308 while line: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
309 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
|
310 if not match: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
311 break |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
312 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
313 lines = [] |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
314 chunks.append(lines) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
315 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
316 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
|
317 [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
|
318 old_line -= 1 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
319 new_line -= 1 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
320 context = len(match.groups()) == 5 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
321 old_end += old_line |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
322 new_end += new_line |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
323 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
324 if context: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
325 if not skipfirst: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
326 lines.append({ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
327 'old_lineno': '...', |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
328 '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
|
329 '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
|
330 'line': line, |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
331 }) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
332 else: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
333 skipfirst = False |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
334 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
335 line = lineiter.next() |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
336 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
|
337 if line: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
338 command, line = line[0], line[1:] |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
339 else: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
340 command = ' ' |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
341 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
|
342 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
343 # 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
|
344 if command in '#@': |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
345 continue |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
346 elif command == '+': |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
347 affects_new = True |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
348 action = 'add' |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
349 elif command == '-': |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
350 affects_old = True |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
351 action = 'del' |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
352 else: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
353 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
|
354 action = 'unmod' |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
355 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
356 old_line += affects_old |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
357 new_line += affects_new |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
358 lines.append({ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
359 'old_lineno': affects_old and old_line or '', |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
360 'new_lineno': affects_new and new_line or '', |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
361 'action': action, |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
362 'line': line |
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 line = lineiter.next() |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
365 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
366 except StopIteration: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
367 pass |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
368 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
369 # highlight inline changes |
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
|
370 for _ in files: |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
371 for chunk in chunks: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
372 lineiter = iter(chunk) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
373 #first = True |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
374 try: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
375 while 1: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
376 line = lineiter.next() |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
377 if line['action'] != 'unmod': |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
378 nextline = lineiter.next() |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
379 if nextline['action'] == 'unmod' or \ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
380 nextline['action'] == line['action']: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
381 continue |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
382 self.differ(line, nextline) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
383 except StopIteration: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
384 pass |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
385 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
386 return files |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
387 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
388 def prepare(self): |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
389 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
390 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
|
391 of dicts |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
392 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
393 return self._parse_udiff() |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
394 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
395 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
|
396 """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
|
397 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
398 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
|
399 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
|
400 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
|
401 ("_"), 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
|
402 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
|
403 and periods unnecessarily. |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
404 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
405 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
|
406 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
|
407 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
|
408 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
409 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
410 # 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
|
411 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
|
412 # 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
|
413 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
|
414 return idstring |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
415 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
416 def raw_diff(self): |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
417 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
418 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
|
419 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
420 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
|
421 if self.__format == 'gitdiff': |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
422 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
|
423 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
|
424 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
425 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
|
426 new_lineno_class='lineno old', old_lineno_class='lineno new', |
1787
d4a7b6c82efe
code garden for changeset ranges and comments
Marcin Kuzminski <marcin@python-works.com>
parents:
1781
diff
changeset
|
427 code_class='code', enable_comments=False): |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
428 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
429 Return udiff as html table with customized css classes |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
430 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
431 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
|
432 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
433 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
|
434 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
435 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
436 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
|
437 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
|
438 '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
|
439 '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
|
440 } |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
441 else: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
442 return label |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
443 diff_lines = self.prepare() |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
444 _html_empty = True |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
445 _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
|
446 _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
|
447 '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
|
448 }) |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
449 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
|
450 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
|
451 _html_empty = False |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
452 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
|
453 _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
|
454 '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
|
455 '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
|
456 }) |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
457 anchor_old_id = '' |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
458 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
|
459 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
|
460 '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
|
461 '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
|
462 } |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
463 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
|
464 '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
|
465 '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
|
466 } |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
467 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
|
468 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
|
469 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
|
470 change['new_lineno']) |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
471 if cond_old: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
472 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
|
473 if cond_new: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
474 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
|
475 ########################################################### |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
476 # OLD LINE NUMBER |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
477 ########################################################### |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
478 _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
|
479 '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
|
480 '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
|
481 }) |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
482 |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
483 _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
|
484 '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
|
485 '#%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
|
486 }) |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
487 _html.append('''</td>\n''') |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
488 ########################################################### |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
489 # NEW LINE NUMBER |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
490 ########################################################### |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
491 |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
492 _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
|
493 '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
|
494 '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
|
495 }) |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
496 |
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 _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
|
498 '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
|
499 '#%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
|
500 }) |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
501 _html.append('''</td>\n''') |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
502 ########################################################### |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
503 # CODE |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
504 ########################################################### |
1787
d4a7b6c82efe
code garden for changeset ranges and comments
Marcin Kuzminski <marcin@python-works.com>
parents:
1781
diff
changeset
|
505 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
|
506 _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
|
507 '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
|
508 '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
|
509 }) |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
510 _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
|
511 '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
|
512 }) |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
513 _html.append('''\t</td>''') |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
514 _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
|
515 _html.append('''</table>''') |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
516 if _html_empty: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
517 return None |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
518 return ''.join(_html) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
519 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
520 def stat(self): |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
521 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
522 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
|
523 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
524 return self.adds, self.removes |