Mercurial > public > src > rhodecode
annotate pylons_app/controllers/files.py @ 145:3f01d02c2cc6
fixed error when browsing revisions on path that doesn't exist. Fixed files browsing. Fixed templates in branches and tags
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 10 May 2010 23:12:45 +0200 |
parents | f7218849798a |
children | 873fd2dc62c2 |
rev | line source |
---|---|
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 import logging |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 |
99
5b57295601b6
Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
3 from pylons import request, response, session, tmpl_context as c, url, config, app_globals as g |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 from pylons.controllers.util import abort, redirect |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 from pylons_app.lib.base import BaseController, render |
99
5b57295601b6
Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
7 from pylons_app.lib.utils import get_repo_slug |
5b57295601b6
Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
8 from pylons_app.model.hg_model import HgModel |
131
49c7e191c2cd
Implemented mercurial style diff-lib
Marcin Kuzminski <marcin@python-works.com>
parents:
130
diff
changeset
|
9 from difflib import unified_diff |
49c7e191c2cd
Implemented mercurial style diff-lib
Marcin Kuzminski <marcin@python-works.com>
parents:
130
diff
changeset
|
10 from pylons_app.lib.differ import render_udiff |
145
3f01d02c2cc6
fixed error when browsing revisions on path that doesn't exist. Fixed files browsing. Fixed templates in branches and tags
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
11 from vcs.exceptions import RepositoryError, ChangesetError |
131
49c7e191c2cd
Implemented mercurial style diff-lib
Marcin Kuzminski <marcin@python-works.com>
parents:
130
diff
changeset
|
12 |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 log = logging.getLogger(__name__) |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 class FilesController(BaseController): |
99
5b57295601b6
Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
16 def __before__(self): |
5b57295601b6
Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
17 c.repos_prefix = config['repos_name'] |
5b57295601b6
Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
18 c.repo_name = get_repo_slug(request) |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 |
99
5b57295601b6
Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
20 def index(self, repo_name, revision, f_path): |
5b57295601b6
Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
21 hg_model = HgModel() |
5b57295601b6
Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
22 c.repo = repo = hg_model.get_repo(c.repo_name) |
145
3f01d02c2cc6
fixed error when browsing revisions on path that doesn't exist. Fixed files browsing. Fixed templates in branches and tags
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
23 |
3f01d02c2cc6
fixed error when browsing revisions on path that doesn't exist. Fixed files browsing. Fixed templates in branches and tags
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
24 revision = request.POST.get('at_rev', None) or revision |
3f01d02c2cc6
fixed error when browsing revisions on path that doesn't exist. Fixed files browsing. Fixed templates in branches and tags
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
25 if request.POST.get('view_low'): |
3f01d02c2cc6
fixed error when browsing revisions on path that doesn't exist. Fixed files browsing. Fixed templates in branches and tags
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
26 revision = int(revision) - 1 |
3f01d02c2cc6
fixed error when browsing revisions on path that doesn't exist. Fixed files browsing. Fixed templates in branches and tags
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
27 if request.POST.get('view_high'): |
3f01d02c2cc6
fixed error when browsing revisions on path that doesn't exist. Fixed files browsing. Fixed templates in branches and tags
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
28 revision = int(revision) + 1 |
3f01d02c2cc6
fixed error when browsing revisions on path that doesn't exist. Fixed files browsing. Fixed templates in branches and tags
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
29 max_rev = len(c.repo.revisions) - 1 |
3f01d02c2cc6
fixed error when browsing revisions on path that doesn't exist. Fixed files browsing. Fixed templates in branches and tags
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
30 if revision > max_rev: |
3f01d02c2cc6
fixed error when browsing revisions on path that doesn't exist. Fixed files browsing. Fixed templates in branches and tags
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
31 revision = max_rev |
3f01d02c2cc6
fixed error when browsing revisions on path that doesn't exist. Fixed files browsing. Fixed templates in branches and tags
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
32 |
99
5b57295601b6
Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
33 c.f_path = f_path |
138
5f42d751c719
fixed files when repository is empty
Marcin Kuzminski <marcin@python-works.com>
parents:
131
diff
changeset
|
34 try: |
5f42d751c719
fixed files when repository is empty
Marcin Kuzminski <marcin@python-works.com>
parents:
131
diff
changeset
|
35 c.changeset = repo.get_changeset(repo._get_revision(revision)) |
142
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
138
diff
changeset
|
36 c.cur_rev = c.changeset.raw_id |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
138
diff
changeset
|
37 c.rev_nr = c.changeset.revision |
138
5f42d751c719
fixed files when repository is empty
Marcin Kuzminski <marcin@python-works.com>
parents:
131
diff
changeset
|
38 c.files_list = c.changeset.get_node(f_path) |
5f42d751c719
fixed files when repository is empty
Marcin Kuzminski <marcin@python-works.com>
parents:
131
diff
changeset
|
39 c.file_history = self._get_history(repo, c.files_list, f_path) |
145
3f01d02c2cc6
fixed error when browsing revisions on path that doesn't exist. Fixed files browsing. Fixed templates in branches and tags
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
40 except (RepositoryError, ChangesetError): |
138
5f42d751c719
fixed files when repository is empty
Marcin Kuzminski <marcin@python-works.com>
parents:
131
diff
changeset
|
41 c.files_list = None |
99
5b57295601b6
Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
42 |
128
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
43 return render('files/files.html') |
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
44 |
129
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
45 def diff(self, repo_name, f_path): |
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
46 hg_model = HgModel() |
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
47 diff1 = request.GET.get('diff1') |
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
48 diff2 = request.GET.get('diff2') |
131
49c7e191c2cd
Implemented mercurial style diff-lib
Marcin Kuzminski <marcin@python-works.com>
parents:
130
diff
changeset
|
49 c.no_changes = diff1 == diff2 |
129
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
50 c.f_path = f_path |
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
51 c.repo = hg_model.get_repo(c.repo_name) |
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
52 c.changeset_1 = c.repo.get_changeset(diff1) |
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
53 c.changeset_2 = c.repo.get_changeset(diff2) |
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
54 |
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
55 c.file_1 = c.changeset_1.get_node(f_path).content |
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
56 c.file_2 = c.changeset_2.get_node(f_path).content |
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
57 c.diff1 = 'r%s:%s' % (c.changeset_1.revision, c.changeset_1._short) |
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
58 c.diff2 = 'r%s:%s' % (c.changeset_2.revision, c.changeset_2._short) |
131
49c7e191c2cd
Implemented mercurial style diff-lib
Marcin Kuzminski <marcin@python-works.com>
parents:
130
diff
changeset
|
59 |
49c7e191c2cd
Implemented mercurial style diff-lib
Marcin Kuzminski <marcin@python-works.com>
parents:
130
diff
changeset
|
60 d2 = unified_diff(c.file_1.splitlines(1), c.file_2.splitlines(1)) |
49c7e191c2cd
Implemented mercurial style diff-lib
Marcin Kuzminski <marcin@python-works.com>
parents:
130
diff
changeset
|
61 c.diff_files = render_udiff(udiff=d2) |
130
ffddbd80649e
Added differ lib from mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
129
diff
changeset
|
62 |
131
49c7e191c2cd
Implemented mercurial style diff-lib
Marcin Kuzminski <marcin@python-works.com>
parents:
130
diff
changeset
|
63 if len(c.diff_files) < 1: |
49c7e191c2cd
Implemented mercurial style diff-lib
Marcin Kuzminski <marcin@python-works.com>
parents:
130
diff
changeset
|
64 c.no_changes = True |
129
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
65 return render('files/file_diff.html') |
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
66 |
128
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
67 def _get_history(self, repo, node, f_path): |
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
68 from vcs.nodes import NodeKind |
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
69 if not node.kind is NodeKind.FILE: |
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
70 return [] |
129
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
71 changesets = node.history |
128
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
72 hist_l = [] |
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
73 for chs in changesets: |
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
74 n_desc = 'r%s:%s' % (chs.revision, chs._short) |
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
75 hist_l.append((chs._short, n_desc,)) |
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
76 return hist_l |