##// END OF EJS Templates
compare/pullrequest: introduce merge parameter...
Mads Kiilerich -
r3486:2053053e beta
parent child Browse files
Show More
@@ -89,6 +89,15 b' class CompareController(BaseRepoControll'
89 # other_ref will be evaluated in other_repo
89 # other_ref will be evaluated in other_repo
90 other_ref = (other_ref_type, other_ref)
90 other_ref = (other_ref_type, other_ref)
91 other_repo = request.GET.get('other_repo', org_repo)
91 other_repo = request.GET.get('other_repo', org_repo)
92 # If merge is True:
93 # Show what org would get if merged with other:
94 # List changesets that are ancestors of other but not of org.
95 # New changesets in org is thus ignored.
96 # Diff will be from common ancestor, and merges of org to other will thus be ignored.
97 # If merge is False:
98 # Make a raw diff from org to other, no matter if related or not.
99 # Changesets in one and not in the other will be ignored
100 merge = bool(request.GET.get('merge'))
92 # fulldiff disables cut_off_limit
101 # fulldiff disables cut_off_limit
93 c.fulldiff = request.GET.get('fulldiff')
102 c.fulldiff = request.GET.get('fulldiff')
94 # partial uses compare_cs.html template directly
103 # partial uses compare_cs.html template directly
@@ -100,7 +109,8 b' class CompareController(BaseRepoControll'
100 repo_name=other_repo,
109 repo_name=other_repo,
101 org_ref_type=other_ref[0], org_ref=other_ref[1],
110 org_ref_type=other_ref[0], org_ref=other_ref[1],
102 other_repo=org_repo,
111 other_repo=org_repo,
103 other_ref_type=org_ref[0], other_ref=org_ref[1])
112 other_ref_type=org_ref[0], other_ref=org_ref[1],
113 merge=merge or '')
104
114
105 org_repo = Repository.get_by_repo_name(org_repo)
115 org_repo = Repository.get_by_repo_name(org_repo)
106 other_repo = Repository.get_by_repo_name(other_repo)
116 other_repo = Repository.get_by_repo_name(other_repo)
@@ -130,22 +140,23 b' class CompareController(BaseRepoControll'
130 c.org_ref_type = org_ref[0]
140 c.org_ref_type = org_ref[0]
131 c.other_ref_type = other_ref[0]
141 c.other_ref_type = other_ref[0]
132
142
133 c.cs_ranges, ancestor = PullRequestModel().get_compare_data(
143 c.cs_ranges, c.ancestor = PullRequestModel().get_compare_data(
134 org_repo, org_ref, other_repo, other_ref)
144 org_repo, org_ref, other_repo, other_ref, merge)
135
145
136 c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in
146 c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in
137 c.cs_ranges])
147 c.cs_ranges])
138 if partial:
148 if partial:
149 assert c.ancestor
139 return render('compare/compare_cs.html')
150 return render('compare/compare_cs.html')
140
151
141 if ancestor and org_repo != other_repo:
152 if c.ancestor:
153 assert merge
142 # case we want a simple diff without incoming changesets,
154 # case we want a simple diff without incoming changesets,
143 # previewing what will be merged.
155 # previewing what will be merged.
144 # Make the diff on the forked repo, with
156 # Make the diff on the other repo (which is known to have other_ref)
145 # revision that is common ancestor
146 log.debug('Using ancestor %s as org_ref instead of %s'
157 log.debug('Using ancestor %s as org_ref instead of %s'
147 % (ancestor, org_ref))
158 % (c.ancestor, org_ref))
148 org_ref = ('rev', ancestor)
159 org_ref = ('rev', c.ancestor)
149 org_repo = other_repo
160 org_repo = other_repo
150
161
151 diff_limit = self.cut_off_limit if not c.fulldiff else None
162 diff_limit = self.cut_off_limit if not c.fulldiff else None
@@ -196,9 +196,9 b' class PullrequestsController(BaseRepoCon'
196 return redirect(url('pullrequest_home', repo_name=repo_name))
196 return redirect(url('pullrequest_home', repo_name=repo_name))
197
197
198 org_repo = _form['org_repo']
198 org_repo = _form['org_repo']
199 org_ref = _form['org_ref']
199 org_ref = 'rev:merge:%s' % _form['merge_rev']
200 other_repo = _form['other_repo']
200 other_repo = _form['other_repo']
201 other_ref = _form['other_ref']
201 other_ref = 'rev:ancestor:%s' % _form['ancestor_rev']
202 revisions = _form['revisions']
202 revisions = _form['revisions']
203 reviewers = _form['review_members']
203 reviewers = _form['review_members']
204
204
@@ -281,10 +281,6 b' class PullrequestsController(BaseRepoCon'
281
281
282 c.cs_ranges = [org_repo.get_changeset(x) for x in pull_request.revisions]
282 c.cs_ranges = [org_repo.get_changeset(x) for x in pull_request.revisions]
283
283
284 other_ref = ('rev', getattr(c.cs_ranges[0].parents[0]
285 if c.cs_ranges[0].parents
286 else EmptyChangeset(), 'raw_id'))
287
288 c.statuses = org_repo.statuses([x.raw_id for x in c.cs_ranges])
284 c.statuses = org_repo.statuses([x.raw_id for x in c.cs_ranges])
289
285
290 c.org_ref = org_ref[1]
286 c.org_ref = org_ref[1]
@@ -385,6 +381,7 b' class PullrequestsController(BaseRepoCon'
385 c.changeset_statuses = ChangesetStatus.STATUSES
381 c.changeset_statuses = ChangesetStatus.STATUSES
386
382
387 c.as_form = False
383 c.as_form = False
384 c.ancestor = None # there is one - but right here we don't know which
388 return render('/pullrequests/pullrequest_show.html')
385 return render('/pullrequests/pullrequest_show.html')
389
386
390 @NotAnonymous()
387 @NotAnonymous()
@@ -395,4 +395,7 b' def PullRequestForm(repo_id):'
395 pullrequest_title = v.UnicodeString(strip=True, required=True, min=3)
395 pullrequest_title = v.UnicodeString(strip=True, required=True, min=3)
396 pullrequest_desc = v.UnicodeString(strip=True, required=False)
396 pullrequest_desc = v.UnicodeString(strip=True, required=False)
397
397
398 ancestor_rev = v.UnicodeString(strip=True, required=True)
399 merge_rev = v.UnicodeString(strip=True, required=True)
400
398 return _PullRequestForm
401 return _PullRequestForm
@@ -161,7 +161,7 b' class PullRequestModel(BaseModel):'
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
@@ -211,16 +211,21 b' class PullRequestModel(BaseModel):'
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)]
218
217
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
@@ -233,7 +238,7 b' class PullRequestModel(BaseModel):'
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
@@ -251,5 +256,6 b' class PullRequestModel(BaseModel):'
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
@@ -37,7 +37,7 b''
37 <a href="#" class="ui-btn small" id="rev_range_clear" style="display:none">${_('Clear selection')}</a>
37 <a href="#" class="ui-btn small" id="rev_range_clear" style="display:none">${_('Clear selection')}</a>
38
38
39 %if c.rhodecode_db_repo.fork:
39 %if c.rhodecode_db_repo.fork:
40 <a id="compare_fork" title="${_('Compare fork with %s' % c.rhodecode_db_repo.fork.repo_name)}" href="${h.url('compare_url',repo_name=c.rhodecode_db_repo.fork.repo_name,org_ref_type='branch',org_ref='default',other_repo=c.repo_name,other_ref_type='branch',other_ref=request.GET.get('branch') or 'default')}" class="ui-btn small">${_('Compare fork with parent')}</a>
40 <a id="compare_fork" title="${_('Compare fork with %s' % c.rhodecode_db_repo.fork.repo_name)}" href="${h.url('compare_url',repo_name=c.rhodecode_db_repo.fork.repo_name,org_ref_type='branch',org_ref='default',other_repo=c.repo_name,other_ref_type='branch',other_ref=request.GET.get('branch') or 'default',merge=1)}" class="ui-btn small">${_('Compare fork with parent')}</a>
41 %endif
41 %endif
42 %if h.is_hg(c.rhodecode_repo):
42 %if h.is_hg(c.rhodecode_repo):
43 <a id="open_new_pr" href="${h.url('pullrequest_home',repo_name=c.repo_name)}" class="ui-btn small">${_('Open new pull request')}</a>
43 <a id="open_new_pr" href="${h.url('pullrequest_home',repo_name=c.repo_name)}" class="ui-btn small">${_('Open new pull request')}</a>
@@ -1,9 +1,9 b''
1 ## Changesets table !
1 ## Changesets table !
2 <div class="container">
2 <div class="container">
3 <table class="compare_view_commits noborder">
4 %if not c.cs_ranges:
3 %if not c.cs_ranges:
5 <span class="empty_data">${_('No changesets')}</span>
4 <span class="empty_data">${_('No changesets')}</span>
6 %else:
5 %else:
6 <table class="compare_view_commits noborder">
7 %for cnt, cs in enumerate(c.cs_ranges):
7 %for cnt, cs in enumerate(c.cs_ranges):
8 <tr>
8 <tr>
9 <td><div class="gravatar"><img alt="gravatar" src="${h.gravatar_url(h.email_or_none(cs.author),14)}"/></div></td>
9 <td><div class="gravatar"><img alt="gravatar" src="${h.gravatar_url(h.email_or_none(cs.author),14)}"/></div></td>
@@ -22,7 +22,15 b''
22 <td><div class="message tooltip" title="${h.tooltip(cs.message)}" style="white-space:normal">${h.urlify_commit(h.shorter(cs.message, 60),c.repo_name)}</div></td>
22 <td><div class="message tooltip" title="${h.tooltip(cs.message)}" style="white-space:normal">${h.urlify_commit(h.shorter(cs.message, 60),c.repo_name)}</div></td>
23 </tr>
23 </tr>
24 %endfor
24 %endfor
25
25 </table>
26 %if c.ancestor:
27 <span class="ancestor">${_('Ancestor')}:
28 ${h.link_to(c.ancestor,h.url('changeset_home',repo_name=c.repo_name,revision=c.ancestor))}
29 </span>
30 %endif
31 %if c.as_form:
32 ${h.hidden('ancestor_rev',c.ancestor)}
33 ${h.hidden('merge_rev',c.cs_ranges[-1].raw_id)}
34 %endif
26 %endif
35 %endif
27 </table>
28 </div>
36 </div>
@@ -133,6 +133,7 b''
133 other_ref_type='__org_ref_type__',
133 other_ref_type='__org_ref_type__',
134 other_ref='__org_ref__',
134 other_ref='__org_ref__',
135 as_form=True,
135 as_form=True,
136 merge=True,
136 )}";
137 )}";
137 var org_repo = YUQ('#pull_request_form #org_repo')[0].value;
138 var org_repo = YUQ('#pull_request_form #org_repo')[0].value;
138 var org_ref = YUQ('#pull_request_form #org_ref')[0].value.split(':');
139 var org_ref = YUQ('#pull_request_form #org_ref')[0].value.split(':');
@@ -106,6 +106,7 b' class TestCompareController(TestControll'
106 other_repo=repo2.repo_name,
106 other_repo=repo2.repo_name,
107 other_ref_type="branch",
107 other_ref_type="branch",
108 other_ref=rev1,
108 other_ref=rev1,
109 merge='1',
109 ))
110 ))
110
111
111 response.mustcontain('%s@%s -&gt; %s@%s' % (repo1.repo_name, rev2, repo2.repo_name, rev1))
112 response.mustcontain('%s@%s -&gt; %s@%s' % (repo1.repo_name, rev2, repo2.repo_name, rev1))
@@ -118,9 +119,9 b' class TestCompareController(TestControll'
118 response.mustcontain("""<a href="/%s/changeset/%s">r1:%s</a>""" % (repo2.repo_name, cs1.raw_id, cs1.short_id))
119 response.mustcontain("""<a href="/%s/changeset/%s">r1:%s</a>""" % (repo2.repo_name, cs1.raw_id, cs1.short_id))
119 response.mustcontain("""<a href="/%s/changeset/%s">r2:%s</a>""" % (repo2.repo_name, cs2.raw_id, cs2.short_id))
120 response.mustcontain("""<a href="/%s/changeset/%s">r2:%s</a>""" % (repo2.repo_name, cs2.raw_id, cs2.short_id))
120 ## files
121 ## files
121 response.mustcontain("""<a href="/%s/compare/branch@%s...branch@%s?other_repo=%s#C--826e8142e6ba">file1</a>""" % (repo1.repo_name, rev2, rev1, repo2.repo_name))
122 response.mustcontain("""<a href="/%s/compare/branch@%s...branch@%s?other_repo=%s&amp;merge=1#C--826e8142e6ba">file1</a>""" % (repo1.repo_name, rev2, rev1, repo2.repo_name))
122 #swap
123 #swap
123 response.mustcontain("""<a href="/%s/compare/branch@%s...branch@%s?other_repo=%s">[swap]</a>""" % (repo2.repo_name, rev1, rev2, repo1.repo_name))
124 response.mustcontain("""<a href="/%s/compare/branch@%s...branch@%s?other_repo=%s&amp;merge=True">[swap]</a>""" % (repo2.repo_name, rev1, rev2, repo1.repo_name))
124
125
125 def test_compare_forks_on_branch_extra_commits_origin_has_incomming_hg(self):
126 def test_compare_forks_on_branch_extra_commits_origin_has_incomming_hg(self):
126 self.log_user()
127 self.log_user()
@@ -160,6 +161,7 b' class TestCompareController(TestControll'
160 other_repo=repo2.repo_name,
161 other_repo=repo2.repo_name,
161 other_ref_type="branch",
162 other_ref_type="branch",
162 other_ref=rev1,
163 other_ref=rev1,
164 merge='x',
163 ))
165 ))
164 response.mustcontain('%s@%s -&gt; %s@%s' % (repo1.repo_name, rev2, repo2.repo_name, rev1))
166 response.mustcontain('%s@%s -&gt; %s@%s' % (repo1.repo_name, rev2, repo2.repo_name, rev1))
165 response.mustcontain("""Showing 2 commits""")
167 response.mustcontain("""Showing 2 commits""")
@@ -171,9 +173,9 b' class TestCompareController(TestControll'
171 response.mustcontain("""<a href="/%s/changeset/%s">r1:%s</a>""" % (repo2.repo_name, cs1.raw_id, cs1.short_id))
173 response.mustcontain("""<a href="/%s/changeset/%s">r1:%s</a>""" % (repo2.repo_name, cs1.raw_id, cs1.short_id))
172 response.mustcontain("""<a href="/%s/changeset/%s">r2:%s</a>""" % (repo2.repo_name, cs2.raw_id, cs2.short_id))
174 response.mustcontain("""<a href="/%s/changeset/%s">r2:%s</a>""" % (repo2.repo_name, cs2.raw_id, cs2.short_id))
173 ## files
175 ## files
174 response.mustcontain("""<a href="/%s/compare/branch@%s...branch@%s?other_repo=%s#C--826e8142e6ba">file1</a>""" % (repo1.repo_name, rev2, rev1, repo2.repo_name))
176 response.mustcontain("""<a href="/%s/compare/branch@%s...branch@%s?other_repo=%s&amp;merge=x#C--826e8142e6ba">file1</a>""" % (repo1.repo_name, rev2, rev1, repo2.repo_name))
175 #swap
177 #swap
176 response.mustcontain("""<a href="/%s/compare/branch@%s...branch@%s?other_repo=%s">[swap]</a>""" % (repo2.repo_name, rev1, rev2, repo1.repo_name))
178 response.mustcontain("""<a href="/%s/compare/branch@%s...branch@%s?other_repo=%s&amp;merge=True">[swap]</a>""" % (repo2.repo_name, rev1, rev2, repo1.repo_name))
177
179
178 def test_compare_cherry_pick_changesets_from_bottom(self):
180 def test_compare_cherry_pick_changesets_from_bottom(self):
179
181
@@ -222,6 +224,7 b' class TestCompareController(TestControll'
222 other_repo=repo1.repo_name,
224 other_repo=repo1.repo_name,
223 other_ref_type="rev",
225 other_ref_type="rev",
224 other_ref=cs4.short_id,
226 other_ref=cs4.short_id,
227 merge='True',
225 ))
228 ))
226 response.mustcontain('%s@%s -&gt; %s@%s' % (repo2.repo_name, cs1.short_id, repo1.repo_name, cs4.short_id))
229 response.mustcontain('%s@%s -&gt; %s@%s' % (repo2.repo_name, cs1.short_id, repo1.repo_name, cs4.short_id))
227 response.mustcontain("""Showing 3 commits""")
230 response.mustcontain("""Showing 3 commits""")
@@ -281,6 +284,7 b' class TestCompareController(TestControll'
281 org_ref=cs2.short_id, # parent of cs3, not in repo2
284 org_ref=cs2.short_id, # parent of cs3, not in repo2
282 other_ref_type="rev",
285 other_ref_type="rev",
283 other_ref=cs5.short_id,
286 other_ref=cs5.short_id,
287 merge='1',
284 ))
288 ))
285
289
286 response.mustcontain('%s@%s -&gt; %s@%s' % (repo1.repo_name, cs2.short_id, repo1.repo_name, cs5.short_id))
290 response.mustcontain('%s@%s -&gt; %s@%s' % (repo1.repo_name, cs2.short_id, repo1.repo_name, cs5.short_id))
@@ -319,6 +323,7 b' class TestCompareController(TestControll'
319 other_ref_type="rev",
323 other_ref_type="rev",
320 other_ref=rev2,
324 other_ref=rev2,
321 other_repo=HG_FORK,
325 other_repo=HG_FORK,
326 merge='1',
322 ))
327 ))
323 response.mustcontain('%s@%s -&gt; %s@%s' % (HG_REPO, rev1, HG_FORK, rev2))
328 response.mustcontain('%s@%s -&gt; %s@%s' % (HG_REPO, rev1, HG_FORK, rev2))
324 ## outgoing changesets between those revisions
329 ## outgoing changesets between those revisions
@@ -328,9 +333,9 b' class TestCompareController(TestControll'
328 response.mustcontain("""<a href="/%s/changeset/7d4bc8ec6be56c0f10425afb40b6fc315a4c25e7">r6:%s</a>""" % (HG_FORK, rev2))
333 response.mustcontain("""<a href="/%s/changeset/7d4bc8ec6be56c0f10425afb40b6fc315a4c25e7">r6:%s</a>""" % (HG_FORK, rev2))
329
334
330 ## files
335 ## files
331 response.mustcontain("""<a href="/%s/compare/rev@%s...rev@%s?other_repo=%s#C--9c390eb52cd6">vcs/backends/hg.py</a>""" % (HG_REPO, rev1, rev2, HG_FORK))
336 response.mustcontain("""<a href="/%s/compare/rev@%s...rev@%s?other_repo=%s&amp;merge=1#C--9c390eb52cd6">vcs/backends/hg.py</a>""" % (HG_REPO, rev1, rev2, HG_FORK))
332 response.mustcontain("""<a href="/%s/compare/rev@%s...rev@%s?other_repo=%s#C--41b41c1f2796">vcs/backends/__init__.py</a>""" % (HG_REPO, rev1, rev2, HG_FORK))
337 response.mustcontain("""<a href="/%s/compare/rev@%s...rev@%s?other_repo=%s&amp;merge=1#C--41b41c1f2796">vcs/backends/__init__.py</a>""" % (HG_REPO, rev1, rev2, HG_FORK))
333 response.mustcontain("""<a href="/%s/compare/rev@%s...rev@%s?other_repo=%s#C--2f574d260608">vcs/backends/base.py</a>""" % (HG_REPO, rev1, rev2, HG_FORK))
338 response.mustcontain("""<a href="/%s/compare/rev@%s...rev@%s?other_repo=%s&amp;merge=1#C--2f574d260608">vcs/backends/base.py</a>""" % (HG_REPO, rev1, rev2, HG_FORK))
334
339
335 def test_org_repo_new_commits_after_forking_simple_diff(self):
340 def test_org_repo_new_commits_after_forking_simple_diff(self):
336 self.log_user()
341 self.log_user()
@@ -401,6 +406,7 b' class TestCompareController(TestControll'
401 other_ref_type="branch",
406 other_ref_type="branch",
402 other_ref=rev2,
407 other_ref=rev2,
403 other_repo=r1_name,
408 other_repo=r1_name,
409 merge='1',
404 ))
410 ))
405 response.mustcontain('%s@%s -&gt; %s@%s' % (r2_name, rev1, r1_name, rev2))
411 response.mustcontain('%s@%s -&gt; %s@%s' % (r2_name, rev1, r1_name, rev2))
406 response.mustcontain('No files')
412 response.mustcontain('No files')
@@ -425,6 +431,7 b' class TestCompareController(TestControll'
425 other_ref_type="branch",
431 other_ref_type="branch",
426 other_ref=rev2,
432 other_ref=rev2,
427 other_repo=r1_name,
433 other_repo=r1_name,
434 merge='1',
428 ))
435 ))
429
436
430 response.mustcontain('%s@%s -&gt; %s@%s' % (r2_name, rev1, r1_name, rev2))
437 response.mustcontain('%s@%s -&gt; %s@%s' % (r2_name, rev1, r1_name, rev2))
General Comments 0
You need to be logged in to leave comments. Login now