comparison rhodecode/controllers/compare.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 75e563531350
children 50927aedcab5
comparison
equal deleted inserted replaced
3485:b19b1723ff10 3486:2053053e0882
87 org_repo = c.rhodecode_db_repo.repo_name 87 org_repo = c.rhodecode_db_repo.repo_name
88 org_ref = (org_ref_type, org_ref) 88 org_ref = (org_ref_type, org_ref)
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
95 partial = request.environ.get('HTTP_X_PARTIAL_XHR') 104 partial = request.environ.get('HTTP_X_PARTIAL_XHR')
96 # as_form puts hidden input field with changeset revisions 105 # as_form puts hidden input field with changeset revisions
98 # swap url for compare_diff page - never partial and never as_form 107 # swap url for compare_diff page - never partial and never as_form
99 c.swap_url = h.url('compare_url', 108 c.swap_url = h.url('compare_url',
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)
107 117
108 self.__get_cs_or_redirect(rev=org_ref, repo=org_repo, partial=partial) 118 self.__get_cs_or_redirect(rev=org_ref, repo=org_repo, partial=partial)
128 c.org_ref = org_ref[1] 138 c.org_ref = org_ref[1]
129 c.other_ref = other_ref[1] 139 c.other_ref = other_ref[1]
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
152 163
153 _diff = diffs.differ(org_repo, org_ref, other_repo, other_ref) 164 _diff = diffs.differ(org_repo, org_ref, other_repo, other_ref)