Show More
@@ -40,6 +40,7 b' from rhodecode.lib import diffs' | |||||
40 | from rhodecode.model.db import Repository |
|
40 | from rhodecode.model.db import Repository | |
41 | from rhodecode.model.pull_request import PullRequestModel |
|
41 | from rhodecode.model.pull_request import PullRequestModel | |
42 | from webob.exc import HTTPBadRequest |
|
42 | from webob.exc import HTTPBadRequest | |
|
43 | from rhodecode.lib.utils2 import str2bool | |||
43 |
|
44 | |||
44 | log = logging.getLogger(__name__) |
|
45 | log = logging.getLogger(__name__) | |
45 |
|
46 | |||
@@ -86,11 +87,13 b' class CompareController(BaseRepoControll' | |||||
86 | org_ref = (org_ref_type, org_ref) |
|
87 | org_ref = (org_ref_type, org_ref) | |
87 | other_ref = (other_ref_type, other_ref) |
|
88 | other_ref = (other_ref_type, other_ref) | |
88 | other_repo = request.GET.get('repo', org_repo) |
|
89 | other_repo = request.GET.get('repo', org_repo) | |
|
90 | bundle_compare = str2bool(request.GET.get('bundle', True)) | |||
89 |
|
91 | |||
90 | c.swap_url = h.url('compare_url', repo_name=other_repo, |
|
92 | c.swap_url = h.url('compare_url', repo_name=other_repo, | |
91 | org_ref_type=other_ref[0], org_ref=other_ref[1], |
|
93 | org_ref_type=other_ref[0], org_ref=other_ref[1], | |
92 | other_ref_type=org_ref[0], other_ref=org_ref[1], |
|
94 | other_ref_type=org_ref[0], other_ref=org_ref[1], | |
93 | repo=org_repo) |
|
95 | repo=org_repo, as_form=request.GET.get('as_form'), | |
|
96 | bundle=bundle_compare) | |||
94 |
|
97 | |||
95 | c.org_repo = org_repo = Repository.get_by_repo_name(org_repo) |
|
98 | c.org_repo = org_repo = Repository.get_by_repo_name(org_repo) | |
96 | c.other_repo = other_repo = Repository.get_by_repo_name(other_repo) |
|
99 | c.other_repo = other_repo = Repository.get_by_repo_name(other_repo) | |
@@ -107,8 +110,8 b' class CompareController(BaseRepoControll' | |||||
107 | self.__get_cs_or_redirect(rev=other_ref, repo=other_repo, partial=partial) |
|
110 | self.__get_cs_or_redirect(rev=other_ref, repo=other_repo, partial=partial) | |
108 |
|
111 | |||
109 | c.cs_ranges, discovery_data = PullRequestModel().get_compare_data( |
|
112 | c.cs_ranges, discovery_data = PullRequestModel().get_compare_data( | |
110 |
|
|
113 | org_repo, org_ref, other_repo, other_ref | |
111 |
|
|
114 | ) | |
112 |
|
115 | |||
113 | c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in |
|
116 | c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in | |
114 | c.cs_ranges]) |
|
117 | c.cs_ranges]) | |
@@ -118,11 +121,18 b' class CompareController(BaseRepoControll' | |||||
118 | if partial: |
|
121 | if partial: | |
119 | return render('compare/compare_cs.html') |
|
122 | return render('compare/compare_cs.html') | |
120 |
|
123 | |||
|
124 | if not bundle_compare and c.cs_ranges: | |||
|
125 | # case we want a simple diff without incoming changesets, just | |||
|
126 | # for review purposes. Make the diff on the forked repo, with | |||
|
127 | # revision that is common ancestor | |||
|
128 | other_ref = ('rev', c.cs_ranges[-1].parents[0].raw_id) | |||
|
129 | other_repo = org_repo | |||
|
130 | ||||
121 | c.org_ref = org_ref[1] |
|
131 | c.org_ref = org_ref[1] | |
122 | c.other_ref = other_ref[1] |
|
132 | c.other_ref = other_ref[1] | |
123 | # diff needs to have swapped org with other to generate proper diff |
|
133 | ||
124 | _diff = diffs.differ(other_repo, other_ref, org_repo, org_ref, |
|
134 | _diff = diffs.differ(other_repo, other_ref, org_repo, org_ref, | |
125 | discovery_data) |
|
135 | discovery_data, bundle_compare=bundle_compare) | |
126 | diff_processor = diffs.DiffProcessor(_diff, format='gitdiff') |
|
136 | diff_processor = diffs.DiffProcessor(_diff, format='gitdiff') | |
127 | _parsed = diff_processor.prepare() |
|
137 | _parsed = diff_processor.prepare() | |
128 |
|
138 |
@@ -272,6 +272,12 b' class PullrequestsController(BaseRepoCon' | |||||
272 | c.cs_ranges, discovery_data = PullRequestModel().get_compare_data( |
|
272 | c.cs_ranges, discovery_data = PullRequestModel().get_compare_data( | |
273 | org_repo, org_ref, other_repo, other_ref |
|
273 | org_repo, org_ref, other_repo, other_ref | |
274 | ) |
|
274 | ) | |
|
275 | if c.cs_ranges: | |||
|
276 | # case we want a simple diff without incoming changesets, just | |||
|
277 | # for review purposes. Make the diff on the forked repo, with | |||
|
278 | # revision that is common ancestor | |||
|
279 | other_ref = ('rev', c.cs_ranges[-1].parents[0].raw_id) | |||
|
280 | other_repo = org_repo | |||
275 |
|
281 | |||
276 | c.statuses = org_repo.statuses([x.raw_id for x in c.cs_ranges]) |
|
282 | c.statuses = org_repo.statuses([x.raw_id for x in c.cs_ranges]) | |
277 | # defines that we need hidden inputs with changesets |
|
283 | # defines that we need hidden inputs with changesets |
@@ -28,6 +28,7 b'' | |||||
28 | import re |
|
28 | import re | |
29 | import difflib |
|
29 | import difflib | |
30 | import markupsafe |
|
30 | import markupsafe | |
|
31 | import logging | |||
31 |
|
32 | |||
32 | from itertools import tee, imap |
|
33 | from itertools import tee, imap | |
33 |
|
34 | |||
@@ -46,6 +47,8 b' from rhodecode.lib.helpers import escape' | |||||
46 | from rhodecode.lib.utils import make_ui |
|
47 | from rhodecode.lib.utils import make_ui | |
47 | from rhodecode.lib.utils2 import safe_unicode |
|
48 | from rhodecode.lib.utils2 import safe_unicode | |
48 |
|
49 | |||
|
50 | log = logging.getLogger(__name__) | |||
|
51 | ||||
49 |
|
52 | |||
50 | def wrap_to_table(str_): |
|
53 | def wrap_to_table(str_): | |
51 | return '''<table class="code-difftable"> |
|
54 | return '''<table class="code-difftable"> | |
@@ -574,7 +577,8 b' class InMemoryBundleRepo(bundlerepositor' | |||||
574 | self.bundlefilespos = {} |
|
577 | self.bundlefilespos = {} | |
575 |
|
578 | |||
576 |
|
579 | |||
577 |
def differ(org_repo, org_ref, other_repo, other_ref, discovery_data=None |
|
580 | def differ(org_repo, org_ref, other_repo, other_ref, discovery_data=None, | |
|
581 | bundle_compare=False): | |||
578 | """ |
|
582 | """ | |
579 | General differ between branches, bookmarks or separate but releated |
|
583 | General differ between branches, bookmarks or separate but releated | |
580 | repositories |
|
584 | repositories | |
@@ -598,7 +602,7 b' def differ(org_repo, org_ref, other_repo' | |||||
598 | org_ref = org_ref[1] |
|
602 | org_ref = org_ref[1] | |
599 | other_ref = other_ref[1] |
|
603 | other_ref = other_ref[1] | |
600 |
|
604 | |||
601 | if org_repo != other_repo: |
|
605 | if org_repo != other_repo and bundle_compare: | |
602 |
|
606 | |||
603 | common, incoming, rheads = discovery_data |
|
607 | common, incoming, rheads = discovery_data | |
604 | other_repo_peer = localrepo.locallegacypeer(other_repo.local()) |
|
608 | other_repo_peer = localrepo.locallegacypeer(other_repo.local()) | |
@@ -633,5 +637,7 b' def differ(org_repo, org_ref, other_repo' | |||||
633 | node2=other_repo[other_ref].node(), |
|
637 | node2=other_repo[other_ref].node(), | |
634 | opts=opts)) |
|
638 | opts=opts)) | |
635 | else: |
|
639 | else: | |
|
640 | log.debug('running diff between %s@%s and %s@%s' | |||
|
641 | % (org_repo, org_ref, other_repo, other_ref)) | |||
636 | return ''.join(patch.diff(org_repo, node1=org_ref, node2=other_ref, |
|
642 | return ''.join(patch.diff(org_repo, node1=org_ref, node2=other_ref, | |
637 | opts=opts)) |
|
643 | opts=opts)) |
@@ -141,7 +141,7 b'' | |||||
141 | org_ref_type='org_ref_type', org_ref='org_ref', |
|
141 | org_ref_type='org_ref_type', org_ref='org_ref', | |
142 | other_ref_type='other_ref_type', other_ref='other_ref', |
|
142 | other_ref_type='other_ref_type', other_ref='other_ref', | |
143 | repo='other_repo', |
|
143 | repo='other_repo', | |
144 | as_form=True)}"; |
|
144 | as_form=True, bundle=False)}"; | |
145 |
|
145 | |||
146 | var select_refs = YUQ('#pull_request_form select.refs') |
|
146 | var select_refs = YUQ('#pull_request_form select.refs') | |
147 | var rev_data = {}; // gather the org/other ref and repo here |
|
147 | var rev_data = {}; // gather the org/other ref and repo here |
@@ -254,7 +254,8 b' class TestCompareController(TestControll' | |||||
254 | org_ref=rev1, |
|
254 | org_ref=rev1, | |
255 | other_ref_type="branch", |
|
255 | other_ref_type="branch", | |
256 | other_ref=rev2, |
|
256 | other_ref=rev2, | |
257 | repo=r1_name |
|
257 | repo=r1_name, | |
|
258 | bundle=True, | |||
258 | )) |
|
259 | )) | |
259 |
|
260 | |||
260 | try: |
|
261 | try: | |
@@ -269,6 +270,112 b' class TestCompareController(TestControll' | |||||
269 | cs=EmptyChangeset(alias='hg'), user=TEST_USER_ADMIN_LOGIN, |
|
270 | cs=EmptyChangeset(alias='hg'), user=TEST_USER_ADMIN_LOGIN, | |
270 | author=TEST_USER_ADMIN_LOGIN, |
|
271 | author=TEST_USER_ADMIN_LOGIN, | |
271 | message='commit2', |
|
272 | message='commit2', | |
|
273 | content='line1-from-new-parent', | |||
|
274 | f_path='file2' | |||
|
275 | ) | |||
|
276 | #compare ! | |||
|
277 | rev1 = 'default' | |||
|
278 | rev2 = 'default' | |||
|
279 | response = self.app.get(url(controller='compare', action='index', | |||
|
280 | repo_name=r2_name, | |||
|
281 | org_ref_type="branch", | |||
|
282 | org_ref=rev1, | |||
|
283 | other_ref_type="branch", | |||
|
284 | other_ref=rev2, | |||
|
285 | repo=r1_name, | |||
|
286 | bundle=True, | |||
|
287 | )) | |||
|
288 | ||||
|
289 | response.mustcontain('%s@%s -> %s@%s' % (r2_name, rev1, r1_name, rev2)) | |||
|
290 | response.mustcontain("""<a href="#">file2</a>""") # new commit from parent | |||
|
291 | response.mustcontain("""line1-from-new-parent""") | |||
|
292 | response.mustcontain("""file1-line1-from-fork""") | |||
|
293 | response.mustcontain("""file2-line1-from-fork""") | |||
|
294 | response.mustcontain("""file3-line1-from-fork""") | |||
|
295 | finally: | |||
|
296 | RepoModel().delete(r2_id) | |||
|
297 | RepoModel().delete(r1_id) | |||
|
298 | ||||
|
299 | def test_org_repo_new_commits_after_forking_simple_diff(self): | |||
|
300 | self.log_user() | |||
|
301 | ||||
|
302 | repo1 = RepoModel().create_repo(repo_name='one', repo_type='hg', | |||
|
303 | description='diff-test', | |||
|
304 | owner=TEST_USER_ADMIN_LOGIN) | |||
|
305 | ||||
|
306 | Session().commit() | |||
|
307 | r1_id = repo1.repo_id | |||
|
308 | r1_name = repo1.repo_name | |||
|
309 | ||||
|
310 | #commit something initially ! | |||
|
311 | cs0 = ScmModel().create_node( | |||
|
312 | repo=repo1.scm_instance, repo_name=r1_name, | |||
|
313 | cs=EmptyChangeset(alias='hg'), user=TEST_USER_ADMIN_LOGIN, | |||
|
314 | author=TEST_USER_ADMIN_LOGIN, | |||
|
315 | message='commit1', | |||
|
316 | content='line1', | |||
|
317 | f_path='file1' | |||
|
318 | ) | |||
|
319 | Session().commit() | |||
|
320 | self.assertEqual(repo1.scm_instance.revisions, [cs0.raw_id]) | |||
|
321 | #fork the repo1 | |||
|
322 | repo2 = RepoModel().create_repo(repo_name='one-fork', repo_type='hg', | |||
|
323 | description='compare-test', | |||
|
324 | clone_uri=repo1.repo_full_path, | |||
|
325 | owner=TEST_USER_ADMIN_LOGIN, fork_of='one') | |||
|
326 | Session().commit() | |||
|
327 | self.assertEqual(repo2.scm_instance.revisions, [cs0.raw_id]) | |||
|
328 | r2_id = repo2.repo_id | |||
|
329 | r2_name = repo2.repo_name | |||
|
330 | ||||
|
331 | #make 3 new commits in fork | |||
|
332 | cs1 = ScmModel().create_node( | |||
|
333 | repo=repo2.scm_instance, repo_name=r2_name, | |||
|
334 | cs=repo2.scm_instance[-1], user=TEST_USER_ADMIN_LOGIN, | |||
|
335 | author=TEST_USER_ADMIN_LOGIN, | |||
|
336 | message='commit1-fork', | |||
|
337 | content='file1-line1-from-fork', | |||
|
338 | f_path='file1-fork' | |||
|
339 | ) | |||
|
340 | cs2 = ScmModel().create_node( | |||
|
341 | repo=repo2.scm_instance, repo_name=r2_name, | |||
|
342 | cs=cs1, user=TEST_USER_ADMIN_LOGIN, | |||
|
343 | author=TEST_USER_ADMIN_LOGIN, | |||
|
344 | message='commit2-fork', | |||
|
345 | content='file2-line1-from-fork', | |||
|
346 | f_path='file2-fork' | |||
|
347 | ) | |||
|
348 | cs3 = ScmModel().create_node( | |||
|
349 | repo=repo2.scm_instance, repo_name=r2_name, | |||
|
350 | cs=cs2, user=TEST_USER_ADMIN_LOGIN, | |||
|
351 | author=TEST_USER_ADMIN_LOGIN, | |||
|
352 | message='commit3-fork', | |||
|
353 | content='file3-line1-from-fork', | |||
|
354 | f_path='file3-fork' | |||
|
355 | ) | |||
|
356 | ||||
|
357 | #compare ! | |||
|
358 | rev1 = 'default' | |||
|
359 | rev2 = 'default' | |||
|
360 | response = self.app.get(url(controller='compare', action='index', | |||
|
361 | repo_name=r2_name, | |||
|
362 | org_ref_type="branch", | |||
|
363 | org_ref=rev1, | |||
|
364 | other_ref_type="branch", | |||
|
365 | other_ref=rev2, | |||
|
366 | repo=r1_name, | |||
|
367 | bundle=False, | |||
|
368 | )) | |||
|
369 | ||||
|
370 | try: | |||
|
371 | #response.mustcontain('%s@%s -> %s@%s' % (r2_name, rev1, r1_name, rev2)) | |||
|
372 | ||||
|
373 | #add new commit into parent ! | |||
|
374 | cs0 = ScmModel().create_node( | |||
|
375 | repo=repo1.scm_instance, repo_name=r1_name, | |||
|
376 | cs=EmptyChangeset(alias='hg'), user=TEST_USER_ADMIN_LOGIN, | |||
|
377 | author=TEST_USER_ADMIN_LOGIN, | |||
|
378 | message='commit2', | |||
272 | content='line1', |
|
379 | content='line1', | |
273 | f_path='file2' |
|
380 | f_path='file2' | |
274 | ) |
|
381 | ) | |
@@ -281,13 +388,16 b' class TestCompareController(TestControll' | |||||
281 | org_ref=rev1, |
|
388 | org_ref=rev1, | |
282 | other_ref_type="branch", |
|
389 | other_ref_type="branch", | |
283 | other_ref=rev2, |
|
390 | other_ref=rev2, | |
284 | repo=r1_name |
|
391 | repo=r1_name, | |
|
392 | bundle=False | |||
285 | )) |
|
393 | )) | |
286 |
|
394 | rev2 = cs0.parents[0].raw_id | ||
287 | response.mustcontain('%s@%s -> %s@%s' % (r2_name, rev1, r1_name, rev2)) |
|
395 | response.mustcontain('%s@%s -> %s@%s' % (r2_name, rev1, r1_name, rev2)) | |
288 | response.mustcontain("""file1-line1-from-fork""") |
|
396 | response.mustcontain("""file1-line1-from-fork""") | |
289 | response.mustcontain("""file2-line1-from-fork""") |
|
397 | response.mustcontain("""file2-line1-from-fork""") | |
290 | response.mustcontain("""file3-line1-from-fork""") |
|
398 | response.mustcontain("""file3-line1-from-fork""") | |
|
399 | self.assertFalse("""<a href="#">file2</a>""" in response.body) # new commit from parent | |||
|
400 | self.assertFalse("""line1-from-new-parent""" in response.body) | |||
291 | finally: |
|
401 | finally: | |
292 | RepoModel().delete(r2_id) |
|
402 | RepoModel().delete(r2_id) | |
293 |
RepoModel().delete(r1_id) |
|
403 | RepoModel().delete(r1_id) No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now