annotate rhodecode/controllers/compare.py @ 2501:044c31d67ccc beta

make get_action always return action
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 21 Jun 2012 17:51:01 +0200
parents 995d938ce14b
children 16a6a2f5d422
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2241
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 """
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 rhodecode.controllers.compare
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 compare controller for pylons showoing differences between two
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7 repos, branches, bookmarks or tips
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 :created_on: May 6, 2012
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 :author: marcink
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 :license: GPLv3, see COPYING for more details.
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13 """
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14 # This program is free software: you can redistribute it and/or modify
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15 # it under the terms of the GNU General Public License as published by
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16 # the Free Software Foundation, either version 3 of the License, or
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 # (at your option) any later version.
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 #
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 # This program is distributed in the hope that it will be useful,
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 # GNU General Public License for more details.
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 #
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 # You should have received a copy of the GNU General Public License
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 import logging
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 import traceback
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28
2337
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2245
diff changeset
29 from webob.exc import HTTPNotFound
2241
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 from pylons import request, response, session, tmpl_context as c, url
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31 from pylons.controllers.util import abort, redirect
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32
2348
a07e04ef7bb4 Implemented basic compare view(for pull requests) for mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents: 2337
diff changeset
33 from rhodecode.lib import helpers as h
2241
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 from rhodecode.lib.base import BaseRepoController, render
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
2337
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2245
diff changeset
36 from rhodecode.lib import diffs
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2245
diff changeset
37
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2245
diff changeset
38 from rhodecode.model.db import Repository
2442
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
39 from rhodecode.model.pull_request import PullRequestModel
2241
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41 log = logging.getLogger(__name__)
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44 class CompareController(BaseRepoController):
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46 @LoginRequired()
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48 'repository.admin')
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 def __before__(self):
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 super(CompareController, self).__before__()
b2a2868d7bec Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51
2363
745dda7817ed Rewrote url routes to make all validations and parsing for compare view + added compare fork button into forked repos
Marcin Kuzminski <marcin@python-works.com>
parents: 2362
diff changeset
52 def index(self, org_ref_type, org_ref, other_ref_type, other_ref):
2362
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2355
diff changeset
53
2363
745dda7817ed Rewrote url routes to make all validations and parsing for compare view + added compare fork button into forked repos
Marcin Kuzminski <marcin@python-works.com>
parents: 2362
diff changeset
54 org_repo = c.rhodecode_db_repo.repo_name
745dda7817ed Rewrote url routes to make all validations and parsing for compare view + added compare fork button into forked repos
Marcin Kuzminski <marcin@python-works.com>
parents: 2362
diff changeset
55 org_ref = (org_ref_type, org_ref)
745dda7817ed Rewrote url routes to make all validations and parsing for compare view + added compare fork button into forked repos
Marcin Kuzminski <marcin@python-works.com>
parents: 2362
diff changeset
56 other_ref = (other_ref_type, other_ref)
745dda7817ed Rewrote url routes to make all validations and parsing for compare view + added compare fork button into forked repos
Marcin Kuzminski <marcin@python-works.com>
parents: 2362
diff changeset
57 other_repo = request.GET.get('repo', org_repo)
745dda7817ed Rewrote url routes to make all validations and parsing for compare view + added compare fork button into forked repos
Marcin Kuzminski <marcin@python-works.com>
parents: 2362
diff changeset
58
745dda7817ed Rewrote url routes to make all validations and parsing for compare view + added compare fork button into forked repos
Marcin Kuzminski <marcin@python-works.com>
parents: 2362
diff changeset
59 c.swap_url = h.url('compare_url', repo_name=other_repo,
745dda7817ed Rewrote url routes to make all validations and parsing for compare view + added compare fork button into forked repos
Marcin Kuzminski <marcin@python-works.com>
parents: 2362
diff changeset
60 org_ref_type=other_ref[0], org_ref=other_ref[1],
745dda7817ed Rewrote url routes to make all validations and parsing for compare view + added compare fork button into forked repos
Marcin Kuzminski <marcin@python-works.com>
parents: 2362
diff changeset
61 other_ref_type=org_ref[0], other_ref=org_ref[1],
745dda7817ed Rewrote url routes to make all validations and parsing for compare view + added compare fork button into forked repos
Marcin Kuzminski <marcin@python-works.com>
parents: 2362
diff changeset
62 repo=org_repo)
745dda7817ed Rewrote url routes to make all validations and parsing for compare view + added compare fork button into forked repos
Marcin Kuzminski <marcin@python-works.com>
parents: 2362
diff changeset
63
2337
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2245
diff changeset
64 c.org_repo = org_repo = Repository.get_by_repo_name(org_repo)
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2245
diff changeset
65 c.other_repo = other_repo = Repository.get_by_repo_name(other_repo)
2362
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2355
diff changeset
66
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2355
diff changeset
67 if c.org_repo is None or c.other_repo is None:
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2355
diff changeset
68 log.error('Could not found repo %s or %s' % (org_repo, other_repo))
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2355
diff changeset
69 raise HTTPNotFound
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2355
diff changeset
70
2444
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
71 if c.org_repo.scm_instance.alias != 'hg':
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
72 log.error('Review not available for GIT REPOS')
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
73 raise HTTPNotFound
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
74
2442
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
75 c.cs_ranges, discovery_data = PullRequestModel().get_compare_data(
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
76 org_repo, org_ref, other_repo, other_ref
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
77 )
2337
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2245
diff changeset
78
2393
b94eac50ec4d added changeset review status into repo/branch compare view
Marcin Kuzminski <marcin@python-works.com>
parents: 2363
diff changeset
79 c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in
b94eac50ec4d added changeset review status into repo/branch compare view
Marcin Kuzminski <marcin@python-works.com>
parents: 2363
diff changeset
80 c.cs_ranges])
2487
995d938ce14b Fixed origin repo in pull-request view
Marcin Kuzminski <marcin@python-works.com>
parents: 2444
diff changeset
81 c.target_repo = c.repo_name
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
82 # defines that we need hidden inputs with changesets
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
83 c.as_form = request.GET.get('as_form', False)
2395
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2393
diff changeset
84 if request.environ.get('HTTP_X_PARTIAL_XHR'):
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2393
diff changeset
85 return render('compare/compare_cs.html')
2393
b94eac50ec4d added changeset review status into repo/branch compare view
Marcin Kuzminski <marcin@python-works.com>
parents: 2363
diff changeset
86
2337
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2245
diff changeset
87 c.org_ref = org_ref[1]
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2245
diff changeset
88 c.other_ref = other_ref[1]
2350
d787da66c292 Changed compare-view of remote repos to use incoming option instead of outgoing.
Marcin Kuzminski <marcin@python-works.com>
parents: 2348
diff changeset
89 # diff needs to have swapped org with other to generate proper diff
2362
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2355
diff changeset
90 _diff = diffs.differ(other_repo, other_ref, org_repo, org_ref,
3c4afb8894bd Improved cross repos diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 2355
diff changeset
91 discovery_data)
2337
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2245
diff changeset
92 diff_processor = diffs.DiffProcessor(_diff, format='gitdiff')
2348
a07e04ef7bb4 Implemented basic compare view(for pull requests) for mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents: 2337
diff changeset
93 _parsed = diff_processor.prepare()
2337
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2245
diff changeset
94
2348
a07e04ef7bb4 Implemented basic compare view(for pull requests) for mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents: 2337
diff changeset
95 c.files = []
a07e04ef7bb4 Implemented basic compare view(for pull requests) for mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents: 2337
diff changeset
96 c.changes = {}
2393
b94eac50ec4d added changeset review status into repo/branch compare view
Marcin Kuzminski <marcin@python-works.com>
parents: 2363
diff changeset
97
b94eac50ec4d added changeset review status into repo/branch compare view
Marcin Kuzminski <marcin@python-works.com>
parents: 2363
diff changeset
98 for f in _parsed:
2348
a07e04ef7bb4 Implemented basic compare view(for pull requests) for mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents: 2337
diff changeset
99 fid = h.FID('', f['filename'])
a07e04ef7bb4 Implemented basic compare view(for pull requests) for mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents: 2337
diff changeset
100 c.files.append([fid, f['operation'], f['filename'], f['stats']])
a07e04ef7bb4 Implemented basic compare view(for pull requests) for mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents: 2337
diff changeset
101 diff = diff_processor.as_html(enable_comments=False, diff_lines=[f])
a07e04ef7bb4 Implemented basic compare view(for pull requests) for mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents: 2337
diff changeset
102 c.changes[fid] = [f['operation'], f['filename'], diff]
2337
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2245
diff changeset
103
f8c953c6b040 Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 2245
diff changeset
104 return render('compare/compare_diff.html')