Show More
@@ -0,0 +1,98 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
2 | """ | |
|
3 | rhodecode.controllers.compare | |
|
4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
|
5 | ||
|
6 | compare controller for pylons showoing differences between two | |
|
7 | repos, branches, bookmarks or tips | |
|
8 | ||
|
9 | :created_on: May 6, 2012 | |
|
10 | :author: marcink | |
|
11 | :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com> | |
|
12 | :license: GPLv3, see COPYING for more details. | |
|
13 | """ | |
|
14 | # This program is free software: you can redistribute it and/or modify | |
|
15 | # it under the terms of the GNU General Public License as published by | |
|
16 | # the Free Software Foundation, either version 3 of the License, or | |
|
17 | # (at your option) any later version. | |
|
18 | # | |
|
19 | # This program is distributed in the hope that it will be useful, | |
|
20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
22 | # GNU General Public License for more details. | |
|
23 | # | |
|
24 | # You should have received a copy of the GNU General Public License | |
|
25 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
|
26 | import logging | |
|
27 | import traceback | |
|
28 | ||
|
29 | from pylons import request, response, session, tmpl_context as c, url | |
|
30 | from pylons.controllers.util import abort, redirect | |
|
31 | ||
|
32 | from rhodecode.lib.base import BaseRepoController, render | |
|
33 | from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator | |
|
34 | from webob.exc import HTTPNotFound | |
|
35 | ||
|
36 | log = logging.getLogger(__name__) | |
|
37 | ||
|
38 | ||
|
39 | class CompareController(BaseRepoController): | |
|
40 | ||
|
41 | @LoginRequired() | |
|
42 | @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', | |
|
43 | 'repository.admin') | |
|
44 | def __before__(self): | |
|
45 | super(CompareController, self).__before__() | |
|
46 | ||
|
47 | def _handle_ref(self, ref): | |
|
48 | """ | |
|
49 | Parse the org...other string | |
|
50 | Possible formats are `(branch|book|tag):<name>...(branch|book|tag):<othername>` | |
|
51 | or using a repo <empty>...(repo:</rhodecode/path/to/other) | |
|
52 | ||
|
53 | ||
|
54 | :param ref: | |
|
55 | :type ref: | |
|
56 | """ | |
|
57 | org_repo = c.rhodecode_repo.name | |
|
58 | ||
|
59 | def org_parser(org): | |
|
60 | _repo = org_repo | |
|
61 | name, val = org.split(':') | |
|
62 | return _repo, (name, val) | |
|
63 | ||
|
64 | def other_parser(other): | |
|
65 | _repo = org_repo | |
|
66 | name, val = other.split(':') | |
|
67 | if 'repo' in other: | |
|
68 | _repo = val | |
|
69 | name = 'branch' | |
|
70 | val = c.rhodecode_repo.DEFAULT_BRANCH_NAME | |
|
71 | ||
|
72 | return _repo, (name, val) | |
|
73 | ||
|
74 | if '...' in ref: | |
|
75 | try: | |
|
76 | org, other = ref.split('...') | |
|
77 | org_repo, org_ref = org_parser(org) | |
|
78 | other_repo, other_ref = other_parser(other) | |
|
79 | return org_repo, org_ref, other_repo, other_ref | |
|
80 | except: | |
|
81 | log.error(traceback.format_exc()) | |
|
82 | ||
|
83 | raise HTTPNotFound | |
|
84 | ||
|
85 | def index(self, ref): | |
|
86 | ||
|
87 | org_repo, org_ref, other_repo, other_ref = self._handle_ref(ref) | |
|
88 | return ''' | |
|
89 | <pre> | |
|
90 | REPO: %s | |
|
91 | REF: %s | |
|
92 | ||
|
93 | vs | |
|
94 | ||
|
95 | REPO: %s | |
|
96 | REF: %s | |
|
97 | </pre> | |
|
98 | ''' % (org_repo, org_ref, other_repo, other_ref) |
@@ -0,0 +1,7 b'' | |||
|
1 | from rhodecode.tests import * | |
|
2 | ||
|
3 | class TestCompareController(TestController): | |
|
4 | ||
|
5 | def test_index(self): | |
|
6 | response = self.app.get(url(controller='compare', action='index')) | |
|
7 | # Test response... |
@@ -412,6 +412,11 b' def make_map(config):' | |||
|
412 | 412 | controller='changeset', action='raw_changeset', |
|
413 | 413 | revision='tip', conditions=dict(function=check_repo)) |
|
414 | 414 | |
|
415 | rmap.connect('compare_home', | |
|
416 | '/{repo_name:.*}/compare/{ref:.*}', | |
|
417 | controller='compare', action='index', | |
|
418 | conditions=dict(function=check_repo)) | |
|
419 | ||
|
415 | 420 | rmap.connect('summary_home', '/{repo_name:.*}/summary', |
|
416 | 421 | controller='summary', conditions=dict(function=check_repo)) |
|
417 | 422 |
General Comments 0
You need to be logged in to leave comments.
Login now