##// END OF EJS Templates
compare: move get_changesets to compare controller where it is used - 2nd half that was lost in 6c79bfcd3b54...
Mads Kiilerich -
r3754:8beaaea7 beta
parent child Browse files
Show More
@@ -25,20 +25,17 b''
25 25
26 26 import logging
27 27 import datetime
28 import re
29 28
30 29 from pylons.i18n.translation import _
31 30
32 31 from rhodecode.model.meta import Session
33 from rhodecode.lib import helpers as h, unionrepo
32 from rhodecode.lib import helpers as h
34 33 from rhodecode.model import BaseModel
35 34 from rhodecode.model.db import PullRequest, PullRequestReviewers, Notification,\
36 35 ChangesetStatus
37 36 from rhodecode.model.notification import NotificationModel
38 37 from rhodecode.lib.utils2 import safe_unicode
39 38
40 from rhodecode.lib.vcs.utils.hgcompat import scmutil
41 from rhodecode.lib.vcs.utils import safe_str
42 39
43 40 log = logging.getLogger(__name__)
44 41
@@ -159,98 +156,3 b' class PullRequestModel(BaseModel):'
159 156 pull_request.status = PullRequest.STATUS_CLOSED
160 157 pull_request.updated_on = datetime.datetime.now()
161 158 Session().add(pull_request)
162
163 def _get_changesets(self, alias, org_repo, org_ref, other_repo, other_ref, merge):
164 """
165 Returns a list of changesets that can be merged from org_repo@org_ref
166 to other_repo@other_ref ... and the ancestor that would be used for merge
167
168 :param org_repo:
169 :param org_ref:
170 :param other_repo:
171 :param other_ref:
172 :param tmp:
173 """
174
175 ancestor = None
176
177 if alias == 'hg':
178 # lookup up the exact node id
179 _revset_predicates = {
180 'branch': 'branch',
181 'book': 'bookmark',
182 'tag': 'tag',
183 'rev': 'id',
184 }
185
186 org_rev_spec = "max(%s('%s'))" % (_revset_predicates[org_ref[0]],
187 safe_str(org_ref[1]))
188 org_revs = scmutil.revrange(org_repo._repo, [org_rev_spec])
189 org_rev = org_repo._repo[org_revs[-1] if org_revs else -1].hex()
190
191 other_rev_spec = "max(%s('%s'))" % (_revset_predicates[other_ref[0]],
192 safe_str(other_ref[1]))
193 other_revs = scmutil.revrange(other_repo._repo, [other_rev_spec])
194 other_rev = other_repo._repo[other_revs[-1] if other_revs else -1].hex()
195
196 #case two independent repos
197 if org_repo != other_repo:
198 hgrepo = unionrepo.unionrepository(other_repo.baseui,
199 other_repo.path,
200 org_repo.path)
201 # all the changesets we are looking for will be in other_repo,
202 # so rev numbers from hgrepo can be used in other_repo
203
204 #no remote compare do it on the same repository
205 else:
206 hgrepo = other_repo._repo
207
208 if merge:
209 revs = ["ancestors(id('%s')) and not ancestors(id('%s')) and not id('%s')" %
210 (other_rev, org_rev, org_rev)]
211
212 ancestors = scmutil.revrange(hgrepo,
213 ["ancestor(id('%s'), id('%s'))" % (org_rev, other_rev)])
214 if ancestors:
215 # pick arbitrary ancestor - but there is usually only one
216 ancestor = hgrepo[ancestors[0]].hex()
217 else:
218 # TODO: have both + and - changesets
219 revs = ["id('%s') :: id('%s') - id('%s')" %
220 (org_rev, other_rev, org_rev)]
221
222 changesets = [other_repo.get_changeset(cs)
223 for cs in scmutil.revrange(hgrepo, revs)]
224
225 elif alias == 'git':
226 assert org_repo == other_repo, (org_repo, other_repo) # no git support for different repos
227 so, se = org_repo.run_git_command(
228 'log --reverse --pretty="format: %%H" -s -p %s..%s' % (org_ref[1],
229 other_ref[1])
230 )
231 changesets = [org_repo.get_changeset(cs)
232 for cs in re.findall(r'[0-9a-fA-F]{40}', so)]
233
234 return changesets, ancestor
235
236 def get_compare_data(self, org_repo, org_ref, other_repo, other_ref, merge):
237 """
238 Returns incoming changesets for mercurial repositories
239
240 :param org_repo:
241 :param org_ref:
242 :param other_repo:
243 :param other_ref:
244 """
245
246 if len(org_ref) != 2 or not isinstance(org_ref, (list, tuple)):
247 raise Exception('org_ref must be a two element list/tuple')
248
249 if len(other_ref) != 2 or not isinstance(org_ref, (list, tuple)):
250 raise Exception('other_ref must be a two element list/tuple')
251
252 cs_ranges, ancestor = self._get_changesets(org_repo.scm_instance.alias,
253 org_repo.scm_instance, org_ref,
254 other_repo.scm_instance, other_ref,
255 merge)
256 return cs_ranges, ancestor
General Comments 0
You need to be logged in to leave comments. Login now