Show More
@@ -25,7 +25,6 b'' | |||||
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 | import logging |
|
26 | import logging | |
27 | import traceback |
|
27 | import traceback | |
28 | import binascii |
|
|||
29 |
|
28 | |||
30 | from webob.exc import HTTPNotFound |
|
29 | from webob.exc import HTTPNotFound | |
31 | from pylons import request, response, session, tmpl_context as c, url |
|
30 | from pylons import request, response, session, tmpl_context as c, url | |
@@ -37,6 +36,7 b' from rhodecode.lib.auth import LoginRequ' | |||||
37 | from rhodecode.lib import diffs |
|
36 | from rhodecode.lib import diffs | |
38 |
|
37 | |||
39 | from rhodecode.model.db import Repository |
|
38 | from rhodecode.model.db import Repository | |
|
39 | from rhodecode.model.pull_request import PullRequestModel | |||
40 |
|
40 | |||
41 | log = logging.getLogger(__name__) |
|
41 | log = logging.getLogger(__name__) | |
42 |
|
42 | |||
@@ -49,46 +49,6 b' class CompareController(BaseRepoControll' | |||||
49 | def __before__(self): |
|
49 | def __before__(self): | |
50 | super(CompareController, self).__before__() |
|
50 | super(CompareController, self).__before__() | |
51 |
|
51 | |||
52 | def _get_discovery(self, org_repo, org_ref, other_repo, other_ref): |
|
|||
53 | from mercurial import discovery |
|
|||
54 | other = org_repo._repo |
|
|||
55 | repo = other_repo._repo |
|
|||
56 | tip = other[org_ref[1]] |
|
|||
57 | log.debug('Doing discovery for %s@%s vs %s@%s' % ( |
|
|||
58 | org_repo, org_ref, other_repo, other_ref) |
|
|||
59 | ) |
|
|||
60 | log.debug('Filter heads are %s[%s]' % (tip, org_ref[1])) |
|
|||
61 | tmp = discovery.findcommonincoming( |
|
|||
62 | repo=repo, # other_repo we check for incoming |
|
|||
63 | remote=other, # org_repo source for incoming |
|
|||
64 | heads=[tip.node()], |
|
|||
65 | force=False |
|
|||
66 | ) |
|
|||
67 | return tmp |
|
|||
68 |
|
||||
69 | def _get_changesets(self, org_repo, org_ref, other_repo, other_ref, tmp): |
|
|||
70 | changesets = [] |
|
|||
71 | #case two independent repos |
|
|||
72 | if org_repo != other_repo: |
|
|||
73 | common, incoming, rheads = tmp |
|
|||
74 |
|
||||
75 | if not incoming: |
|
|||
76 | revs = [] |
|
|||
77 | else: |
|
|||
78 | revs = org_repo._repo.changelog.findmissing(common, rheads) |
|
|||
79 |
|
||||
80 | for cs in reversed(map(binascii.hexlify, revs)): |
|
|||
81 | changesets.append(org_repo.get_changeset(cs)) |
|
|||
82 | else: |
|
|||
83 | revs = ['ancestors(%s) and not ancestors(%s)' % (org_ref[1], |
|
|||
84 | other_ref[1])] |
|
|||
85 | from mercurial import scmutil |
|
|||
86 | out = scmutil.revrange(org_repo._repo, revs) |
|
|||
87 | for cs in reversed(out): |
|
|||
88 | changesets.append(org_repo.get_changeset(cs)) |
|
|||
89 |
|
||||
90 | return changesets |
|
|||
91 |
|
||||
92 | def index(self, org_ref_type, org_ref, other_ref_type, other_ref): |
|
52 | def index(self, org_ref_type, org_ref, other_ref_type, other_ref): | |
93 |
|
53 | |||
94 | org_repo = c.rhodecode_db_repo.repo_name |
|
54 | org_repo = c.rhodecode_db_repo.repo_name | |
@@ -108,15 +68,9 b' class CompareController(BaseRepoControll' | |||||
108 | log.error('Could not found repo %s or %s' % (org_repo, other_repo)) |
|
68 | log.error('Could not found repo %s or %s' % (org_repo, other_repo)) | |
109 | raise HTTPNotFound |
|
69 | raise HTTPNotFound | |
110 |
|
70 | |||
111 | discovery_data = self._get_discovery(org_repo.scm_instance, |
|
71 | c.cs_ranges, discovery_data = PullRequestModel().get_compare_data( | |
112 |
|
|
72 | org_repo, org_ref, other_repo, other_ref | |
113 |
|
|
73 | ) | |
114 | other_ref) |
|
|||
115 | c.cs_ranges = self._get_changesets(org_repo.scm_instance, |
|
|||
116 | org_ref, |
|
|||
117 | other_repo.scm_instance, |
|
|||
118 | other_ref, |
|
|||
119 | discovery_data) |
|
|||
120 |
|
74 | |||
121 | c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in |
|
75 | c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in | |
122 | c.cs_ranges]) |
|
76 | c.cs_ranges]) |
@@ -140,47 +140,13 b' class PullrequestsController(BaseRepoCon' | |||||
140 |
|
140 | |||
141 | return redirect(url('changelog_home', repo_name=repo_name)) |
|
141 | return redirect(url('changelog_home', repo_name=repo_name)) | |
142 |
|
142 | |||
143 | def _get_changesets(self, org_repo, org_ref, other_repo, other_ref, tmp): |
|
143 | def _load_compare_data(self, pull_request): | |
144 | changesets = [] |
|
144 | """ | |
145 | #case two independent repos |
|
145 | Load context data needed for generating compare diff | |
146 | if org_repo != other_repo: |
|
|||
147 | common, incoming, rheads = tmp |
|
|||
148 |
|
||||
149 | if not incoming: |
|
|||
150 | revs = [] |
|
|||
151 | else: |
|
|||
152 | revs = org_repo._repo.changelog.findmissing(common, rheads) |
|
|||
153 |
|
||||
154 | for cs in reversed(map(binascii.hexlify, revs)): |
|
|||
155 | changesets.append(org_repo.get_changeset(cs)) |
|
|||
156 | else: |
|
|||
157 | revs = ['ancestors(%s) and not ancestors(%s)' % (org_ref[1], |
|
|||
158 | other_ref[1])] |
|
|||
159 | from mercurial import scmutil |
|
|||
160 | out = scmutil.revrange(org_repo._repo, revs) |
|
|||
161 | for cs in reversed(out): |
|
|||
162 | changesets.append(org_repo.get_changeset(cs)) |
|
|||
163 |
|
|
146 | ||
164 | return changesets |
|
147 | :param pull_request: | |
165 |
|
148 | :type pull_request: | ||
166 | def _get_discovery(self, org_repo, org_ref, other_repo, other_ref): |
|
149 | """ | |
167 | from mercurial import discovery |
|
|||
168 | other = org_repo._repo |
|
|||
169 | repo = other_repo._repo |
|
|||
170 | tip = other[org_ref[1]] |
|
|||
171 | log.debug('Doing discovery for %s@%s vs %s@%s' % ( |
|
|||
172 | org_repo, org_ref, other_repo, other_ref) |
|
|||
173 | ) |
|
|||
174 | log.debug('Filter heads are %s[%s]' % (tip, org_ref[1])) |
|
|||
175 | tmp = discovery.findcommonincoming( |
|
|||
176 | repo=repo, # other_repo we check for incoming |
|
|||
177 | remote=other, # org_repo source for incoming |
|
|||
178 | heads=[tip.node()], |
|
|||
179 | force=False |
|
|||
180 | ) |
|
|||
181 | return tmp |
|
|||
182 |
|
||||
183 | def _compare(self, pull_request): |
|
|||
184 |
|
150 | |||
185 | org_repo = pull_request.org_repo |
|
151 | org_repo = pull_request.org_repo | |
186 | org_ref_type, org_ref_, org_ref = pull_request.org_ref.split(':') |
|
152 | org_ref_type, org_ref_, org_ref = pull_request.org_ref.split(':') | |
@@ -193,22 +159,14 b' class PullrequestsController(BaseRepoCon' | |||||
193 | c.org_repo = org_repo |
|
159 | c.org_repo = org_repo | |
194 | c.other_repo = other_repo |
|
160 | c.other_repo = other_repo | |
195 |
|
161 | |||
196 | discovery_data = self._get_discovery(org_repo.scm_instance, |
|
162 | c.cs_ranges, discovery_data = PullRequestModel().get_compare_data( | |
197 |
|
|
163 | org_repo, org_ref, other_repo, other_ref | |
198 |
|
|
164 | ) | |
199 | other_ref) |
|
|||
200 | c.cs_ranges = self._get_changesets(org_repo.scm_instance, |
|
|||
201 | org_ref, |
|
|||
202 | other_repo.scm_instance, |
|
|||
203 | other_ref, |
|
|||
204 | discovery_data) |
|
|||
205 |
|
165 | |||
206 | c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in |
|
166 | c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in | |
207 | c.cs_ranges]) |
|
167 | c.cs_ranges]) | |
208 | # defines that we need hidden inputs with changesets |
|
168 | # defines that we need hidden inputs with changesets | |
209 | c.as_form = request.GET.get('as_form', False) |
|
169 | c.as_form = request.GET.get('as_form', False) | |
210 | if request.environ.get('HTTP_X_PARTIAL_XHR'): |
|
|||
211 | return render('compare/compare_cs.html') |
|
|||
212 |
|
170 | |||
213 | c.org_ref = org_ref[1] |
|
171 | c.org_ref = org_ref[1] | |
214 | c.other_ref = other_ref[1] |
|
172 | c.other_ref = other_ref[1] | |
@@ -232,8 +190,9 b' class PullrequestsController(BaseRepoCon' | |||||
232 | c.users_array = repo_model.get_users_js() |
|
190 | c.users_array = repo_model.get_users_js() | |
233 | c.users_groups_array = repo_model.get_users_groups_js() |
|
191 | c.users_groups_array = repo_model.get_users_groups_js() | |
234 | c.pull_request = PullRequest.get(pull_request_id) |
|
192 | c.pull_request = PullRequest.get(pull_request_id) | |
235 | ##TODO: need more generic solution |
|
193 | ||
236 | self._compare(c.pull_request) |
|
194 | # load compare data into template context | |
|
195 | self._load_compare_data(c.pull_request) | |||
237 |
|
196 | |||
238 | # inline comments |
|
197 | # inline comments | |
239 | c.inline_cnt = 0 |
|
198 | c.inline_cnt = 0 |
@@ -12,3 +12,4 b' from mercurial.match import match' | |||||
12 | from mercurial.mdiff import diffopts |
|
12 | from mercurial.mdiff import diffopts | |
13 | from mercurial.node import hex |
|
13 | from mercurial.node import hex | |
14 | from mercurial.encoding import tolocal |
|
14 | from mercurial.encoding import tolocal | |
|
15 | from mercurial import discovery No newline at end of file |
@@ -24,6 +24,7 b'' | |||||
24 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
24 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
25 |
|
25 | |||
26 | import logging |
|
26 | import logging | |
|
27 | import binascii | |||
27 | from pylons.i18n.translation import _ |
|
28 | from pylons.i18n.translation import _ | |
28 |
|
29 | |||
29 | from rhodecode.lib import helpers as h |
|
30 | from rhodecode.lib import helpers as h | |
@@ -32,6 +33,8 b' from rhodecode.model.db import PullReque' | |||||
32 | from rhodecode.model.notification import NotificationModel |
|
33 | from rhodecode.model.notification import NotificationModel | |
33 | from rhodecode.lib.utils2 import safe_unicode |
|
34 | from rhodecode.lib.utils2 import safe_unicode | |
34 |
|
35 | |||
|
36 | from rhodecode.lib.vcs.utils.hgcompat import discovery | |||
|
37 | ||||
35 | log = logging.getLogger(__name__) |
|
38 | log = logging.getLogger(__name__) | |
36 |
|
39 | |||
37 |
|
40 | |||
@@ -82,3 +85,103 b' class PullRequestModel(BaseModel):' | |||||
82 | type_=Notification.TYPE_PULL_REQUEST,) |
|
85 | type_=Notification.TYPE_PULL_REQUEST,) | |
83 |
|
86 | |||
84 | return new |
|
87 | return new | |
|
88 | ||||
|
89 | def _get_changesets(self, org_repo, org_ref, other_repo, other_ref, | |||
|
90 | discovery_data): | |||
|
91 | """ | |||
|
92 | Returns a list of changesets that are incoming from org_repo@org_ref | |||
|
93 | to other_repo@other_ref | |||
|
94 | ||||
|
95 | :param org_repo: | |||
|
96 | :type org_repo: | |||
|
97 | :param org_ref: | |||
|
98 | :type org_ref: | |||
|
99 | :param other_repo: | |||
|
100 | :type other_repo: | |||
|
101 | :param other_ref: | |||
|
102 | :type other_ref: | |||
|
103 | :param tmp: | |||
|
104 | :type tmp: | |||
|
105 | """ | |||
|
106 | changesets = [] | |||
|
107 | #case two independent repos | |||
|
108 | if org_repo != other_repo: | |||
|
109 | common, incoming, rheads = discovery_data | |||
|
110 | ||||
|
111 | if not incoming: | |||
|
112 | revs = [] | |||
|
113 | else: | |||
|
114 | revs = org_repo._repo.changelog.findmissing(common, rheads) | |||
|
115 | ||||
|
116 | for cs in reversed(map(binascii.hexlify, revs)): | |||
|
117 | changesets.append(org_repo.get_changeset(cs)) | |||
|
118 | else: | |||
|
119 | revs = ['ancestors(%s) and not ancestors(%s)' % (org_ref[1], | |||
|
120 | other_ref[1])] | |||
|
121 | from mercurial import scmutil | |||
|
122 | out = scmutil.revrange(org_repo._repo, revs) | |||
|
123 | for cs in reversed(out): | |||
|
124 | changesets.append(org_repo.get_changeset(cs)) | |||
|
125 | ||||
|
126 | return changesets | |||
|
127 | ||||
|
128 | def _get_discovery(self, org_repo, org_ref, other_repo, other_ref): | |||
|
129 | """ | |||
|
130 | Get's mercurial discovery data used to calculate difference between | |||
|
131 | repos and refs | |||
|
132 | ||||
|
133 | :param org_repo: | |||
|
134 | :type org_repo: | |||
|
135 | :param org_ref: | |||
|
136 | :type org_ref: | |||
|
137 | :param other_repo: | |||
|
138 | :type other_repo: | |||
|
139 | :param other_ref: | |||
|
140 | :type other_ref: | |||
|
141 | """ | |||
|
142 | ||||
|
143 | other = org_repo._repo | |||
|
144 | repo = other_repo._repo | |||
|
145 | tip = other[org_ref[1]] | |||
|
146 | log.debug('Doing discovery for %s@%s vs %s@%s' % ( | |||
|
147 | org_repo, org_ref, other_repo, other_ref) | |||
|
148 | ) | |||
|
149 | log.debug('Filter heads are %s[%s]' % (tip, org_ref[1])) | |||
|
150 | tmp = discovery.findcommonincoming( | |||
|
151 | repo=repo, # other_repo we check for incoming | |||
|
152 | remote=other, # org_repo source for incoming | |||
|
153 | heads=[tip.node()], | |||
|
154 | force=False | |||
|
155 | ) | |||
|
156 | return tmp | |||
|
157 | ||||
|
158 | def get_compare_data(self, org_repo, org_ref, other_repo, other_ref): | |||
|
159 | """ | |||
|
160 | Returns a tuple of incomming changesets, and discoverydata cache | |||
|
161 | ||||
|
162 | :param org_repo: | |||
|
163 | :type org_repo: | |||
|
164 | :param org_ref: | |||
|
165 | :type org_ref: | |||
|
166 | :param other_repo: | |||
|
167 | :type other_repo: | |||
|
168 | :param other_ref: | |||
|
169 | :type other_ref: | |||
|
170 | """ | |||
|
171 | ||||
|
172 | if len(org_ref) != 2 or not isinstance(org_ref, (list, tuple)): | |||
|
173 | raise Exception('org_ref must be a two element list/tuple') | |||
|
174 | ||||
|
175 | if len(other_ref) != 2 or not isinstance(org_ref, (list, tuple)): | |||
|
176 | raise Exception('other_ref must be a two element list/tuple') | |||
|
177 | ||||
|
178 | discovery_data = self._get_discovery(org_repo.scm_instance, | |||
|
179 | org_ref, | |||
|
180 | other_repo.scm_instance, | |||
|
181 | other_ref) | |||
|
182 | cs_ranges = self._get_changesets(org_repo.scm_instance, | |||
|
183 | org_ref, | |||
|
184 | other_repo.scm_instance, | |||
|
185 | other_ref, | |||
|
186 | discovery_data) | |||
|
187 | return cs_ranges, discovery_data |
General Comments 0
You need to be logged in to leave comments.
Login now