comparison rhodecode/model/pull_request.py @ 3486:2053053e0882 beta

compare/pullrequest: introduce merge parameter This is more correct and flexible than the old way of looking on same/different repo.
author Mads Kiilerich <madski@unity3d.com>
date Tue, 05 Mar 2013 11:55:01 +0100
parents 3ac76dfdab8e
children 5dcfa6304f88
comparison
equal deleted inserted replaced
3485:b19b1723ff10 3486:2053053e0882
159 pull_request = self.__get_pull_request(pull_request) 159 pull_request = self.__get_pull_request(pull_request)
160 pull_request.status = PullRequest.STATUS_CLOSED 160 pull_request.status = PullRequest.STATUS_CLOSED
161 pull_request.updated_on = datetime.datetime.now() 161 pull_request.updated_on = datetime.datetime.now()
162 Session().add(pull_request) 162 Session().add(pull_request)
163 163
164 def _get_changesets(self, alias, org_repo, org_ref, other_repo, other_ref): 164 def _get_changesets(self, alias, org_repo, org_ref, other_repo, other_ref, merge):
165 """ 165 """
166 Returns a list of changesets that can be merged from org_repo@org_ref 166 Returns a list of changesets that can be merged from org_repo@org_ref
167 to other_repo@other_ref ... and the ancestor that would be used for merge 167 to other_repo@other_ref ... and the ancestor that would be used for merge
168 168
169 :param org_repo: 169 :param org_repo:
209 209
210 #no remote compare do it on the same repository 210 #no remote compare do it on the same repository
211 else: 211 else:
212 hgrepo = other_repo._repo 212 hgrepo = other_repo._repo
213 213
214 revs = ["ancestors(id('%s')) and not ancestors(id('%s'))" % 214 if merge:
215 (other_rev, org_rev)] 215 revs = ["ancestors(id('%s')) and not ancestors(id('%s')) and not id('%s')" %
216 changesets = [other_repo.get_changeset(cs) 216 (other_rev, org_rev, org_rev)]
217 for cs in scmutil.revrange(hgrepo, revs)] 217
218
219 if org_repo != other_repo:
220 ancestors = scmutil.revrange(hgrepo, 218 ancestors = scmutil.revrange(hgrepo,
221 ["ancestor(id('%s'), id('%s'))" % (org_rev, other_rev)]) 219 ["ancestor(id('%s'), id('%s'))" % (org_rev, other_rev)])
222 if len(ancestors) == 1: 220 if len(ancestors) == 1:
223 ancestor = hgrepo[ancestors[0]].hex() 221 ancestor = hgrepo[ancestors[0]].hex()
222 else:
223 # TODO: have both + and - changesets
224 revs = ["id('%s') :: id('%s') - id('%s')" %
225 (org_rev, other_rev, org_rev)]
226
227 changesets = [other_repo.get_changeset(cs)
228 for cs in scmutil.revrange(hgrepo, revs)]
224 229
225 elif alias == 'git': 230 elif alias == 'git':
226 assert org_repo == other_repo, (org_repo, other_repo) # no git support for different repos 231 assert org_repo == other_repo, (org_repo, other_repo) # no git support for different repos
227 so, se = org_repo.run_git_command( 232 so, se = org_repo.run_git_command(
228 'log --reverse --pretty="format: %%H" -s -p %s..%s' % (org_ref[1], 233 'log --reverse --pretty="format: %%H" -s -p %s..%s' % (org_ref[1],
231 changesets = [org_repo.get_changeset(cs) 236 changesets = [org_repo.get_changeset(cs)
232 for cs in re.findall(r'[0-9a-fA-F]{40}', so)] 237 for cs in re.findall(r'[0-9a-fA-F]{40}', so)]
233 238
234 return changesets, ancestor 239 return changesets, ancestor
235 240
236 def get_compare_data(self, org_repo, org_ref, other_repo, other_ref): 241 def get_compare_data(self, org_repo, org_ref, other_repo, other_ref, merge):
237 """ 242 """
238 Returns incoming changesets for mercurial repositories 243 Returns incoming changesets for mercurial repositories
239 244
240 :param org_repo: 245 :param org_repo:
241 :param org_ref: 246 :param org_ref:
249 if len(other_ref) != 2 or not isinstance(org_ref, (list, tuple)): 254 if len(other_ref) != 2 or not isinstance(org_ref, (list, tuple)):
250 raise Exception('other_ref must be a two element list/tuple') 255 raise Exception('other_ref must be a two element list/tuple')
251 256
252 cs_ranges, ancestor = self._get_changesets(org_repo.scm_instance.alias, 257 cs_ranges, ancestor = self._get_changesets(org_repo.scm_instance.alias,
253 org_repo.scm_instance, org_ref, 258 org_repo.scm_instance, org_ref,
254 other_repo.scm_instance, other_ref) 259 other_repo.scm_instance, other_ref,
260 merge)
255 return cs_ranges, ancestor 261 return cs_ranges, ancestor