Show More
@@ -23,8 +23,10 b'' | |||||
23 | # |
|
23 | # | |
24 | # You should have received a copy of the GNU General Public License |
|
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/>. |
|
25 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
|
26 | ||||
26 | import logging |
|
27 | import logging | |
27 | import traceback |
|
28 | import traceback | |
|
29 | import re | |||
28 |
|
30 | |||
29 | from webob.exc import HTTPNotFound |
|
31 | from webob.exc import HTTPNotFound | |
30 | from pylons import request, response, session, tmpl_context as c, url |
|
32 | from pylons import request, response, session, tmpl_context as c, url | |
@@ -32,16 +34,17 b' from pylons.controllers.util import abor' | |||||
32 | from pylons.i18n.translation import _ |
|
34 | from pylons.i18n.translation import _ | |
33 |
|
35 | |||
34 | from rhodecode.lib.vcs.exceptions import EmptyRepositoryError, RepositoryError |
|
36 | from rhodecode.lib.vcs.exceptions import EmptyRepositoryError, RepositoryError | |
|
37 | from rhodecode.lib.vcs.utils import safe_str | |||
|
38 | from rhodecode.lib.vcs.utils.hgcompat import scmutil | |||
35 | from rhodecode.lib import helpers as h |
|
39 | from rhodecode.lib import helpers as h | |
36 | from rhodecode.lib.base import BaseRepoController, render |
|
40 | from rhodecode.lib.base import BaseRepoController, render | |
37 | from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator |
|
41 | from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator | |
38 | from rhodecode.lib import diffs |
|
42 | from rhodecode.lib import diffs, unionrepo | |
39 |
|
43 | |||
40 | from rhodecode.model.db import Repository |
|
44 | from rhodecode.model.db import Repository | |
41 | from rhodecode.model.pull_request import PullRequestModel |
|
|||
42 | from webob.exc import HTTPBadRequest |
|
45 | from webob.exc import HTTPBadRequest | |
43 | from rhodecode.lib.diffs import LimitedDiffContainer |
|
46 | from rhodecode.lib.diffs import LimitedDiffContainer | |
44 | from rhodecode.lib.vcs.backends.base import EmptyChangeset |
|
47 | ||
45 |
|
48 | |||
46 | log = logging.getLogger(__name__) |
|
49 | log = logging.getLogger(__name__) | |
47 |
|
50 | |||
@@ -140,8 +143,10 b' class CompareController(BaseRepoControll' | |||||
140 | c.org_ref_type = org_ref[0] |
|
143 | c.org_ref_type = org_ref[0] | |
141 | c.other_ref_type = other_ref[0] |
|
144 | c.other_ref_type = other_ref[0] | |
142 |
|
145 | |||
143 |
c.cs_ranges, c.ancestor = |
|
146 | c.cs_ranges, c.ancestor = self._get_changesets(org_repo.scm_instance.alias, | |
144 | org_repo, org_ref, other_repo, other_ref, merge) |
|
147 | org_repo.scm_instance, org_ref, | |
|
148 | other_repo.scm_instance, other_ref, | |||
|
149 | merge) | |||
145 |
|
150 | |||
146 | c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in |
|
151 | c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in | |
147 | c.cs_ranges]) |
|
152 | c.cs_ranges]) | |
@@ -189,3 +194,76 b' class CompareController(BaseRepoControll' | |||||
189 | c.changes[fid] = [f['operation'], f['filename'], diff] |
|
194 | c.changes[fid] = [f['operation'], f['filename'], diff] | |
190 |
|
195 | |||
191 | return render('compare/compare_diff.html') |
|
196 | return render('compare/compare_diff.html') | |
|
197 | ||||
|
198 | def _get_changesets(self, alias, org_repo, org_ref, other_repo, other_ref, merge): | |||
|
199 | """ | |||
|
200 | Returns a list of changesets that can be merged from org_repo@org_ref | |||
|
201 | to other_repo@other_ref ... and the ancestor that would be used for merge | |||
|
202 | ||||
|
203 | :param org_repo: | |||
|
204 | :param org_ref: | |||
|
205 | :param other_repo: | |||
|
206 | :param other_ref: | |||
|
207 | :param tmp: | |||
|
208 | """ | |||
|
209 | ||||
|
210 | ancestor = None | |||
|
211 | ||||
|
212 | if alias == 'hg': | |||
|
213 | # lookup up the exact node id | |||
|
214 | _revset_predicates = { | |||
|
215 | 'branch': 'branch', | |||
|
216 | 'book': 'bookmark', | |||
|
217 | 'tag': 'tag', | |||
|
218 | 'rev': 'id', | |||
|
219 | } | |||
|
220 | ||||
|
221 | org_rev_spec = "max(%s('%s'))" % (_revset_predicates[org_ref[0]], | |||
|
222 | safe_str(org_ref[1])) | |||
|
223 | org_revs = scmutil.revrange(org_repo._repo, [org_rev_spec]) | |||
|
224 | org_rev = org_repo._repo[org_revs[-1] if org_revs else -1].hex() | |||
|
225 | ||||
|
226 | other_rev_spec = "max(%s('%s'))" % (_revset_predicates[other_ref[0]], | |||
|
227 | safe_str(other_ref[1])) | |||
|
228 | other_revs = scmutil.revrange(other_repo._repo, [other_rev_spec]) | |||
|
229 | other_rev = other_repo._repo[other_revs[-1] if other_revs else -1].hex() | |||
|
230 | ||||
|
231 | #case two independent repos | |||
|
232 | if org_repo != other_repo: | |||
|
233 | hgrepo = unionrepo.unionrepository(other_repo.baseui, | |||
|
234 | other_repo.path, | |||
|
235 | org_repo.path) | |||
|
236 | # all the changesets we are looking for will be in other_repo, | |||
|
237 | # so rev numbers from hgrepo can be used in other_repo | |||
|
238 | ||||
|
239 | #no remote compare do it on the same repository | |||
|
240 | else: | |||
|
241 | hgrepo = other_repo._repo | |||
|
242 | ||||
|
243 | if merge: | |||
|
244 | revs = ["ancestors(id('%s')) and not ancestors(id('%s')) and not id('%s')" % | |||
|
245 | (other_rev, org_rev, org_rev)] | |||
|
246 | ||||
|
247 | ancestors = scmutil.revrange(hgrepo, | |||
|
248 | ["ancestor(id('%s'), id('%s'))" % (org_rev, other_rev)]) | |||
|
249 | if ancestors: | |||
|
250 | # pick arbitrary ancestor - but there is usually only one | |||
|
251 | ancestor = hgrepo[ancestors[0]].hex() | |||
|
252 | else: | |||
|
253 | # TODO: have both + and - changesets | |||
|
254 | revs = ["id('%s') :: id('%s') - id('%s')" % | |||
|
255 | (org_rev, other_rev, org_rev)] | |||
|
256 | ||||
|
257 | changesets = [other_repo.get_changeset(cs) | |||
|
258 | for cs in scmutil.revrange(hgrepo, revs)] | |||
|
259 | ||||
|
260 | elif alias == 'git': | |||
|
261 | assert org_repo == other_repo, (org_repo, other_repo) # no git support for different repos | |||
|
262 | so, se = org_repo.run_git_command( | |||
|
263 | 'log --reverse --pretty="format: %%H" -s -p %s..%s' % (org_ref[1], | |||
|
264 | other_ref[1]) | |||
|
265 | ) | |||
|
266 | changesets = [org_repo.get_changeset(cs) | |||
|
267 | for cs in re.findall(r'[0-9a-fA-F]{40}', so)] | |||
|
268 | ||||
|
269 | return changesets, ancestor |
General Comments 0
You need to be logged in to leave comments.
Login now