Changeset - 3ac76dfdab8e
[Not reviewed]
beta
0 2 0
Mads Kiilerich - 13 years ago 2013-02-28 23:23:09
madski@unity3d.com
Grafted from: 6a5f7a89c648
compare: minor refactoring and comments
2 files changed with 9 insertions and 10 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/compare.py
Show inline comments
 
@@ -62,54 +62,57 @@ class CompareController(BaseRepoControll
 
        instead
 

	
 
        :param rev: revision to fetch
 
        :param repo: repo instance
 
        """
 

	
 
        try:
 
            type_, rev = rev
 
            return repo.scm_instance.get_changeset(rev)
 
        except EmptyRepositoryError, e:
 
            if not redirect_after:
 
                return None
 
            h.flash(h.literal(_('There are no changesets yet')),
 
                    category='warning')
 
            redirect(url('summary_home', repo_name=repo.repo_name))
 

	
 
        except RepositoryError, e:
 
            log.error(traceback.format_exc())
 
            h.flash(str(e), category='warning')
 
            if not partial:
 
                redirect(h.url('summary_home', repo_name=repo.repo_name))
 
            raise HTTPBadRequest()
 

	
 
    def index(self, org_ref_type, org_ref, other_ref_type, other_ref):
 

	
 
        # org_ref will be evaluated in org_repo
 
        org_repo = c.rhodecode_db_repo.repo_name
 
        org_ref = (org_ref_type, org_ref)
 
        # other_ref will be evaluated in other_repo
 
        other_ref = (other_ref_type, other_ref)
 
        other_repo = request.GET.get('other_repo', org_repo)
 
        c.fulldiff = fulldiff = request.GET.get('fulldiff')
 
        # fulldiff disables cut_off_limit
 
        c.fulldiff = request.GET.get('fulldiff')
 
        # only consider this range of changesets
 
        rev_start = request.GET.get('rev_start')
 
        rev_end = request.GET.get('rev_end')
 
        # partial uses compare_cs.html template directly
 
        partial = request.environ.get('HTTP_X_PARTIAL_XHR')
 
        # as_form puts hidden input field with changeset revisions
 
        c.as_form = partial and request.GET.get('as_form')
 
        # swap url for compare_diff page - never partial and never as_form
 
        c.swap_url = h.url('compare_url',
 
            repo_name=other_repo,
 
            org_ref_type=other_ref[0], org_ref=other_ref[1],
 
            other_repo=org_repo,
 
            other_ref_type=org_ref[0], other_ref=org_ref[1])
 

	
 
        org_repo = Repository.get_by_repo_name(org_repo)
 
        other_repo = Repository.get_by_repo_name(other_repo)
 

	
 
        self.__get_cs_or_redirect(rev=org_ref, repo=org_repo, partial=partial)
 
        self.__get_cs_or_redirect(rev=other_ref, repo=other_repo, partial=partial)
 

	
 
        if org_repo is None:
 
            log.error('Could not find org repo %s' % org_repo)
 
            raise HTTPNotFound
 
        if other_repo is None:
 
            log.error('Could not find other repo %s' % other_repo)
 
@@ -142,49 +145,49 @@ class CompareController(BaseRepoControll
 
            rev_start = _cs.parents[0].raw_id if _cs.parents else EmptyChangeset().raw_id
 
            org_ref = ('rev', rev_start)
 
            other_ref = ('rev', rev_end)
 
            #if we cherry pick it's not remote, make the other_repo org_repo
 
            org_repo = other_repo
 

	
 
        c.cs_ranges, ancestor = PullRequestModel().get_compare_data(
 
            org_repo, org_ref, other_repo, other_ref)
 

	
 
        c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in
 
                                                   c.cs_ranges])
 
        if partial:
 
            return render('compare/compare_cs.html')
 

	
 
        if ancestor and org_repo != other_repo:
 
            # case we want a simple diff without incoming changesets,
 
            # previewing what will be merged.
 
            # Make the diff on the forked repo, with
 
            # revision that is common ancestor
 
            log.debug('Using ancestor %s as org_ref instead of %s'
 
                      % (ancestor, org_ref))
 
            org_ref = ('rev', ancestor)
 
            org_repo = other_repo
 

	
 
        diff_limit = self.cut_off_limit if not fulldiff else None
 
        diff_limit = self.cut_off_limit if not c.fulldiff else None
 

	
 
        _diff = diffs.differ(org_repo, org_ref, other_repo, other_ref)
 

	
 
        diff_processor = diffs.DiffProcessor(_diff or '', format='gitdiff',
 
                                             diff_limit=diff_limit)
 
        _parsed = diff_processor.prepare()
 

	
 
        c.limited_diff = False
 
        if isinstance(_parsed, LimitedDiffContainer):
 
            c.limited_diff = True
 

	
 
        c.files = []
 
        c.changes = {}
 
        c.lines_added = 0
 
        c.lines_deleted = 0
 
        for f in _parsed:
 
            st = f['stats']
 
            if st[0] != 'b':
 
                c.lines_added += st[0]
 
                c.lines_deleted += st[1]
 
            fid = h.FID('', f['filename'])
 
            c.files.append([fid, f['operation'], f['filename'], f['stats']])
 
            diff = diff_processor.as_html(enable_comments=False, parsed_lines=[f])
 
            c.changes[fid] = [f['operation'], f['filename'], diff]
rhodecode/model/pull_request.py
Show inline comments
 
@@ -228,32 +228,28 @@ class PullRequestModel(BaseModel):
 
                'log --reverse --pretty="format: %%H" -s -p %s..%s' % (org_ref[1],
 
                                                                       other_ref[1])
 
            )
 
            changesets = [org_repo.get_changeset(cs)
 
                          for cs in re.findall(r'[0-9a-fA-F]{40}', so)]
 

	
 
        return changesets, ancestor
 

	
 
    def get_compare_data(self, org_repo, org_ref, other_repo, other_ref):
 
        """
 
        Returns incoming changesets for mercurial repositories
 

	
 
        :param org_repo:
 
        :param org_ref:
 
        :param other_repo:
 
        :param other_ref:
 
        """
 

	
 
        if len(org_ref) != 2 or not isinstance(org_ref, (list, tuple)):
 
            raise Exception('org_ref must be a two element list/tuple')
 

	
 
        if len(other_ref) != 2 or not isinstance(org_ref, (list, tuple)):
 
            raise Exception('other_ref must be a two element list/tuple')
 

	
 
        org_repo_scm = org_repo.scm_instance
 
        other_repo_scm = other_repo.scm_instance
 

	
 
        alias = org_repo.scm_instance.alias
 
        cs_ranges, ancestor = self._get_changesets(alias,
 
                                                   org_repo_scm, org_ref,
 
                                                   other_repo_scm, other_ref)
 
        cs_ranges, ancestor = self._get_changesets(org_repo.scm_instance.alias,
 
                                                   org_repo.scm_instance, org_ref,
 
                                                   other_repo.scm_instance, other_ref)
 
        return cs_ranges, ancestor
0 comments (0 inline, 0 general)