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