Show More
@@ -1,64 +1,86 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | # encoding: utf-8 |
|
2 | # encoding: utf-8 | |
3 | # changeset controller for pylons |
|
3 | # changeset controller for pylons | |
4 | # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
|
4 | # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> | |
5 |
|
5 | |||
6 | # This program is free software; you can redistribute it and/or |
|
6 | # This program is free software; you can redistribute it and/or | |
7 | # modify it under the terms of the GNU General Public License |
|
7 | # modify it under the terms of the GNU General Public License | |
8 | # as published by the Free Software Foundation; version 2 |
|
8 | # as published by the Free Software Foundation; version 2 | |
9 | # of the License or (at your opinion) any later version of the license. |
|
9 | # of the License or (at your opinion) any later version of the license. | |
10 | # |
|
10 | # | |
11 | # This program is distributed in the hope that it will be useful, |
|
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. |
|
14 | # GNU General Public License for more details. | |
15 | # |
|
15 | # | |
16 | # You should have received a copy of the GNU General Public License |
|
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software |
|
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
19 | # MA 02110-1301, USA. |
|
19 | # MA 02110-1301, USA. | |
20 | """ |
|
20 | """ | |
21 | Created on April 25, 2010 |
|
21 | Created on April 25, 2010 | |
22 | changeset controller for pylons |
|
22 | changeset controller for pylons | |
23 | @author: marcink |
|
23 | @author: marcink | |
24 | """ |
|
24 | """ | |
25 | from pylons import tmpl_context as c |
|
25 | from pylons import tmpl_context as c | |
26 | from pylons_app.lib.auth import LoginRequired |
|
26 | from pylons_app.lib.auth import LoginRequired | |
27 | from pylons_app.lib.base import BaseController, render |
|
27 | from pylons_app.lib.base import BaseController, render | |
28 | from pylons_app.model.hg_model import HgModel |
|
28 | from pylons_app.model.hg_model import HgModel | |
29 | from vcs.utils import diffs as differ |
|
29 | from vcs.utils import diffs as differ | |
30 | import logging |
|
30 | import logging | |
31 | from vcs.nodes import FileNode |
|
31 | from vcs.nodes import FileNode | |
32 |
|
32 | |||
33 |
|
33 | |||
34 | log = logging.getLogger(__name__) |
|
34 | log = logging.getLogger(__name__) | |
35 |
|
35 | |||
36 | class ChangesetController(BaseController): |
|
36 | class ChangesetController(BaseController): | |
37 |
|
37 | |||
38 | @LoginRequired() |
|
38 | @LoginRequired() | |
39 | def __before__(self): |
|
39 | def __before__(self): | |
40 | super(ChangesetController, self).__before__() |
|
40 | super(ChangesetController, self).__before__() | |
41 |
|
41 | |||
42 | def index(self, revision): |
|
42 | def index(self, revision): | |
43 | hg_model = HgModel() |
|
43 | hg_model = HgModel() | |
44 | c.changeset = hg_model.get_repo(c.repo_name).get_changeset(revision) |
|
44 | c.changeset = hg_model.get_repo(c.repo_name).get_changeset(revision) | |
45 | c.changeset_old = c.changeset.parents[0] |
|
45 | c.changeset_old = c.changeset.parents[0] | |
46 | c.changes = [] |
|
46 | c.changes = [] | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | for node in c.changeset.added: |
|
49 | for node in c.changeset.added: | |
50 | filenode_old = FileNode(node.path, '') |
|
50 | filenode_old = FileNode(node.path, '') | |
51 | f_udiff = differ.get_udiff(filenode_old, node) |
|
51 | if filenode_old.is_binary or node.is_binary: | |
52 | diff = differ.DiffProcessor(f_udiff).as_html() |
|
52 | diff = 'binary file' | |
53 | c.changes.append(('added', node, diff)) |
|
53 | else: | |
|
54 | f_udiff = differ.get_udiff(filenode_old, node) | |||
|
55 | diff = differ.DiffProcessor(f_udiff).as_html() | |||
|
56 | try: | |||
|
57 | diff = unicode(diff) | |||
|
58 | except: | |||
|
59 | log.warning('Decoding failed of %s', filenode_old) | |||
|
60 | log.warning('Decoding failed of %s', node) | |||
|
61 | diff = 'unsupported type' | |||
|
62 | cs1 = None | |||
|
63 | cs2 = node.last_changeset.raw_id | |||
|
64 | c.changes.append(('added', node, diff, cs1, cs2)) | |||
54 |
|
65 | |||
55 | for node in c.changeset.changed: |
|
66 | for node in c.changeset.changed: | |
56 | filenode_old = c.changeset_old.get_node(node.path) |
|
67 | filenode_old = c.changeset_old.get_node(node.path) | |
57 | f_udiff = differ.get_udiff(filenode_old, node) |
|
68 | if filenode_old.is_binary or node.is_binary: | |
58 | diff = differ.DiffProcessor(f_udiff).as_html() |
|
69 | diff = 'binary file' | |
59 | c.changes.append(('changed', node, diff)) |
|
70 | else: | |
|
71 | f_udiff = differ.get_udiff(filenode_old, node) | |||
|
72 | diff = differ.DiffProcessor(f_udiff).as_html() | |||
|
73 | try: | |||
|
74 | diff = unicode(diff) | |||
|
75 | except: | |||
|
76 | log.warning('Decoding failed of %s', filenode_old) | |||
|
77 | log.warning('Decoding failed of %s', node) | |||
|
78 | diff = 'unsupported type' | |||
|
79 | cs1 = filenode_old.last_changeset.raw_id | |||
|
80 | cs2 = node.last_changeset.raw_id | |||
|
81 | c.changes.append(('changed', node, diff, cs1, cs2)) | |||
60 |
|
82 | |||
61 | for node in c.changeset.removed: |
|
83 | for node in c.changeset.removed: | |
62 | c.changes.append(('removed', node, None)) |
|
84 | c.changes.append(('removed', node, None, None, None)) | |
63 |
|
85 | |||
64 | return render('changeset/changeset.html') |
|
86 | return render('changeset/changeset.html') |
General Comments 0
You need to be logged in to leave comments.
Login now