Show More
@@ -1,62 +1,65 b'' | |||
|
1 | 1 | import logging |
|
2 | 2 | |
|
3 | 3 | from pylons import request, response, session, tmpl_context as c, url, config, app_globals as g |
|
4 | 4 | from pylons.controllers.util import abort, redirect |
|
5 | 5 | |
|
6 | 6 | from pylons_app.lib.base import BaseController, render |
|
7 | 7 | from pylons_app.lib.utils import get_repo_slug |
|
8 | 8 | from pylons_app.model.hg_model import HgModel |
|
9 | 9 | from difflib import unified_diff |
|
10 | 10 | from pylons_app.lib.differ import render_udiff |
|
11 | from vcs.exceptions import RepositoryError | |
|
11 | 12 | |
|
12 | 13 | log = logging.getLogger(__name__) |
|
13 | 14 | |
|
14 | 15 | class FilesController(BaseController): |
|
15 | 16 | def __before__(self): |
|
16 | 17 | c.repos_prefix = config['repos_name'] |
|
17 | 18 | c.repo_name = get_repo_slug(request) |
|
18 | 19 | |
|
19 | 20 | def index(self, repo_name, revision, f_path): |
|
20 | 21 | hg_model = HgModel() |
|
21 | 22 | c.repo = repo = hg_model.get_repo(c.repo_name) |
|
22 | 23 | c.cur_rev = revision |
|
23 | 24 | c.f_path = f_path |
|
25 | try: | |
|
24 | 26 | c.changeset = repo.get_changeset(repo._get_revision(revision)) |
|
25 | ||
|
26 | 27 | c.files_list = c.changeset.get_node(f_path) |
|
28 | c.file_history = self._get_history(repo, c.files_list, f_path) | |
|
29 | except RepositoryError: | |
|
30 | c.files_list = None | |
|
27 | 31 | |
|
28 | c.file_history = self._get_history(repo, c.files_list, f_path) | |
|
29 | 32 | return render('files/files.html') |
|
30 | 33 | |
|
31 | 34 | def diff(self, repo_name, f_path): |
|
32 | 35 | hg_model = HgModel() |
|
33 | 36 | diff1 = request.GET.get('diff1') |
|
34 | 37 | diff2 = request.GET.get('diff2') |
|
35 | 38 | c.no_changes = diff1 == diff2 |
|
36 | 39 | c.f_path = f_path |
|
37 | 40 | c.repo = hg_model.get_repo(c.repo_name) |
|
38 | 41 | c.changeset_1 = c.repo.get_changeset(diff1) |
|
39 | 42 | c.changeset_2 = c.repo.get_changeset(diff2) |
|
40 | 43 | |
|
41 | 44 | c.file_1 = c.changeset_1.get_node(f_path).content |
|
42 | 45 | c.file_2 = c.changeset_2.get_node(f_path).content |
|
43 | 46 | c.diff1 = 'r%s:%s' % (c.changeset_1.revision, c.changeset_1._short) |
|
44 | 47 | c.diff2 = 'r%s:%s' % (c.changeset_2.revision, c.changeset_2._short) |
|
45 | 48 | |
|
46 | 49 | d2 = unified_diff(c.file_1.splitlines(1), c.file_2.splitlines(1)) |
|
47 | 50 | c.diff_files = render_udiff(udiff=d2) |
|
48 | 51 | |
|
49 | 52 | if len(c.diff_files) < 1: |
|
50 | 53 | c.no_changes = True |
|
51 | 54 | return render('files/file_diff.html') |
|
52 | 55 | |
|
53 | 56 | def _get_history(self, repo, node, f_path): |
|
54 | 57 | from vcs.nodes import NodeKind |
|
55 | 58 | if not node.kind is NodeKind.FILE: |
|
56 | 59 | return [] |
|
57 | 60 | changesets = node.history |
|
58 | 61 | hist_l = [] |
|
59 | 62 | for chs in changesets: |
|
60 | 63 | n_desc = 'r%s:%s' % (chs.revision, chs._short) |
|
61 | 64 | hist_l.append((chs._short, n_desc,)) |
|
62 | 65 | return hist_l |
General Comments 0
You need to be logged in to leave comments.
Login now