comparison pylons_app/controllers/files.py @ 275:2d61aa00e855

fixed bugs when putting empty or unknown changesets into diff
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 09 Jun 2010 08:07:05 +0200
parents a83e86e3f580
children fdf9f6ee5217
comparison
equal deleted inserted replaced
274:5db466f19b8d 275:2d61aa00e855
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # encoding: utf-8 2 # encoding: utf-8
3 # files controller for pylons 3 # files 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 from mercurial import archival
6 from pylons import request, response, session, tmpl_context as c, url
7 from pylons.controllers.util import redirect
8 from pylons_app.lib.auth import LoginRequired
9 from pylons_app.lib.base import BaseController, render
10 from pylons_app.lib.utils import EmptyChangeset
11 from pylons_app.model.hg_model import HgModel
12 from vcs.exceptions import RepositoryError, ChangesetError
13 from vcs.nodes import FileNode
14 from vcs.utils import diffs as differ
15 import logging
16 import pylons_app.lib.helpers as h
17 import tempfile
5 18
6 # This program is free software; you can redistribute it and/or 19 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License 20 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; version 2 21 # as published by the Free Software Foundation; version 2
9 # of the License or (at your opinion) any later version of the license. 22 # of the License or (at your opinion) any later version of the license.
20 """ 33 """
21 Created on April 21, 2010 34 Created on April 21, 2010
22 files controller for pylons 35 files controller for pylons
23 @author: marcink 36 @author: marcink
24 """ 37 """
25 from mercurial import archival
26 from pylons import request, response, session, tmpl_context as c, url
27 from pylons_app.lib.auth import LoginRequired
28 from pylons_app.lib.base import BaseController, render
29 import pylons_app.lib.helpers as h
30 from pylons_app.model.hg_model import HgModel
31 from vcs.exceptions import RepositoryError, ChangesetError
32 from vcs.utils import diffs as differ
33 import logging
34 import tempfile
35 38
36 39
37 log = logging.getLogger(__name__) 40 log = logging.getLogger(__name__)
38 41
39 class FilesController(BaseController): 42 class FilesController(BaseController):
138 diff2 = request.GET.get('diff2') 141 diff2 = request.GET.get('diff2')
139 c.action = action = request.GET.get('diff') 142 c.action = action = request.GET.get('diff')
140 c.no_changes = diff1 == diff2 143 c.no_changes = diff1 == diff2
141 c.f_path = f_path 144 c.f_path = f_path
142 c.repo = hg_model.get_repo(c.repo_name) 145 c.repo = hg_model.get_repo(c.repo_name)
143 c.changeset_1 = c.repo.get_changeset(diff1)
144 c.changeset_2 = c.repo.get_changeset(diff2)
145 146
146 c.diff1 = 'r%s:%s' % (c.changeset_1.revision, c.changeset_1._short) 147 try:
147 c.diff2 = 'r%s:%s' % (c.changeset_2.revision, c.changeset_2._short) 148 if diff1 not in ['', None, 'None', '0' * 12]:
148 f_udiff = differ.get_udiff(c.changeset_1.get_node(f_path), 149 c.changeset_1 = c.repo.get_changeset(diff1)
149 c.changeset_2.get_node(f_path)) 150 node1 = c.changeset_1.get_node(f_path)
151 else:
152 c.changeset_1 = EmptyChangeset()
153 node1 = FileNode('.', '')
154 if diff2 not in ['', None, 'None', '0' * 12]:
155 c.changeset_2 = c.repo.get_changeset(diff2)
156 node2 = c.changeset_2.get_node(f_path)
157 else:
158 c.changeset_2 = EmptyChangeset()
159 node2 = FileNode('.', '')
160 except RepositoryError:
161 return redirect(url('files_home',
162 repo_name=c.repo_name, f_path=f_path))
163
164 c.diff1 = 'r%s:%s' % (c.changeset_1.revision, c.changeset_1.raw_id)
165 c.diff2 = 'r%s:%s' % (c.changeset_2.revision, c.changeset_2.raw_id)
166 f_udiff = differ.get_udiff(node1, node2)
150 167
151 diff = differ.DiffProcessor(f_udiff) 168 diff = differ.DiffProcessor(f_udiff)
152 169
153 if action == 'download': 170 if action == 'download':
154 diff_name = '%s_vs_%s.diff' % (diff1, diff2) 171 diff_name = '%s_vs_%s.diff' % (diff1, diff2)