Mercurial > kallithea
annotate rhodecode/controllers/compare.py @ 4147:1c8f818787b3 rhodecode-2.2.5-gpl
old style: show the full link box on summary page - no overlap or truncation
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Wed, 02 Jul 2014 19:03:23 -0400 |
parents | ffd45b185016 |
children | 7e5f8c12a3fc |
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 # 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
|
3 # 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
|
4 # 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
|
5 # (at your option) any later version. |
b2a2868d7bec
Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 # |
b2a2868d7bec
Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 # 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
|
8 # 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
|
9 # 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
|
10 # GNU General Public License for more details. |
b2a2868d7bec
Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 # |
b2a2868d7bec
Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 # 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
|
13 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
14 """ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
15 rhodecode.controllers.compare |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
17 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
18 compare controller for pylons showing differences between two |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
19 repos, branches, bookmarks or tips |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
20 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
21 :created_on: May 6, 2012 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
22 :author: marcink |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
23 :copyright: (c) 2013 RhodeCode GmbH. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
24 :license: GPLv3, see LICENSE for more details. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
25 """ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
26 |
3721
6c79bfcd3b54
compare: move get_changesets to compare controller where it is used
Mads Kiilerich <madski@unity3d.com>
parents:
3718
diff
changeset
|
27 |
2241
b2a2868d7bec
Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 import logging |
b2a2868d7bec
Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 import traceback |
3721
6c79bfcd3b54
compare: move get_changesets to compare controller where it is used
Mads Kiilerich <madski@unity3d.com>
parents:
3718
diff
changeset
|
30 import re |
2241
b2a2868d7bec
Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 |
4077
0e1023147334
Use safe_str on flash messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
4041
diff
changeset
|
32 from webob.exc import HTTPNotFound, HTTPBadRequest |
2241
b2a2868d7bec
Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 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
|
34 from pylons.controllers.util import abort, redirect |
2593
16a6a2f5d422
Add check for existing revisions in compare view
Marcin Kuzminski <marcin@python-works.com>
parents:
2487
diff
changeset
|
35 from pylons.i18n.translation import _ |
2241
b2a2868d7bec
Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 |
2593
16a6a2f5d422
Add check for existing revisions in compare view
Marcin Kuzminski <marcin@python-works.com>
parents:
2487
diff
changeset
|
37 from rhodecode.lib.vcs.exceptions import EmptyRepositoryError, RepositoryError |
3721
6c79bfcd3b54
compare: move get_changesets to compare controller where it is used
Mads Kiilerich <madski@unity3d.com>
parents:
3718
diff
changeset
|
38 from rhodecode.lib.vcs.utils import safe_str |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
39 from rhodecode.lib.vcs.utils.hgcompat import unionrepo |
2348
a07e04ef7bb4
Implemented basic compare view(for pull requests) for mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
2337
diff
changeset
|
40 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
|
41 from rhodecode.lib.base import BaseRepoController, render |
b2a2868d7bec
Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator |
3976
42bca6fa923b
unionrepo: update for Mercurial 2.6
Mads Kiilerich <madski@unity3d.com>
parents:
3821
diff
changeset
|
43 from rhodecode.lib import diffs |
2337
f8c953c6b040
Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
2245
diff
changeset
|
44 from rhodecode.model.db import Repository |
3011
25d77aef2729
Optimized look of compare view of changesets.
Marcin Kuzminski <marcin@python-works.com>
parents:
3010
diff
changeset
|
45 from rhodecode.lib.diffs import LimitedDiffContainer |
3721
6c79bfcd3b54
compare: move get_changesets to compare controller where it is used
Mads Kiilerich <madski@unity3d.com>
parents:
3718
diff
changeset
|
46 |
2241
b2a2868d7bec
Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 |
b2a2868d7bec
Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 log = logging.getLogger(__name__) |
b2a2868d7bec
Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 |
b2a2868d7bec
Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 |
b2a2868d7bec
Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 class CompareController(BaseRepoController): |
b2a2868d7bec
Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 |
b2a2868d7bec
Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 def __before__(self): |
b2a2868d7bec
Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 super(CompareController, self).__before__() |
b2a2868d7bec
Basic compare-view controller with ref parsing
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 |
4039
b44fabc4377c
compare: resolve revisions in the right repository for diffs between repos
Mads Kiilerich <madski@unity3d.com>
parents:
4038
diff
changeset
|
56 def __get_rev_or_redirect(self, ref, repo, redirect_after=True, |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
57 partial=False): |
2593
16a6a2f5d422
Add check for existing revisions in compare view
Marcin Kuzminski <marcin@python-works.com>
parents:
2487
diff
changeset
|
58 """ |
16a6a2f5d422
Add check for existing revisions in compare view
Marcin Kuzminski <marcin@python-works.com>
parents:
2487
diff
changeset
|
59 Safe way to get changeset if error occur it redirects to changeset with |
2847
1cd0a0c05f42
swap the select values with revisions dynamically when switching the repos on pull request view
Marcin Kuzminski <marcin@python-works.com>
parents:
2684
diff
changeset
|
60 proper message. If partial is set then don't do redirect raise Exception |
1cd0a0c05f42
swap the select values with revisions dynamically when switching the repos on pull request view
Marcin Kuzminski <marcin@python-works.com>
parents:
2684
diff
changeset
|
61 instead |
2593
16a6a2f5d422
Add check for existing revisions in compare view
Marcin Kuzminski <marcin@python-works.com>
parents:
2487
diff
changeset
|
62 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
63 :param ref: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
64 :param repo: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
65 :param redirect_after: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
66 :param partial: |
2593
16a6a2f5d422
Add check for existing revisions in compare view
Marcin Kuzminski <marcin@python-works.com>
parents:
2487
diff
changeset
|
67 """ |
4038
ed50319aab94
compare: make __get_cs_or_redirect more exact
Mads Kiilerich <madski@unity3d.com>
parents:
4037
diff
changeset
|
68 rev = ref[1] # default and used for git |
ed50319aab94
compare: make __get_cs_or_redirect more exact
Mads Kiilerich <madski@unity3d.com>
parents:
4037
diff
changeset
|
69 if repo.scm_instance.alias == 'hg': |
ed50319aab94
compare: make __get_cs_or_redirect more exact
Mads Kiilerich <madski@unity3d.com>
parents:
4037
diff
changeset
|
70 # lookup up the exact node id |
ed50319aab94
compare: make __get_cs_or_redirect more exact
Mads Kiilerich <madski@unity3d.com>
parents:
4037
diff
changeset
|
71 _revset_predicates = { |
ed50319aab94
compare: make __get_cs_or_redirect more exact
Mads Kiilerich <madski@unity3d.com>
parents:
4037
diff
changeset
|
72 'branch': 'branch', |
ed50319aab94
compare: make __get_cs_or_redirect more exact
Mads Kiilerich <madski@unity3d.com>
parents:
4037
diff
changeset
|
73 'book': 'bookmark', |
ed50319aab94
compare: make __get_cs_or_redirect more exact
Mads Kiilerich <madski@unity3d.com>
parents:
4037
diff
changeset
|
74 'tag': 'tag', |
ed50319aab94
compare: make __get_cs_or_redirect more exact
Mads Kiilerich <madski@unity3d.com>
parents:
4037
diff
changeset
|
75 'rev': 'id', |
ed50319aab94
compare: make __get_cs_or_redirect more exact
Mads Kiilerich <madski@unity3d.com>
parents:
4037
diff
changeset
|
76 } |
ed50319aab94
compare: make __get_cs_or_redirect more exact
Mads Kiilerich <madski@unity3d.com>
parents:
4037
diff
changeset
|
77 rev_spec = "max(%s(%%s))" % _revset_predicates[ref[0]] |
ed50319aab94
compare: make __get_cs_or_redirect more exact
Mads Kiilerich <madski@unity3d.com>
parents:
4037
diff
changeset
|
78 revs = repo.scm_instance._repo.revs(rev_spec, safe_str(ref[1])) |
ed50319aab94
compare: make __get_cs_or_redirect more exact
Mads Kiilerich <madski@unity3d.com>
parents:
4037
diff
changeset
|
79 if revs: |
ed50319aab94
compare: make __get_cs_or_redirect more exact
Mads Kiilerich <madski@unity3d.com>
parents:
4037
diff
changeset
|
80 rev = revs[-1] |
ed50319aab94
compare: make __get_cs_or_redirect more exact
Mads Kiilerich <madski@unity3d.com>
parents:
4037
diff
changeset
|
81 # else: TODO: just report 'not found' |
ed50319aab94
compare: make __get_cs_or_redirect more exact
Mads Kiilerich <madski@unity3d.com>
parents:
4037
diff
changeset
|
82 |
2593
16a6a2f5d422
Add check for existing revisions in compare view
Marcin Kuzminski <marcin@python-works.com>
parents:
2487
diff
changeset
|
83 try: |
4039
b44fabc4377c
compare: resolve revisions in the right repository for diffs between repos
Mads Kiilerich <madski@unity3d.com>
parents:
4038
diff
changeset
|
84 return repo.scm_instance.get_changeset(rev).raw_id |
2593
16a6a2f5d422
Add check for existing revisions in compare view
Marcin Kuzminski <marcin@python-works.com>
parents:
2487
diff
changeset
|
85 except EmptyRepositoryError, e: |
16a6a2f5d422
Add check for existing revisions in compare view
Marcin Kuzminski <marcin@python-works.com>
parents:
2487
diff
changeset
|
86 if not redirect_after: |
16a6a2f5d422
Add check for existing revisions in compare view
Marcin Kuzminski <marcin@python-works.com>
parents:
2487
diff
changeset
|
87 return None |
16a6a2f5d422
Add check for existing revisions in compare view
Marcin Kuzminski <marcin@python-works.com>
parents:
2487
diff
changeset
|
88 h.flash(h.literal(_('There are no changesets yet')), |
16a6a2f5d422
Add check for existing revisions in compare view
Marcin Kuzminski <marcin@python-works.com>
parents:
2487
diff
changeset
|
89 category='warning') |
16a6a2f5d422
Add check for existing revisions in compare view
Marcin Kuzminski <marcin@python-works.com>
parents:
2487
diff
changeset
|
90 redirect(url('summary_home', repo_name=repo.repo_name)) |
16a6a2f5d422
Add check for existing revisions in compare view
Marcin Kuzminski <marcin@python-works.com>
parents:
2487
diff
changeset
|
91 |
16a6a2f5d422
Add check for existing revisions in compare view
Marcin Kuzminski <marcin@python-works.com>
parents:
2487
diff
changeset
|
92 except RepositoryError, e: |
2684
2b6939a77052
Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents:
2593
diff
changeset
|
93 log.error(traceback.format_exc()) |
4077
0e1023147334
Use safe_str on flash messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
4041
diff
changeset
|
94 h.flash(safe_str(e), category='warning') |
2847
1cd0a0c05f42
swap the select values with revisions dynamically when switching the repos on pull request view
Marcin Kuzminski <marcin@python-works.com>
parents:
2684
diff
changeset
|
95 if not partial: |
1cd0a0c05f42
swap the select values with revisions dynamically when switching the repos on pull request view
Marcin Kuzminski <marcin@python-works.com>
parents:
2684
diff
changeset
|
96 redirect(h.url('summary_home', repo_name=repo.repo_name)) |
1cd0a0c05f42
swap the select values with revisions dynamically when switching the repos on pull request view
Marcin Kuzminski <marcin@python-works.com>
parents:
2684
diff
changeset
|
97 raise HTTPBadRequest() |
2593
16a6a2f5d422
Add check for existing revisions in compare view
Marcin Kuzminski <marcin@python-works.com>
parents:
2487
diff
changeset
|
98 |
4041
15f4825890fe
compare: let _get_changesets work on the already resolved revisions
Mads Kiilerich <madski@unity3d.com>
parents:
4040
diff
changeset
|
99 def _get_changesets(self, alias, org_repo, org_rev, other_repo, other_rev, merge): |
3749
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
100 """ |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
101 Returns a list of changesets that can be merged from org_repo at org_rev |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
102 to other_repo at other_rev ... and the ancestor that would be used for merge. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
103 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
104 :param org_repo: repo object, that is most likely the orginal repo we forked from |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
105 :param org_rev: the revision we want our compare to be made |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
106 :param other_repo: repo object, mostl likely the fork of org_repo. It hass |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
107 all changesets that we need to obtain |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
108 :param other_rev: revision we want out compare to be made on other_repo |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
109 |
3749
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
110 """ |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
111 ancestor = None |
4040
d415621fa7c5
compare: handle revisions and ancestor of empty range in _get_changesets
Mads Kiilerich <madski@unity3d.com>
parents:
4039
diff
changeset
|
112 if org_rev == other_rev: |
d415621fa7c5
compare: handle revisions and ancestor of empty range in _get_changesets
Mads Kiilerich <madski@unity3d.com>
parents:
4039
diff
changeset
|
113 changesets = [] |
d415621fa7c5
compare: handle revisions and ancestor of empty range in _get_changesets
Mads Kiilerich <madski@unity3d.com>
parents:
4039
diff
changeset
|
114 if merge: |
d415621fa7c5
compare: handle revisions and ancestor of empty range in _get_changesets
Mads Kiilerich <madski@unity3d.com>
parents:
4039
diff
changeset
|
115 ancestor = org_rev |
d415621fa7c5
compare: handle revisions and ancestor of empty range in _get_changesets
Mads Kiilerich <madski@unity3d.com>
parents:
4039
diff
changeset
|
116 |
d415621fa7c5
compare: handle revisions and ancestor of empty range in _get_changesets
Mads Kiilerich <madski@unity3d.com>
parents:
4039
diff
changeset
|
117 elif alias == 'hg': |
3749
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
118 #case two independent repos |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
119 if org_repo != other_repo: |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
120 hgrepo = unionrepo.unionrepository(other_repo.baseui, |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
121 other_repo.path, |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
122 org_repo.path) |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
123 # all the changesets we are looking for will be in other_repo, |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
124 # so rev numbers from hgrepo can be used in other_repo |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
125 |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
126 #no remote compare do it on the same repository |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
127 else: |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
128 hgrepo = other_repo._repo |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
129 |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
130 if merge: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
131 revs = hgrepo.revs( |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
132 "ancestors(id(%s)) and not ancestors(id(%s)) and not id(%s)", |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
133 other_rev, org_rev, org_rev) |
3749
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
134 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
135 ancestors = hgrepo.revs("ancestor(id(%s), id(%s))", org_rev, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
136 other_rev) |
3749
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
137 if ancestors: |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
138 # pick arbitrary ancestor - but there is usually only one |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
139 ancestor = hgrepo[ancestors[0]].hex() |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
140 else: |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
141 # TODO: have both + and - changesets |
3811
3591b33e0c94
hg: use 'revset injection safe' repo.revs for revsets
Mads Kiilerich <madski@unity3d.com>
parents:
3783
diff
changeset
|
142 revs = hgrepo.revs("id(%s) :: id(%s) - id(%s)", |
3591b33e0c94
hg: use 'revset injection safe' repo.revs for revsets
Mads Kiilerich <madski@unity3d.com>
parents:
3783
diff
changeset
|
143 org_rev, other_rev, org_rev) |
3749
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
144 |
3811
3591b33e0c94
hg: use 'revset injection safe' repo.revs for revsets
Mads Kiilerich <madski@unity3d.com>
parents:
3783
diff
changeset
|
145 changesets = [other_repo.get_changeset(rev) for rev in revs] |
3749
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
146 |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
147 elif alias == 'git': |
3783
f533c054fb19
It's better to use Exception here than assertion. It plays better with the exception handling software like sentry or errormator
Marcin Kuzminski <marcin@python-works.com>
parents:
3771
diff
changeset
|
148 if org_repo != other_repo: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
149 from dulwich.repo import Repo |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
150 from dulwich.client import SubprocessGitClient |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
151 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
152 gitrepo = Repo(org_repo.path) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
153 SubprocessGitClient(thin_packs=False).fetch(other_repo.path, gitrepo) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
154 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
155 gitrepo_remote = Repo(other_repo.path) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
156 SubprocessGitClient(thin_packs=False).fetch(org_repo.path, gitrepo_remote) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
157 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
158 revs = [] |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
159 for x in gitrepo_remote.get_walker(include=[other_rev], |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
160 exclude=[org_rev]): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
161 revs.append(x.commit.id) |
3783
f533c054fb19
It's better to use Exception here than assertion. It plays better with the exception handling software like sentry or errormator
Marcin Kuzminski <marcin@python-works.com>
parents:
3771
diff
changeset
|
162 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
163 changesets = [other_repo.get_changeset(rev) for rev in reversed(revs)] |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
164 if changesets: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
165 ancestor = changesets[0].parents[0].raw_id |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
166 else: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
167 # no changesets from other repo, ancestor is the other_rev |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
168 ancestor = other_rev |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
169 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
170 else: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
171 so, se = org_repo.run_git_command( |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
172 'log --reverse --pretty="format: %%H" -s %s..%s' |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
173 % (org_rev, other_rev) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
174 ) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
175 changesets = [org_repo.get_changeset(cs) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
176 for cs in re.findall(r'[0-9a-fA-F]{40}', so)] |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
177 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
178 else: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
179 raise Exception('Bad alias only git and hg is allowed') |
3749
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
180 |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
181 return changesets, ancestor |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
182 |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
183 @LoginRequired() |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
184 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3721
diff
changeset
|
185 'repository.admin') |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
186 def index(self, repo_name): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
187 c.compare_home = True |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
188 org_repo = c.rhodecode_db_repo.repo_name |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
189 other_repo = request.GET.get('other_repo', org_repo) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
190 c.org_repo = Repository.get_by_repo_name(org_repo) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
191 c.other_repo = Repository.get_by_repo_name(other_repo) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
192 c.org_ref = c.other_ref = _('Select changeset') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
193 return render('compare/compare_diff.html') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
194 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
195 @LoginRequired() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
196 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
197 'repository.admin') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
198 def compare(self, repo_name, org_ref_type, org_ref, other_ref_type, other_ref): |
3443
3ac76dfdab8e
compare: minor refactoring and comments
Mads Kiilerich <madski@unity3d.com>
parents:
3442
diff
changeset
|
199 # org_ref will be evaluated in org_repo |
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
|
200 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
|
201 org_ref = (org_ref_type, org_ref) |
3443
3ac76dfdab8e
compare: minor refactoring and comments
Mads Kiilerich <madski@unity3d.com>
parents:
3442
diff
changeset
|
202 # other_ref will be evaluated in other_repo |
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
|
203 other_ref = (other_ref_type, other_ref) |
3317
b36285f90f89
compare: rename optional compare_url parameter repo to other_repo
Mads Kiilerich <madski@unity3d.com>
parents:
3304
diff
changeset
|
204 other_repo = request.GET.get('other_repo', org_repo) |
3486
2053053e0882
compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents:
3484
diff
changeset
|
205 # If merge is True: |
2053053e0882
compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents:
3484
diff
changeset
|
206 # Show what org would get if merged with other: |
2053053e0882
compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents:
3484
diff
changeset
|
207 # List changesets that are ancestors of other but not of org. |
2053053e0882
compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents:
3484
diff
changeset
|
208 # New changesets in org is thus ignored. |
2053053e0882
compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents:
3484
diff
changeset
|
209 # Diff will be from common ancestor, and merges of org to other will thus be ignored. |
2053053e0882
compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents:
3484
diff
changeset
|
210 # If merge is False: |
2053053e0882
compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents:
3484
diff
changeset
|
211 # Make a raw diff from org to other, no matter if related or not. |
2053053e0882
compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents:
3484
diff
changeset
|
212 # Changesets in one and not in the other will be ignored |
2053053e0882
compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents:
3484
diff
changeset
|
213 merge = bool(request.GET.get('merge')) |
3443
3ac76dfdab8e
compare: minor refactoring and comments
Mads Kiilerich <madski@unity3d.com>
parents:
3442
diff
changeset
|
214 # fulldiff disables cut_off_limit |
3ac76dfdab8e
compare: minor refactoring and comments
Mads Kiilerich <madski@unity3d.com>
parents:
3442
diff
changeset
|
215 c.fulldiff = request.GET.get('fulldiff') |
3442
b3680a200f75
compare: cleanup of as_form handling
Mads Kiilerich <madski@unity3d.com>
parents:
3387
diff
changeset
|
216 # partial uses compare_cs.html template directly |
b3680a200f75
compare: cleanup of as_form handling
Mads Kiilerich <madski@unity3d.com>
parents:
3387
diff
changeset
|
217 partial = request.environ.get('HTTP_X_PARTIAL_XHR') |
b3680a200f75
compare: cleanup of as_form handling
Mads Kiilerich <madski@unity3d.com>
parents:
3387
diff
changeset
|
218 # as_form puts hidden input field with changeset revisions |
b3680a200f75
compare: cleanup of as_form handling
Mads Kiilerich <madski@unity3d.com>
parents:
3387
diff
changeset
|
219 c.as_form = partial and request.GET.get('as_form') |
b3680a200f75
compare: cleanup of as_form handling
Mads Kiilerich <madski@unity3d.com>
parents:
3387
diff
changeset
|
220 # swap url for compare_diff page - never partial and never as_form |
b3680a200f75
compare: cleanup of as_form handling
Mads Kiilerich <madski@unity3d.com>
parents:
3387
diff
changeset
|
221 c.swap_url = h.url('compare_url', |
3317
b36285f90f89
compare: rename optional compare_url parameter repo to other_repo
Mads Kiilerich <madski@unity3d.com>
parents:
3304
diff
changeset
|
222 repo_name=other_repo, |
b36285f90f89
compare: rename optional compare_url parameter repo to other_repo
Mads Kiilerich <madski@unity3d.com>
parents:
3304
diff
changeset
|
223 org_ref_type=other_ref[0], org_ref=other_ref[1], |
3320
75431548602a
fixed broken swap url, and added a test to detect it in feature
Marcin Kuzminski <marcin@python-works.com>
parents:
3317
diff
changeset
|
224 other_repo=org_repo, |
3486
2053053e0882
compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents:
3484
diff
changeset
|
225 other_ref_type=org_ref[0], other_ref=org_ref[1], |
2053053e0882
compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents:
3484
diff
changeset
|
226 merge=merge or '') |
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
|
227 |
3380
01fe360a66c0
fixed pull-requests with cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3357
diff
changeset
|
228 org_repo = Repository.get_by_repo_name(org_repo) |
01fe360a66c0
fixed pull-requests with cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3357
diff
changeset
|
229 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
|
230 |
3380
01fe360a66c0
fixed pull-requests with cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3357
diff
changeset
|
231 if org_repo is None: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
232 msg = 'Could not find org repo %s' % org_repo |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
233 log.error(msg) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
234 h.flash(msg, category='error') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
235 return redirect(url('compare_home', repo_name=c.repo_name)) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
236 |
3380
01fe360a66c0
fixed pull-requests with cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3357
diff
changeset
|
237 if other_repo is None: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
238 msg = 'Could not find other repo %s' % other_repo |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
239 log.error(msg) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
240 h.flash(msg, category='error') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
241 return redirect(url('compare_home', repo_name=c.repo_name)) |
3010
bf96fd1920c1
Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents:
2995
diff
changeset
|
242 |
3380
01fe360a66c0
fixed pull-requests with cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3357
diff
changeset
|
243 if org_repo.scm_instance.alias != other_repo.scm_instance.alias: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
244 msg = 'compare of two different kind of remote repos not available' |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
245 log.error(msg) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
246 h.flash(msg, category='error') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
247 return redirect(url('compare_home', repo_name=c.repo_name)) |
3010
bf96fd1920c1
Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents:
2995
diff
changeset
|
248 |
4039
b44fabc4377c
compare: resolve revisions in the right repository for diffs between repos
Mads Kiilerich <madski@unity3d.com>
parents:
4038
diff
changeset
|
249 org_rev = self.__get_rev_or_redirect(ref=org_ref, repo=org_repo, partial=partial) |
b44fabc4377c
compare: resolve revisions in the right repository for diffs between repos
Mads Kiilerich <madski@unity3d.com>
parents:
4038
diff
changeset
|
250 other_rev = self.__get_rev_or_redirect(ref=other_ref, repo=other_repo, partial=partial) |
3615
50927aedcab5
move the existing changeset checks bellow other checks else it can throw exceptions for non
Marcin Kuzminski <marcin@python-works.com>
parents:
3486
diff
changeset
|
251 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
252 c.compare_home = False |
3380
01fe360a66c0
fixed pull-requests with cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3357
diff
changeset
|
253 c.org_repo = org_repo |
01fe360a66c0
fixed pull-requests with cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3357
diff
changeset
|
254 c.other_repo = other_repo |
01fe360a66c0
fixed pull-requests with cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3357
diff
changeset
|
255 c.org_ref = org_ref[1] |
01fe360a66c0
fixed pull-requests with cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3357
diff
changeset
|
256 c.other_ref = other_ref[1] |
01fe360a66c0
fixed pull-requests with cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3357
diff
changeset
|
257 c.org_ref_type = org_ref[0] |
01fe360a66c0
fixed pull-requests with cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3357
diff
changeset
|
258 c.other_ref_type = other_ref[0] |
2593
16a6a2f5d422
Add check for existing revisions in compare view
Marcin Kuzminski <marcin@python-works.com>
parents:
2487
diff
changeset
|
259 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
260 c.cs_ranges, c.ancestor = self._get_changesets( |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
261 org_repo.scm_instance.alias, org_repo.scm_instance, org_rev, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
262 other_repo.scm_instance, other_rev, merge) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
263 c.statuses = c.rhodecode_db_repo.statuses( |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
264 [x.raw_id for x in c.cs_ranges]) |
2337
f8c953c6b040
Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
2245
diff
changeset
|
265 |
4037
48142e84bdc8
compare: only warn about missing ancestor if a 'merge' diff was requested
Mads Kiilerich <madski@unity3d.com>
parents:
3976
diff
changeset
|
266 if merge and not c.ancestor: |
48142e84bdc8
compare: only warn about missing ancestor if a 'merge' diff was requested
Mads Kiilerich <madski@unity3d.com>
parents:
3976
diff
changeset
|
267 log.error('Unable to find ancestor revision') |
3771
d23f2bea2346
removed assertion about ancestor revision.
Marcin Kuzminski <marcin@python-works.com>
parents:
3749
diff
changeset
|
268 |
2847
1cd0a0c05f42
swap the select values with revisions dynamically when switching the repos on pull request view
Marcin Kuzminski <marcin@python-works.com>
parents:
2684
diff
changeset
|
269 if partial: |
2395
b262e349a7a5
created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents:
2393
diff
changeset
|
270 return render('compare/compare_cs.html') |
3486
2053053e0882
compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents:
3484
diff
changeset
|
271 if c.ancestor: |
2053053e0882
compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents:
3484
diff
changeset
|
272 assert merge |
3323
a07296564f6b
compare: show aggregated diff of what will be merged to other repo, using merge ancestor
Mads Kiilerich <madski@unity3d.com>
parents:
3322
diff
changeset
|
273 # case we want a simple diff without incoming changesets, |
a07296564f6b
compare: show aggregated diff of what will be merged to other repo, using merge ancestor
Mads Kiilerich <madski@unity3d.com>
parents:
3322
diff
changeset
|
274 # previewing what will be merged. |
3486
2053053e0882
compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents:
3484
diff
changeset
|
275 # Make the diff on the other repo (which is known to have other_ref) |
3380
01fe360a66c0
fixed pull-requests with cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3357
diff
changeset
|
276 log.debug('Using ancestor %s as org_ref instead of %s' |
3486
2053053e0882
compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents:
3484
diff
changeset
|
277 % (c.ancestor, org_ref)) |
4039
b44fabc4377c
compare: resolve revisions in the right repository for diffs between repos
Mads Kiilerich <madski@unity3d.com>
parents:
4038
diff
changeset
|
278 org_rev = c.ancestor |
3322
c9b0f1d363c7
compare: swap org and other when they refer to different repos, ie are pull request style
Mads Kiilerich <madski@unity3d.com>
parents:
3320
diff
changeset
|
279 org_repo = other_repo |
2892
5fba3778431c
#590 Add GET flag that controls the way the diff are generated, for pull requests we want to use non-bundle based diffs,
Marcin Kuzminski <marcin@python-works.com>
parents:
2847
diff
changeset
|
280 |
3443
3ac76dfdab8e
compare: minor refactoring and comments
Mads Kiilerich <madski@unity3d.com>
parents:
3442
diff
changeset
|
281 diff_limit = self.cut_off_limit if not c.fulldiff else None |
3023
c2a206162062
Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3015
diff
changeset
|
282 |
3812
4324d6899e55
diff: cleanup of variables and logging in compare and pullrequests
Mads Kiilerich <madski@unity3d.com>
parents:
3811
diff
changeset
|
283 log.debug('running diff between %s and %s in %s' |
4039
b44fabc4377c
compare: resolve revisions in the right repository for diffs between repos
Mads Kiilerich <madski@unity3d.com>
parents:
4038
diff
changeset
|
284 % (org_rev, other_rev, org_repo.scm_instance.path)) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
285 |
4039
b44fabc4377c
compare: resolve revisions in the right repository for diffs between repos
Mads Kiilerich <madski@unity3d.com>
parents:
4038
diff
changeset
|
286 txtdiff = org_repo.scm_instance.get_diff(rev1=org_rev, rev2=other_rev) |
3812
4324d6899e55
diff: cleanup of variables and logging in compare and pullrequests
Mads Kiilerich <madski@unity3d.com>
parents:
3811
diff
changeset
|
287 diff_processor = diffs.DiffProcessor(txtdiff or '', format='gitdiff', |
3011
25d77aef2729
Optimized look of compare view of changesets.
Marcin Kuzminski <marcin@python-works.com>
parents:
3010
diff
changeset
|
288 diff_limit=diff_limit) |
2348
a07e04ef7bb4
Implemented basic compare view(for pull requests) for mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
2337
diff
changeset
|
289 _parsed = diff_processor.prepare() |
2337
f8c953c6b040
Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
2245
diff
changeset
|
290 |
3011
25d77aef2729
Optimized look of compare view of changesets.
Marcin Kuzminski <marcin@python-works.com>
parents:
3010
diff
changeset
|
291 c.limited_diff = False |
25d77aef2729
Optimized look of compare view of changesets.
Marcin Kuzminski <marcin@python-works.com>
parents:
3010
diff
changeset
|
292 if isinstance(_parsed, LimitedDiffContainer): |
25d77aef2729
Optimized look of compare view of changesets.
Marcin Kuzminski <marcin@python-works.com>
parents:
3010
diff
changeset
|
293 c.limited_diff = True |
25d77aef2729
Optimized look of compare view of changesets.
Marcin Kuzminski <marcin@python-works.com>
parents:
3010
diff
changeset
|
294 |
2348
a07e04ef7bb4
Implemented basic compare view(for pull requests) for mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
2337
diff
changeset
|
295 c.files = [] |
a07e04ef7bb4
Implemented basic compare view(for pull requests) for mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
2337
diff
changeset
|
296 c.changes = {} |
3015
16af24982e30
Multiple changes for compare system
Marcin Kuzminski <marcin@python-works.com>
parents:
3011
diff
changeset
|
297 c.lines_added = 0 |
16af24982e30
Multiple changes for compare system
Marcin Kuzminski <marcin@python-works.com>
parents:
3011
diff
changeset
|
298 c.lines_deleted = 0 |
2393
b94eac50ec4d
added changeset review status into repo/branch compare view
Marcin Kuzminski <marcin@python-works.com>
parents:
2363
diff
changeset
|
299 for f in _parsed: |
3015
16af24982e30
Multiple changes for compare system
Marcin Kuzminski <marcin@python-works.com>
parents:
3011
diff
changeset
|
300 st = f['stats'] |
3821
ce4b7023a492
diff parser: redefined operations stats for changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3812
diff
changeset
|
301 if not st['binary']: |
ce4b7023a492
diff parser: redefined operations stats for changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3812
diff
changeset
|
302 c.lines_added += st['added'] |
ce4b7023a492
diff parser: redefined operations stats for changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3812
diff
changeset
|
303 c.lines_deleted += st['deleted'] |
2348
a07e04ef7bb4
Implemented basic compare view(for pull requests) for mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
2337
diff
changeset
|
304 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
|
305 c.files.append([fid, f['operation'], f['filename'], f['stats']]) |
3812
4324d6899e55
diff: cleanup of variables and logging in compare and pullrequests
Mads Kiilerich <madski@unity3d.com>
parents:
3811
diff
changeset
|
306 htmldiff = diff_processor.as_html(enable_comments=False, parsed_lines=[f]) |
4324d6899e55
diff: cleanup of variables and logging in compare and pullrequests
Mads Kiilerich <madski@unity3d.com>
parents:
3811
diff
changeset
|
307 c.changes[fid] = [f['operation'], f['filename'], htmldiff] |
2337
f8c953c6b040
Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
2245
diff
changeset
|
308 |
f8c953c6b040
Created base for diffing two repositories inside rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
2245
diff
changeset
|
309 return render('compare/compare_diff.html') |