annotate rhodecode/model/pull_request.py @ 2684:2b6939a77052 beta

Bumped mercurial version to 2.3 - fixed issues with compare of two remote repos at particular revisions - added tests for cases when mercurial update broke code and tests didn't catch this - removed obsolete EmptyChangeset from the rhodecode code
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 04 Aug 2012 01:20:38 +0200
parents f79320e47e99
children 49a4864b11c1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 """
2608
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2597
diff changeset
3 rhodecode.model.pull_request
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2597
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 pull request model for RhodeCode
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 :created_on: Jun 6, 2012
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 :author: marcink
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 :copyright: (C) 2012-2012 Marcin Kuzminski <marcin@python-works.com>
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 :license: GPLv3, see COPYING for more details.
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 """
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13 # This program is free software: you can redistribute it and/or modify
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14 # it under the terms of the GNU General Public License as published by
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15 # the Free Software Foundation, either version 3 of the License, or
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16 # (at your option) any later version.
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 #
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 # This program is distributed in the hope that it will be useful,
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 # GNU General Public License for more details.
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 #
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 # You should have received a copy of the GNU General Public License
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 import logging
2442
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
27 import binascii
2608
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2597
diff changeset
28 import datetime
2597
7b092b919f4f Switch to waitress wsgi server by default in rhodecode.
Marcin Kuzminski <marcin@python-works.com>
parents: 2584
diff changeset
29
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 from pylons.i18n.translation import _
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31
2597
7b092b919f4f Switch to waitress wsgi server by default in rhodecode.
Marcin Kuzminski <marcin@python-works.com>
parents: 2584
diff changeset
32 from rhodecode.model.meta import Session
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 from rhodecode.lib import helpers as h
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 from rhodecode.model import BaseModel
2597
7b092b919f4f Switch to waitress wsgi server by default in rhodecode.
Marcin Kuzminski <marcin@python-works.com>
parents: 2584
diff changeset
35 from rhodecode.model.db import PullRequest, PullRequestReviewers, Notification
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 from rhodecode.model.notification import NotificationModel
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 from rhodecode.lib.utils2 import safe_unicode
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38
2684
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2630
diff changeset
39 from rhodecode.lib.vcs.utils.hgcompat import discovery, localrepo, scmutil
2442
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
40
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41 log = logging.getLogger(__name__)
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44 class PullRequestModel(BaseModel):
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45
2522
17893d61792a Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
46 cls = PullRequest
17893d61792a Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
47
2608
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2597
diff changeset
48 def __get_pull_request(self, pull_request):
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2597
diff changeset
49 return self._get_instance(PullRequest, pull_request)
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2597
diff changeset
50
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
51 def get_all(self, repo):
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
52 repo = self._get_repo(repo)
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
53 return PullRequest.query().filter(PullRequest.other_repo == repo).all()
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
54
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55 def create(self, created_by, org_repo, org_ref, other_repo,
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 other_ref, revisions, reviewers, title, description=None):
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
57
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
58 created_by_user = self._get_user(created_by)
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
59 org_repo = self._get_repo(org_repo)
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
60 other_repo = self._get_repo(other_repo)
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 new = PullRequest()
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
63 new.org_repo = org_repo
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64 new.org_ref = org_ref
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
65 new.other_repo = other_repo
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66 new.other_ref = other_ref
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67 new.revisions = revisions
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68 new.title = title
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69 new.description = description
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
70 new.author = created_by_user
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71 self.sa.add(new)
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
72 Session().flush()
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73 #members
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74 for member in reviewers:
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 _usr = self._get_user(member)
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 reviewer = PullRequestReviewers(_usr, new)
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
77 self.sa.add(reviewer)
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79 #notification to reviewers
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80 notif = NotificationModel()
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
81
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
82 subject = safe_unicode(
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
83 h.link_to(
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
84 _('%(user)s wants you to review pull request #%(pr_id)s') % \
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
85 {'user': created_by_user.username,
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
86 'pr_id': new.pull_request_id},
2584
c1cac08d7062 fix url in notification inbox for opened pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2541
diff changeset
87 h.url('pullrequest_show', repo_name=other_repo.repo_name,
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88 pull_request_id=new.pull_request_id,
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89 qualified=True,
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
90 )
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91 )
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92 )
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
93 body = description
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2522
diff changeset
94 notif.create(created_by=created_by_user, subject=subject, body=body,
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95 recipients=reviewers,
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 type_=Notification.TYPE_PULL_REQUEST,)
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98 return new
2442
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
99
2614
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
100 def update_reviewers(self, pull_request, reviewers_ids):
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
101 reviewers_ids = set(reviewers_ids)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
102 pull_request = self.__get_pull_request(pull_request)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
103 current_reviewers = PullRequestReviewers.query()\
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
104 .filter(PullRequestReviewers.pull_request==
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
105 pull_request)\
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
106 .all()
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
107 current_reviewers_ids = set([x.user.user_id for x in current_reviewers])
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
108
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
109 to_add = reviewers_ids.difference(current_reviewers_ids)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
110 to_remove = current_reviewers_ids.difference(reviewers_ids)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
111
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
112 log.debug("Adding %s reviewers" % to_add)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
113 log.debug("Removing %s reviewers" % to_remove)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
114
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
115 for uid in to_add:
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
116 _usr = self._get_user(uid)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
117 reviewer = PullRequestReviewers(_usr, pull_request)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
118 self.sa.add(reviewer)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
119
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
120 for uid in to_remove:
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
121 reviewer = PullRequestReviewers.query()\
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
122 .filter(PullRequestReviewers.user_id==uid,
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
123 PullRequestReviewers.pull_request==pull_request)\
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
124 .scalar()
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
125 if reviewer:
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
126 self.sa.delete(reviewer)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
127
2608
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2597
diff changeset
128 def close_pull_request(self, pull_request):
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2597
diff changeset
129 pull_request = self.__get_pull_request(pull_request)
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2597
diff changeset
130 pull_request.status = PullRequest.STATUS_CLOSED
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2597
diff changeset
131 pull_request.updated_on = datetime.datetime.now()
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2597
diff changeset
132 self.sa.add(pull_request)
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2597
diff changeset
133
2442
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
134 def _get_changesets(self, org_repo, org_ref, other_repo, other_ref,
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
135 discovery_data):
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
136 """
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
137 Returns a list of changesets that are incoming from org_repo@org_ref
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
138 to other_repo@other_ref
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
139
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
140 :param org_repo:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
141 :type org_repo:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
142 :param org_ref:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
143 :type org_ref:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
144 :param other_repo:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
145 :type other_repo:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
146 :param other_ref:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
147 :type other_ref:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
148 :param tmp:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
149 :type tmp:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
150 """
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
151 changesets = []
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
152 #case two independent repos
2684
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2630
diff changeset
153 common, incoming, rheads = discovery_data
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2630
diff changeset
154 if org_repo != other_repo and incoming:
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2630
diff changeset
155 revs = org_repo._repo.changelog.findmissing(common, rheads)
2442
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
156
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
157 for cs in reversed(map(binascii.hexlify, revs)):
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
158 changesets.append(org_repo.get_changeset(cs))
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
159 else:
2630
f79320e47e99 Merged pull request #56
Marcin Kuzminski <marcin@python-works.com>
parents: 2614
diff changeset
160 _revset_predicates = {
f79320e47e99 Merged pull request #56
Marcin Kuzminski <marcin@python-works.com>
parents: 2614
diff changeset
161 'branch': 'branch',
f79320e47e99 Merged pull request #56
Marcin Kuzminski <marcin@python-works.com>
parents: 2614
diff changeset
162 'book': 'bookmark',
f79320e47e99 Merged pull request #56
Marcin Kuzminski <marcin@python-works.com>
parents: 2614
diff changeset
163 'tag': 'tag',
f79320e47e99 Merged pull request #56
Marcin Kuzminski <marcin@python-works.com>
parents: 2614
diff changeset
164 'rev': 'id',
f79320e47e99 Merged pull request #56
Marcin Kuzminski <marcin@python-works.com>
parents: 2614
diff changeset
165 }
f79320e47e99 Merged pull request #56
Marcin Kuzminski <marcin@python-works.com>
parents: 2614
diff changeset
166
f79320e47e99 Merged pull request #56
Marcin Kuzminski <marcin@python-works.com>
parents: 2614
diff changeset
167 revs = [
f79320e47e99 Merged pull request #56
Marcin Kuzminski <marcin@python-works.com>
parents: 2614
diff changeset
168 "ancestors(%s('%s')) and not ancestors(%s('%s'))" % (
f79320e47e99 Merged pull request #56
Marcin Kuzminski <marcin@python-works.com>
parents: 2614
diff changeset
169 _revset_predicates[org_ref[0]], org_ref[1],
f79320e47e99 Merged pull request #56
Marcin Kuzminski <marcin@python-works.com>
parents: 2614
diff changeset
170 _revset_predicates[other_ref[0]], other_ref[1]
f79320e47e99 Merged pull request #56
Marcin Kuzminski <marcin@python-works.com>
parents: 2614
diff changeset
171 )
f79320e47e99 Merged pull request #56
Marcin Kuzminski <marcin@python-works.com>
parents: 2614
diff changeset
172 ]
f79320e47e99 Merged pull request #56
Marcin Kuzminski <marcin@python-works.com>
parents: 2614
diff changeset
173
2442
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
174 out = scmutil.revrange(org_repo._repo, revs)
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
175 for cs in reversed(out):
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
176 changesets.append(org_repo.get_changeset(cs))
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
177
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
178 return changesets
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
179
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
180 def _get_discovery(self, org_repo, org_ref, other_repo, other_ref):
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
181 """
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
182 Get's mercurial discovery data used to calculate difference between
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
183 repos and refs
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
184
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
185 :param org_repo:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
186 :type org_repo:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
187 :param org_ref:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
188 :type org_ref:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
189 :param other_repo:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
190 :type other_repo:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
191 :param other_ref:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
192 :type other_ref:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
193 """
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
194
2684
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2630
diff changeset
195 _org_repo = org_repo._repo
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2630
diff changeset
196 org_rev_type, org_rev = org_ref
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2630
diff changeset
197
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2630
diff changeset
198 _other_repo = other_repo._repo
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2630
diff changeset
199 other_rev_type, other_rev = other_ref
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2630
diff changeset
200
2442
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
201 log.debug('Doing discovery for %s@%s vs %s@%s' % (
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
202 org_repo, org_ref, other_repo, other_ref)
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
203 )
2684
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2630
diff changeset
204 #log.debug('Filter heads are %s[%s]' % ('', org_ref[1]))
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2630
diff changeset
205 org_peer = localrepo.locallegacypeer(_org_repo.local())
2442
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
206 tmp = discovery.findcommonincoming(
2684
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2630
diff changeset
207 repo=_other_repo, # other_repo we check for incoming
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2630
diff changeset
208 remote=org_peer, # org_repo source for incoming
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2630
diff changeset
209 heads=[_other_repo[other_rev].node(),
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2630
diff changeset
210 _org_repo[org_rev].node()],
2442
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
211 force=False
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
212 )
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
213 return tmp
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
214
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
215 def get_compare_data(self, org_repo, org_ref, other_repo, other_ref):
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
216 """
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
217 Returns a tuple of incomming changesets, and discoverydata cache
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
218
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
219 :param org_repo:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
220 :type org_repo:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
221 :param org_ref:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
222 :type org_ref:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
223 :param other_repo:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
224 :type other_repo:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
225 :param other_ref:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
226 :type other_ref:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
227 """
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
228
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
229 if len(org_ref) != 2 or not isinstance(org_ref, (list, tuple)):
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
230 raise Exception('org_ref must be a two element list/tuple')
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
231
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
232 if len(other_ref) != 2 or not isinstance(org_ref, (list, tuple)):
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
233 raise Exception('other_ref must be a two element list/tuple')
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
234
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
235 discovery_data = self._get_discovery(org_repo.scm_instance,
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
236 org_ref,
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
237 other_repo.scm_instance,
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
238 other_ref)
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
239 cs_ranges = self._get_changesets(org_repo.scm_instance,
2684
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2630
diff changeset
240 org_ref,
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2630
diff changeset
241 other_repo.scm_instance,
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2630
diff changeset
242 other_ref,
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2630
diff changeset
243 discovery_data)
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2630
diff changeset
244
2442
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
245 return cs_ranges, discovery_data