Mercurial > kallithea
annotate rhodecode/lib/diffs.py @ 2602:17083006a33d beta
Added cleanup repos script that allows to cleanup removed repos from rhodecode
older than given amount of time units.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 14 Jul 2012 18:53:39 +0200 |
parents | 5fe0f744bec0 |
children | 2b6939a77052 |
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 from mercurial import localrepo |
29a8096820dc
added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents:
2349
diff
changeset
|
38 |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
39 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
|
40 |
2552
e8650fbc4d4e
Moved BytesIO into compat because of py25 compatibility issue
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
41 from rhodecode.lib.compat import BytesIO |
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 |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2084
diff
changeset
|
44 from rhodecode.lib.helpers import escape |
2355
29a8096820dc
added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents:
2349
diff
changeset
|
45 from rhodecode.lib.utils import EmptyChangeset, make_ui |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
46 |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
47 |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
48 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
|
49 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
|
50 <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
|
51 <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
|
52 <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
|
53 </tr> |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
54 </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
|
55 |
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 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
|
58 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
|
59 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
|
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 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
|
62 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
|
63 """ |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
64 |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
65 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
|
66 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
|
67 |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
68 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
|
69 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
|
70 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
|
71 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
|
72 |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
73 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
|
74 (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
|
75 |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
76 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
|
77 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
|
78 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
|
79 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
|
80 |
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 = 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
|
82 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
|
83 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
|
84 else: |
2340
93243e162068
typo fix ref #461
Marcin Kuzminski <marcin@python-works.com>
parents:
2233
diff
changeset
|
85 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
|
86 '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
|
87 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
|
88 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
|
89 if not diff: |
2233
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2084
diff
changeset
|
90 submodules = filter(lambda o: isinstance(o, SubModuleNode), |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2084
diff
changeset
|
91 [filenode_new, filenode_old]) |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2084
diff
changeset
|
92 if submodules: |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2084
diff
changeset
|
93 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
|
94 else: |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2084
diff
changeset
|
95 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
|
96 |
2084
feb0fccdcf83
fixed vcs issue with last_changeset for filenodes
Marcin Kuzminski <marcin@python-works.com>
parents:
2007
diff
changeset
|
97 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
|
98 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
|
99 |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
100 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
|
101 |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
102 |
1768
5610fd9b6803
added line context control to diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
1753
diff
changeset
|
103 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
|
104 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
105 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
|
106 |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
107 :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
|
108 """ |
1894
0cbc3fb540b0
adapt codes to latest vcs
Marcin Kuzminski <marcin@python-works.com>
parents:
1883
diff
changeset
|
109 # make sure we pass in default context |
0cbc3fb540b0
adapt codes to latest vcs
Marcin Kuzminski <marcin@python-works.com>
parents:
1883
diff
changeset
|
110 context = context or 3 |
2233
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2084
diff
changeset
|
111 submodules = filter(lambda o: isinstance(o, SubModuleNode), |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2084
diff
changeset
|
112 [filenode_new, filenode_old]) |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2084
diff
changeset
|
113 if submodules: |
07fce1930417
fixed issues with gitsubmodule diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2084
diff
changeset
|
114 return '' |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
115 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
116 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
|
117 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
|
118 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
|
119 % filenode.__class__) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
120 |
1894
0cbc3fb540b0
adapt codes to latest vcs
Marcin Kuzminski <marcin@python-works.com>
parents:
1883
diff
changeset
|
121 repo = filenode_new.changeset.repository |
0cbc3fb540b0
adapt codes to latest vcs
Marcin Kuzminski <marcin@python-works.com>
parents:
1883
diff
changeset
|
122 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
|
123 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
|
124 |
1883
69d3c4450944
fix for latest vcs
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
125 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
|
126 ignore_whitespace, context) |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
127 return vcs_gitdiff |
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 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
130 class DiffProcessor(object): |
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 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
|
133 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
|
134 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
|
135 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
136 _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
|
137 _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
|
138 |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
139 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
|
140 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
141 :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
|
142 :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
|
143 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
144 if isinstance(diff, basestring): |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
145 diff = [diff] |
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 self.__udiff = diff |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
148 self.__format = format |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
149 self.adds = 0 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
150 self.removes = 0 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
151 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
152 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
|
153 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
|
154 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
155 elif self.__format == 'gitdiff': |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
156 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
|
157 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
|
158 else: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
159 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
|
160 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
|
161 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
162 # Select a differ. |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
163 if differ == 'difflib': |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
164 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
|
165 else: |
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_udiff |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
167 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
168 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
|
169 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
|
170 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
171 def copy_iterator(self): |
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 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
|
174 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
|
175 this instance of DiffProcessor |
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 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
|
178 return iterator_copy |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
179 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
180 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
|
181 """ |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
182 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
|
183 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
184 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
185 try: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
186 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
|
187 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
|
188 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
|
189 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
|
190 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
|
191 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
192 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
|
193 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
|
194 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
|
195 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
|
196 |
1787
d4a7b6c82efe
code garden for changeset ranges and comments
Marcin Kuzminski <marcin@python-works.com>
parents:
1781
diff
changeset
|
197 filename = (old_filename |
d4a7b6c82efe
code garden for changeset ranges and comments
Marcin Kuzminski <marcin@python-works.com>
parents:
1781
diff
changeset
|
198 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
|
199 |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
200 operation = 'D' if new_filename == '/dev/null' else None |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
201 if not operation: |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
202 operation = 'M' if old_filename != '/dev/null' else 'A' |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
203 |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
204 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
|
205 except (ValueError, IndexError): |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
206 pass |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
207 |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
208 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
|
209 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
210 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
|
211 def line_decoder(l): |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
212 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
|
213 self.adds += 1 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
214 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
|
215 self.removes += 1 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
216 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
|
217 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
218 output = list(diffiterator) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
219 size = len(output) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
220 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
221 if size == 2: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
222 l = [] |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
223 l.extend([output[0]]) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
224 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
|
225 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
|
226 elif size == 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, output[0].splitlines(1)) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
228 elif size == 0: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
229 return [] |
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 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
|
232 |
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
|
233 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
|
234 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
235 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
|
236 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
237 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
238 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
|
239 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
|
240 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
|
241 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
|
242 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
243 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
|
244 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
|
245 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
246 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
|
247 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
248 oldfragments, newfragments = [], [] |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
249 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
|
250 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
|
251 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
|
252 if tag != 'equal': |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
253 if oldfrag: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
254 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
|
255 if newfrag: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
256 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
|
257 oldfragments.append(oldfrag) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
258 newfragments.append(newfrag) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
259 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
260 old['line'] = "".join(oldfragments) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
261 new['line'] = "".join(newfragments) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
262 |
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
|
263 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
|
264 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
265 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
|
266 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
267 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
|
268 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
|
269 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
|
270 start += 1 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
271 end = -1 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
272 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
|
273 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
|
274 end -= 1 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
275 end += 1 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
276 if start or end: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
277 def do(l): |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
278 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
|
279 if l['action'] == 'add': |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
280 tag = 'ins' |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
281 else: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
282 tag = 'del' |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
283 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
|
284 l['line'][:start], |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
285 tag, |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
286 l['line'][start:last], |
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'][last:] |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
289 ) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
290 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
|
291 do(next_) |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
292 |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
293 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
|
294 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
295 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
|
296 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
297 lineiter = self.lines |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
298 files = [] |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
299 try: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
300 line = lineiter.next() |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
301 while 1: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
302 # 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
|
303 if not line.startswith('--- '): |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
304 line = lineiter.next() |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
305 continue |
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 chunks = [] |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
308 stats = [0, 0] |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
309 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
|
310 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
|
311 files.append({ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
312 'filename': filename, |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
313 'old_revision': old_rev, |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
314 'new_revision': new_rev, |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
315 'chunks': chunks, |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
316 'operation': operation, |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
317 'stats': stats, |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
318 }) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
319 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
320 line = lineiter.next() |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
321 while line: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
322 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
|
323 if not match: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
324 break |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
325 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
326 lines = [] |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
327 chunks.append(lines) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
328 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
329 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
|
330 [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
|
331 old_line -= 1 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
332 new_line -= 1 |
2359
a264d898ca08
Alwas show initial context on html diffs.
Marcin Kuzminski <marcin@python-works.com>
parents:
2340
diff
changeset
|
333 gr = match.groups() |
a264d898ca08
Alwas show initial context on html diffs.
Marcin Kuzminski <marcin@python-works.com>
parents:
2340
diff
changeset
|
334 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
|
335 old_end += old_line |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
336 new_end += new_line |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
337 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
338 if context: |
2359
a264d898ca08
Alwas show initial context on html diffs.
Marcin Kuzminski <marcin@python-works.com>
parents:
2340
diff
changeset
|
339 # 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
|
340 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
|
341 lines.append({ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
342 'old_lineno': '...', |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
343 '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
|
344 '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
|
345 'line': line, |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
346 }) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
347 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
348 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
|
349 |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
350 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
|
351 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
|
352 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
|
353 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
|
354 #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
|
355 # 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
|
356 line = line[1:] |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
357 else: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
358 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
|
359 |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
360 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
|
361 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
362 # 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
|
363 if command in '#@': |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
364 continue |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
365 elif command == '+': |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
366 affects_new = True |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
367 action = 'add' |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
368 stats[0] += 1 |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
369 elif command == '-': |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
370 affects_old = True |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
371 action = 'del' |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
372 stats[1] += 1 |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
373 else: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
374 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
|
375 action = 'unmod' |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
376 |
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
|
377 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
|
378 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
|
379 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
|
380 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
|
381 '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
|
382 '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
|
383 '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
|
384 '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
|
385 }) |
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 |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
387 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
|
388 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
|
389 # 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
|
390 # 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
|
391 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
|
392 '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
|
393 '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
|
394 '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
|
395 '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
|
396 }) |
2391 | 397 |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
398 except StopIteration: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
399 pass |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
400 |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
401 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
|
402 if inline_diff is False: |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
403 return sorted(files, key=sorter) |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
404 |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
405 # highlight inline changes |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
406 for diff_data in files: |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
407 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
|
408 lineiter = iter(chunk) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
409 try: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
410 while 1: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
411 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
|
412 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
|
413 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
|
414 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
|
415 nextline['action'] == line['action']: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
416 continue |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
417 self.differ(line, nextline) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
418 except StopIteration: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
419 pass |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
420 |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
421 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
|
422 |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
423 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
|
424 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
425 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
|
426 of dicts |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
427 """ |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
428 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
|
429 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
430 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
|
431 """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
|
432 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
433 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
|
434 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
|
435 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
|
436 ("_"), 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
|
437 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
|
438 and periods unnecessarily. |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
439 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
440 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
|
441 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
|
442 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
|
443 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
444 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
445 # 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
|
446 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
|
447 # 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
|
448 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
|
449 return idstring |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
450 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
451 def raw_diff(self): |
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 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
|
454 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
455 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
|
456 if self.__format == 'gitdiff': |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
457 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
|
458 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
|
459 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
460 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
|
461 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
|
462 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
|
463 """ |
2349
0edbffa9e2e2
fixed bug with inline changes highlighter.
Marcin Kuzminski <marcin@python-works.com>
parents:
2347
diff
changeset
|
464 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
|
465 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
466 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
|
467 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
468 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
|
469 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
470 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
471 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
|
472 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
|
473 '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
|
474 '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
|
475 } |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
476 else: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
477 return label |
2385
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
478 if diff_lines is None: |
a455b2c79c85
Improved RSS/ATOM feeds
Marcin Kuzminski <marcin@python-works.com>
parents:
2360
diff
changeset
|
479 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
|
480 _html_empty = True |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
481 _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
|
482 _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
|
483 '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
|
484 }) |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
485 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
|
486 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
|
487 _html_empty = False |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
488 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
|
489 _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
|
490 '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
|
491 '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
|
492 }) |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
493 anchor_old_id = '' |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
494 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
|
495 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
|
496 '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
|
497 '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
|
498 } |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
499 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
|
500 '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
|
501 '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
|
502 } |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
503 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
|
504 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
|
505 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
|
506 change['new_lineno']) |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
507 if cond_old: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
508 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
|
509 if cond_new: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
510 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
|
511 ########################################################### |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
512 # OLD LINE NUMBER |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
513 ########################################################### |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
514 _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
|
515 '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
|
516 '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
|
517 }) |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
518 |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
519 _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
|
520 '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
|
521 '#%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
|
522 }) |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
523 _html.append('''</td>\n''') |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
524 ########################################################### |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
525 # NEW LINE NUMBER |
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 |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
528 _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
|
529 '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
|
530 '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
|
531 }) |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
532 |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
533 _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
|
534 '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
|
535 '#%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
|
536 }) |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
537 _html.append('''</td>\n''') |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
538 ########################################################### |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
539 # CODE |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
540 ########################################################### |
1787
d4a7b6c82efe
code garden for changeset ranges and comments
Marcin Kuzminski <marcin@python-works.com>
parents:
1781
diff
changeset
|
541 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
|
542 _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
|
543 '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
|
544 '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
|
545 }) |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1787
diff
changeset
|
546 _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
|
547 '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
|
548 }) |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
549 _html.append('''\t</td>''') |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
550 _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
|
551 _html.append('''</table>''') |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
552 if _html_empty: |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
553 return None |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
554 return ''.join(_html) |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
555 |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
556 def stat(self): |
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 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
|
559 """ |
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
560 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
|
561 |
f8c953c6b040
Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
2233
diff
changeset
|
562 |
2362
3c4afb8894bd
Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2361
diff
changeset
|
563 class InMemoryBundleRepo(bundlerepository): |
3c4afb8894bd
Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2361
diff
changeset
|
564 def __init__(self, ui, path, bundlestream): |
3c4afb8894bd
Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2361
diff
changeset
|
565 self._tempparent = None |
3c4afb8894bd
Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2361
diff
changeset
|
566 localrepo.localrepository.__init__(self, ui, path) |
3c4afb8894bd
Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2361
diff
changeset
|
567 self.ui.setconfig('phases', 'publish', False) |
3c4afb8894bd
Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2361
diff
changeset
|
568 |
3c4afb8894bd
Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2361
diff
changeset
|
569 self.bundle = bundlestream |
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 # dict with the mapping 'filename' -> position in the bundle |
3c4afb8894bd
Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2361
diff
changeset
|
572 self.bundlefilespos = {} |
3c4afb8894bd
Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2361
diff
changeset
|
573 |
3c4afb8894bd
Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2361
diff
changeset
|
574 |
2355
29a8096820dc
added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents:
2349
diff
changeset
|
575 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
|
576 """ |
2478
8eab81115660
white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
2431
diff
changeset
|
577 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
|
578 repositories |
2337
f8c953c6b040
Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
2233
diff
changeset
|
579 |
f8c953c6b040
Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
2233
diff
changeset
|
580 :param org_repo: |
f8c953c6b040
Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
2233
diff
changeset
|
581 :type org_repo: |
f8c953c6b040
Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
2233
diff
changeset
|
582 :param org_ref: |
f8c953c6b040
Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
2233
diff
changeset
|
583 :type org_ref: |
f8c953c6b040
Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
2233
diff
changeset
|
584 :param other_repo: |
f8c953c6b040
Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
2233
diff
changeset
|
585 :type other_repo: |
f8c953c6b040
Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
2233
diff
changeset
|
586 :param other_ref: |
f8c953c6b040
Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
2233
diff
changeset
|
587 :type other_ref: |
f8c953c6b040
Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
2233
diff
changeset
|
588 """ |
2355
29a8096820dc
added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents:
2349
diff
changeset
|
589 |
2364 | 590 bundlerepo = None |
591 ignore_whitespace = False | |
2337
f8c953c6b040
Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
2233
diff
changeset
|
592 context = 3 |
f8c953c6b040
Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
2233
diff
changeset
|
593 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
|
594 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
|
595 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
|
596 org_ref = org_ref[1] |
f8c953c6b040
Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
2233
diff
changeset
|
597 other_ref = other_ref[1] |
f8c953c6b040
Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
2233
diff
changeset
|
598 |
2355
29a8096820dc
added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents:
2349
diff
changeset
|
599 if org_repo != other_repo: |
29a8096820dc
added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents:
2349
diff
changeset
|
600 |
29a8096820dc
added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents:
2349
diff
changeset
|
601 common, incoming, rheads = discovery_data |
2362
3c4afb8894bd
Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2361
diff
changeset
|
602 |
2355
29a8096820dc
added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents:
2349
diff
changeset
|
603 # create a bundle (uncompressed if other repo is not local) |
2362
3c4afb8894bd
Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2361
diff
changeset
|
604 if other_repo.capable('getbundle') and incoming: |
2355
29a8096820dc
added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents:
2349
diff
changeset
|
605 # 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
|
606 # 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
|
607 # 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
|
608 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
|
609 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
|
610 |
29a8096820dc
added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents:
2349
diff
changeset
|
611 unbundle = other_repo.getbundle('incoming', common=common, |
29a8096820dc
added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents:
2349
diff
changeset
|
612 heads=rheads) |
29a8096820dc
added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents:
2349
diff
changeset
|
613 |
2552
e8650fbc4d4e
Moved BytesIO into compat because of py25 compatibility issue
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
614 buf = BytesIO() |
2355
29a8096820dc
added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents:
2349
diff
changeset
|
615 while True: |
2364 | 616 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
|
617 if not chunk: |
29a8096820dc
added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents:
2349
diff
changeset
|
618 break |
29a8096820dc
added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents:
2349
diff
changeset
|
619 buf.write(chunk) |
2337
f8c953c6b040
Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
2233
diff
changeset
|
620 |
2355
29a8096820dc
added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents:
2349
diff
changeset
|
621 buf.seek(0) |
2364 | 622 # 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
|
623 unbundle._stream = buf |
29a8096820dc
added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents:
2349
diff
changeset
|
624 |
2362
3c4afb8894bd
Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2361
diff
changeset
|
625 ui = make_ui('db') |
3c4afb8894bd
Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2361
diff
changeset
|
626 bundlerepo = InMemoryBundleRepo(ui, path=org_repo.root, |
3c4afb8894bd
Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
2361
diff
changeset
|
627 bundlestream=unbundle) |
2431
60dfc369df1d
Improved cross-repo diff using bundlerepo
Marcin Kuzminski <marcin@python-works.com>
parents:
2391
diff
changeset
|
628 |
60dfc369df1d
Improved cross-repo diff using bundlerepo
Marcin Kuzminski <marcin@python-works.com>
parents:
2391
diff
changeset
|
629 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
|
630 node1=org_repo[org_ref].node(), |
60dfc369df1d
Improved cross-repo diff using bundlerepo
Marcin Kuzminski <marcin@python-works.com>
parents:
2391
diff
changeset
|
631 node2=other_repo[other_ref].node(), |
2364 | 632 opts=opts)) |
2355
29a8096820dc
added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents:
2349
diff
changeset
|
633 else: |
29a8096820dc
added basic comparision of two repositories using bundles
Marcin Kuzminski <marcin@python-works.com>
parents:
2349
diff
changeset
|
634 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
|
635 opts=opts)) |