comparison pylons_app/controllers/changeset.py @ 509:183cee110578

first implementation of #34 changeset raw diff based on udiff from python
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 11 Sep 2010 01:52:16 +0200
parents fdf9f6ee5217
children 9dd372c7166c
comparison
equal deleted inserted replaced
508:e01a85f9fc90 509:183cee110578
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
6 # This program is free software; you can redistribute it and/or 5 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License 6 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; version 2 7 # as published by the Free Software Foundation; version 2
9 # of the License or (at your opinion) any later version of the license. 8 # of the License or (at your opinion) any later version of the license.
10 # 9 #
20 """ 19 """
21 Created on April 25, 2010 20 Created on April 25, 2010
22 changeset controller for pylons 21 changeset controller for pylons
23 @author: marcink 22 @author: marcink
24 """ 23 """
25 from pylons import tmpl_context as c, url, request 24 from pylons import tmpl_context as c, url, request, response
26 from pylons.controllers.util import redirect 25 from pylons.controllers.util import redirect
27 from pylons_app.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator 26 from pylons_app.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
28 from pylons_app.lib.base import BaseController, render 27 from pylons_app.lib.base import BaseController, render
29 from pylons_app.model.hg_model import HgModel 28 from pylons_app.model.hg_model import HgModel
30 from vcs.exceptions import RepositoryError 29 from vcs.exceptions import RepositoryError
62 if filenode_old.is_binary or node.is_binary: 61 if filenode_old.is_binary or node.is_binary:
63 diff = 'binary file' 62 diff = 'binary file'
64 else: 63 else:
65 f_udiff = differ.get_udiff(filenode_old, node) 64 f_udiff = differ.get_udiff(filenode_old, node)
66 diff = differ.DiffProcessor(f_udiff).as_html() 65 diff = differ.DiffProcessor(f_udiff).as_html()
67 try: 66
68 diff = unicode(diff)
69 except:
70 log.warning('Decoding failed of %s', filenode_old)
71 log.warning('Decoding failed of %s', node)
72 diff = 'unsupported type'
73 cs1 = None 67 cs1 = None
74 cs2 = node.last_changeset.raw_id 68 cs2 = node.last_changeset.raw_id
75 c.changes.append(('added', node, diff, cs1, cs2)) 69 c.changes.append(('added', node, diff, cs1, cs2))
76 70
77 for node in c.changeset.changed: 71 for node in c.changeset.changed:
79 if filenode_old.is_binary or node.is_binary: 73 if filenode_old.is_binary or node.is_binary:
80 diff = 'binary file' 74 diff = 'binary file'
81 else: 75 else:
82 f_udiff = differ.get_udiff(filenode_old, node) 76 f_udiff = differ.get_udiff(filenode_old, node)
83 diff = differ.DiffProcessor(f_udiff).as_html() 77 diff = differ.DiffProcessor(f_udiff).as_html()
84 try: 78
85 diff = unicode(diff)
86 except:
87 log.warning('Decoding failed of %s', filenode_old)
88 log.warning('Decoding failed of %s', node)
89 diff = 'unsupported type'
90 cs1 = filenode_old.last_changeset.raw_id 79 cs1 = filenode_old.last_changeset.raw_id
91 cs2 = node.last_changeset.raw_id 80 cs2 = node.last_changeset.raw_id
92 c.changes.append(('changed', node, diff, cs1, cs2)) 81 c.changes.append(('changed', node, diff, cs1, cs2))
93 82
94 for node in c.changeset.removed: 83 for node in c.changeset.removed:
95 c.changes.append(('removed', node, None, None, None)) 84 c.changes.append(('removed', node, None, None, None))
96 85
97 return render('changeset/changeset.html') 86 return render('changeset/changeset.html')
87
88 def raw_changeset(self,revision):
89
90 hg_model = HgModel()
91 try:
92 c.changeset = hg_model.get_repo(c.repo_name).get_changeset(revision)
93 except RepositoryError:
94 log.error(traceback.format_exc())
95 return redirect(url('hg_home'))
96 else:
97 try:
98 c.changeset_old = c.changeset.parents[0]
99 except IndexError:
100 c.changeset_old = None
101 c.changes = []
102
103 for node in c.changeset.added:
104 filenode_old = FileNode(node.path, '')
105 if filenode_old.is_binary or node.is_binary:
106 diff = 'binary file'
107 else:
108 f_udiff = differ.get_udiff(filenode_old, node)
109 diff = differ.DiffProcessor(f_udiff).raw_diff()
110
111 cs1 = None
112 cs2 = node.last_changeset.raw_id
113 c.changes.append(('added', node, diff, cs1, cs2))
114
115 for node in c.changeset.changed:
116 filenode_old = c.changeset_old.get_node(node.path)
117 if filenode_old.is_binary or node.is_binary:
118 diff = 'binary file'
119 else:
120 f_udiff = differ.get_udiff(filenode_old, node)
121 diff = differ.DiffProcessor(f_udiff).raw_diff()
122
123 cs1 = filenode_old.last_changeset.raw_id
124 cs2 = node.last_changeset.raw_id
125 c.changes.append(('changed', node, diff, cs1, cs2))
126
127 response.content_type = 'text/plain'
128
129 parent = True if len(c.changeset.parents) > 0 else False
130 c.parent_tmpl = 'Parent %s' % c.changeset.parents[0]._hex if parent else ''
131
132 c.diffs = ''
133 for x in c.changes:
134 c.diffs += x[2]
135
136 return render('changeset/raw_changeset.html')