comparison rhodecode/controllers/compare.py @ 3380:01fe360a66c0 beta

fixed pull-requests with cherry picking changesets - fixed tests for them
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 19 Feb 2013 01:57:59 +0100
parents 674a8fad3abc
children 934f1fd5d549
comparison
equal deleted inserted replaced
3379:8171dfafb5db 3380:01fe360a66c0
38 from rhodecode.lib import diffs 38 from rhodecode.lib import diffs
39 39
40 from rhodecode.model.db import Repository 40 from rhodecode.model.db import Repository
41 from rhodecode.model.pull_request import PullRequestModel 41 from rhodecode.model.pull_request import PullRequestModel
42 from webob.exc import HTTPBadRequest 42 from webob.exc import HTTPBadRequest
43 from rhodecode.lib.utils2 import str2bool
44 from rhodecode.lib.diffs import LimitedDiffContainer 43 from rhodecode.lib.diffs import LimitedDiffContainer
45 from rhodecode.lib.vcs.backends.base import EmptyChangeset
46 44
47 log = logging.getLogger(__name__) 45 log = logging.getLogger(__name__)
48 46
49 47
50 class CompareController(BaseRepoController): 48 class CompareController(BaseRepoController):
97 repo_name=other_repo, 95 repo_name=other_repo,
98 org_ref_type=other_ref[0], org_ref=other_ref[1], 96 org_ref_type=other_ref[0], org_ref=other_ref[1],
99 other_repo=org_repo, 97 other_repo=org_repo,
100 other_ref_type=org_ref[0], other_ref=org_ref[1]) 98 other_ref_type=org_ref[0], other_ref=org_ref[1])
101 99
102 c.org_repo = org_repo = Repository.get_by_repo_name(org_repo) 100 partial = request.environ.get('HTTP_X_PARTIAL_XHR')
103 c.other_repo = other_repo = Repository.get_by_repo_name(other_repo)
104 101
105 if c.org_repo is None: 102 org_repo = Repository.get_by_repo_name(org_repo)
103 other_repo = Repository.get_by_repo_name(other_repo)
104
105 self.__get_cs_or_redirect(rev=org_ref, repo=org_repo, partial=partial)
106 self.__get_cs_or_redirect(rev=other_ref, repo=other_repo, partial=partial)
107
108 if org_repo is None:
106 log.error('Could not find org repo %s' % org_repo) 109 log.error('Could not find org repo %s' % org_repo)
107 raise HTTPNotFound 110 raise HTTPNotFound
108 if c.other_repo is None: 111 if other_repo is None:
109 log.error('Could not find other repo %s' % other_repo) 112 log.error('Could not find other repo %s' % other_repo)
110 raise HTTPNotFound 113 raise HTTPNotFound
111 114
112 if c.org_repo != c.other_repo and h.is_git(c.rhodecode_repo): 115 if org_repo != other_repo and h.is_git(org_repo):
113 log.error('compare of two remote repos not available for GIT REPOS') 116 log.error('compare of two remote repos not available for GIT REPOS')
114 raise HTTPNotFound 117 raise HTTPNotFound
115 118
116 if c.org_repo.scm_instance.alias != c.other_repo.scm_instance.alias: 119 if org_repo.scm_instance.alias != other_repo.scm_instance.alias:
117 log.error('compare of two different kind of remote repos not available') 120 log.error('compare of two different kind of remote repos not available')
118 raise HTTPNotFound 121 raise HTTPNotFound
119 122
120 partial = request.environ.get('HTTP_X_PARTIAL_XHR') 123 c.org_repo = org_repo
121 self.__get_cs_or_redirect(rev=org_ref, repo=org_repo, partial=partial) 124 c.other_repo = other_repo
122 self.__get_cs_or_redirect(rev=other_ref, repo=other_repo, partial=partial) 125 c.org_ref = org_ref[1]
126 c.other_ref = other_ref[1]
127 c.org_ref_type = org_ref[0]
128 c.other_ref_type = other_ref[0]
123 129
124 if rev_start and rev_end: 130 if rev_start and rev_end:
125 #replace our org_ref with given CS 131 # swap revs with cherry picked ones, save them for display
132 #org_ref = ('rev', rev_start)
133 #other_ref = ('rev', rev_end)
134 c.org_ref = rev_start[:12]
135 c.other_ref = rev_end[:12]
136 # get parent of
137 # rev start to include it in the diff
138 _cs = other_repo.scm_instance.get_changeset(rev_start)
139 rev_start = _cs.parents[0].raw_id
126 org_ref = ('rev', rev_start) 140 org_ref = ('rev', rev_start)
127 other_ref = ('rev', rev_end) 141 other_ref = ('rev', rev_end)
142 #if we cherry pick it's not remote, make the other_repo org_repo
143 org_repo = other_repo
128 144
129 c.cs_ranges, ancestor = PullRequestModel().get_compare_data( 145 c.cs_ranges, ancestor = PullRequestModel().get_compare_data(
130 org_repo, org_ref, other_repo, other_ref) 146 org_repo, org_ref, other_repo, other_ref)
131 147
132 c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in 148 c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in
134 # defines that we need hidden inputs with changesets 150 # defines that we need hidden inputs with changesets
135 c.as_form = request.GET.get('as_form', False) 151 c.as_form = request.GET.get('as_form', False)
136 if partial: 152 if partial:
137 return render('compare/compare_cs.html') 153 return render('compare/compare_cs.html')
138 154
139 c.org_ref = org_ref[1] 155 if ancestor and org_repo != other_repo:
140 c.org_ref_type = org_ref[0]
141 c.other_ref = other_ref[1]
142 c.other_ref_type = other_ref[0]
143
144 if ancestor and c.org_repo != c.other_repo:
145 # case we want a simple diff without incoming changesets, 156 # case we want a simple diff without incoming changesets,
146 # previewing what will be merged. 157 # previewing what will be merged.
147 # Make the diff on the forked repo, with 158 # Make the diff on the forked repo, with
148 # revision that is common ancestor 159 # revision that is common ancestor
149 _org_ref = org_ref 160 log.debug('Using ancestor %s as org_ref instead of %s'
150 log.debug('Using ancestor %s as org_ref instead of %s', ancestor, _org_ref) 161 % (ancestor, org_ref))
151 org_ref = ('rev', ancestor) 162 org_ref = ('rev', ancestor)
152 org_repo = other_repo 163 org_repo = other_repo
153 164
154 diff_limit = self.cut_off_limit if not fulldiff else None 165 diff_limit = self.cut_off_limit if not fulldiff else None
155 166