Mercurial > kallithea
comparison rhodecode/controllers/compare.py @ 4039:b44fabc4377c
compare: resolve revisions in the right repository for diffs between repos
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Wed, 26 Jun 2013 00:13:15 +0200 |
parents | ed50319aab94 |
children | d415621fa7c5 |
comparison
equal
deleted
inserted
replaced
4038:ed50319aab94 | 4039:b44fabc4377c |
---|---|
52 class CompareController(BaseRepoController): | 52 class CompareController(BaseRepoController): |
53 | 53 |
54 def __before__(self): | 54 def __before__(self): |
55 super(CompareController, self).__before__() | 55 super(CompareController, self).__before__() |
56 | 56 |
57 def __get_cs_or_redirect(self, ref, repo, redirect_after=True, | 57 def __get_rev_or_redirect(self, ref, repo, redirect_after=True, |
58 partial=False): | 58 partial=False): |
59 """ | 59 """ |
60 Safe way to get changeset if error occur it redirects to changeset with | 60 Safe way to get changeset if error occur it redirects to changeset with |
61 proper message. If partial is set then don't do redirect raise Exception | 61 proper message. If partial is set then don't do redirect raise Exception |
62 instead | 62 instead |
79 if revs: | 79 if revs: |
80 rev = revs[-1] | 80 rev = revs[-1] |
81 # else: TODO: just report 'not found' | 81 # else: TODO: just report 'not found' |
82 | 82 |
83 try: | 83 try: |
84 return repo.scm_instance.get_changeset(rev) | 84 return repo.scm_instance.get_changeset(rev).raw_id |
85 except EmptyRepositoryError, e: | 85 except EmptyRepositoryError, e: |
86 if not redirect_after: | 86 if not redirect_after: |
87 return None | 87 return None |
88 h.flash(h.literal(_('There are no changesets yet')), | 88 h.flash(h.literal(_('There are no changesets yet')), |
89 category='warning') | 89 category='warning') |
217 | 217 |
218 if org_repo.scm_instance.alias != other_repo.scm_instance.alias: | 218 if org_repo.scm_instance.alias != other_repo.scm_instance.alias: |
219 log.error('compare of two different kind of remote repos not available') | 219 log.error('compare of two different kind of remote repos not available') |
220 raise HTTPNotFound | 220 raise HTTPNotFound |
221 | 221 |
222 self.__get_cs_or_redirect(ref=org_ref, repo=org_repo, partial=partial) | 222 org_rev = self.__get_rev_or_redirect(ref=org_ref, repo=org_repo, partial=partial) |
223 self.__get_cs_or_redirect(ref=other_ref, repo=other_repo, partial=partial) | 223 other_rev = self.__get_rev_or_redirect(ref=other_ref, repo=other_repo, partial=partial) |
224 | 224 |
225 c.org_repo = org_repo | 225 c.org_repo = org_repo |
226 c.other_repo = other_repo | 226 c.other_repo = other_repo |
227 c.org_ref = org_ref[1] | 227 c.org_ref = org_ref[1] |
228 c.other_ref = other_ref[1] | 228 c.other_ref = other_ref[1] |
247 # case we want a simple diff without incoming changesets, | 247 # case we want a simple diff without incoming changesets, |
248 # previewing what will be merged. | 248 # previewing what will be merged. |
249 # Make the diff on the other repo (which is known to have other_ref) | 249 # Make the diff on the other repo (which is known to have other_ref) |
250 log.debug('Using ancestor %s as org_ref instead of %s' | 250 log.debug('Using ancestor %s as org_ref instead of %s' |
251 % (c.ancestor, org_ref)) | 251 % (c.ancestor, org_ref)) |
252 org_ref = ('rev', c.ancestor) | 252 org_rev = c.ancestor |
253 org_repo = other_repo | 253 org_repo = other_repo |
254 | 254 |
255 diff_limit = self.cut_off_limit if not c.fulldiff else None | 255 diff_limit = self.cut_off_limit if not c.fulldiff else None |
256 | 256 |
257 log.debug('running diff between %s and %s in %s' | 257 log.debug('running diff between %s and %s in %s' |
258 % (org_ref, other_ref, org_repo.scm_instance.path)) | 258 % (org_rev, other_rev, org_repo.scm_instance.path)) |
259 txtdiff = org_repo.scm_instance.get_diff(rev1=safe_str(org_ref[1]), rev2=safe_str(other_ref[1])) | 259 txtdiff = org_repo.scm_instance.get_diff(rev1=org_rev, rev2=other_rev) |
260 | 260 |
261 diff_processor = diffs.DiffProcessor(txtdiff or '', format='gitdiff', | 261 diff_processor = diffs.DiffProcessor(txtdiff or '', format='gitdiff', |
262 diff_limit=diff_limit) | 262 diff_limit=diff_limit) |
263 _parsed = diff_processor.prepare() | 263 _parsed = diff_processor.prepare() |
264 | 264 |