Changeset - dca89d578c70
[Not reviewed]
beta
0 2 0
Mads Kiilerich - 13 years ago 2013-04-08 22:29:29
madski@unity3d.com
pull requests: use branch name when creating PRs from a changelog with branch filter
2 files changed with 24 insertions and 8 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/pullrequests.py
Show inline comments
 
@@ -59,58 +59,71 @@ from rhodecode.lib.utils2 import safe_in
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
class PullrequestsController(BaseRepoController):
 

	
 
    def __before__(self):
 
        super(PullrequestsController, self).__before__()
 
        repo_model = RepoModel()
 
        c.users_array = repo_model.get_users_js()
 
        c.users_groups_array = repo_model.get_users_groups_js()
 

	
 
    def _get_repo_refs(self, repo, rev=None, branch_rev=None):
 
    def _get_repo_refs(self, repo, rev=None, branch=None, branch_rev=None):
 
        """return a structure with repo's interesting changesets, suitable for
 
        the selectors in pullrequest.html
 

	
 
        rev: a revision that must be in the list and selected by default
 
        rev: a revision that must be in the list somehow and selected by default
 
        branch: a branch that must be in the list and selected by default - even if closed
 
        branch_rev: a revision of which peers should be preferred and available."""
 
        # list named branches that has been merged to this named branch - it should probably merge back
 
        peers = []
 

	
 
        if rev:
 
            rev = safe_str(rev)
 

	
 
        if branch:
 
            branch = safe_str(branch)
 

	
 
        if branch_rev:
 
            branch_rev = safe_str(branch_rev)
 
            # not restricting to merge() would also get branch point and be better
 
            # (especially because it would get the branch point) ... but is currently too expensive
 
            otherbranches = {}
 
            for i in repo._repo.revs(
 
                "sort(parents(branch(id(%s)) and merge()) - branch(id(%s)))",
 
                branch_rev, branch_rev):
 
                cs = repo.get_changeset(i)
 
                otherbranches[cs.branch] = cs.raw_id
 
            for abranch, node in otherbranches.iteritems():
 
                selected = 'branch:%s:%s' % (abranch, node)
 
                peers.append((selected, abranch))
 

	
 
        selected = None
 

	
 
        branches = []
 
        for abranch, branchrev in repo.branches.iteritems():
 
            n = 'branch:%s:%s' % (abranch, branchrev)
 
            branches.append((n, abranch))
 
            if rev == branchrev:
 
                selected = n
 
            if branch == abranch:
 
                selected = n
 
                branch = None
 
        if branch: # branch not in list - it is probably closed
 
            revs = repo._repo.revs('max(branch(%s))', branch)
 
            if revs:
 
                cs = repo.get_changeset(revs[0])
 
                selected = 'branch:%s:%s' % (branch, cs.raw_id)
 
                branches.append((selected, branch))
 

	
 
        bookmarks = []
 
        for bookmark, bookmarkrev in repo.bookmarks.iteritems():
 
            n = 'book:%s:%s' % (bookmark, bookmarkrev)
 
            bookmarks.append((n, bookmark))
 
            if rev == bookmarkrev:
 
                selected = n
 

	
 
        tags = []
 
        for tag, tagrev in repo.tags.iteritems():
 
            n = 'tag:%s:%s' % (tag, tagrev)
 
            tags.append((n, tag))
 
@@ -243,29 +256,30 @@ class PullrequestsController(BaseRepoCon
 

	
 
        try:
 
            org_repo.scm_instance.get_changeset()
 
        except EmptyRepositoryError, e:
 
            h.flash(h.literal(_('There are no changesets yet')),
 
                    category='warning')
 
            redirect(url('summary_home', repo_name=org_repo.repo_name))
 

	
 
        org_rev = request.GET.get('rev_end')
 
        # rev_start is not directly useful - its parent could however be used
 
        # as default for other and thus give a simple compare view
 
        #other_rev = request.POST.get('rev_start')
 
        branch = request.GET.get('branch')
 

	
 
        c.org_repos = []
 
        c.org_repos.append((org_repo.repo_name, org_repo.repo_name))
 
        c.default_org_repo = org_repo.repo_name
 
        c.org_refs, c.default_org_ref = self._get_repo_refs(org_repo.scm_instance, org_rev)
 
        c.org_refs, c.default_org_ref = self._get_repo_refs(org_repo.scm_instance, rev=org_rev, branch=branch)
 

	
 
        c.other_repos = []
 
        other_repos_info = {}
 

	
 
        def add_other_repo(repo, branch_rev=None):
 
            if repo.repo_name in other_repos_info: # shouldn't happen
 
                return
 
            c.other_repos.append((repo.repo_name, repo.repo_name))
 
            other_refs, selected_other_ref = self._get_repo_refs(repo.scm_instance, branch_rev=branch_rev)
 
            other_repos_info[repo.repo_name] = {
 
                'user': dict(user_id=repo.user.user_id,
 
                             username=repo.user.username,
rhodecode/templates/changelog/changelog.html
Show inline comments
 
@@ -140,25 +140,24 @@ ${self.context_bar('changelog')}
 
                </div>
 
            </div>
 
        </div>
 

	
 
        <script type="text/javascript" src="${h.url('/js/graph.js')}"></script>
 
        <script type="text/javascript">
 
            YAHOO.util.Event.onDOMReady(function(){
 

	
 
                //Monitor range checkboxes and build a link to changesets
 
                //ranges
 
                var checkboxes = YUD.getElementsByClassName('changeset_range');
 
                var url_tmpl = "${h.url('changeset_home',repo_name=c.repo_name,revision='__REVRANGE__')}";
 
                var pr_tmpl = "${h.url('pullrequest_home',repo_name=c.repo_name)}";
 

	
 
                var checkbox_checker = function(e){
 
                    var checked_checkboxes = [];
 
                    for (pos in checkboxes){
 
                        if(checkboxes[pos].checked){
 
                            checked_checkboxes.push(checkboxes[pos]);
 
                        }
 
                    }
 
                    if(YUD.get('open_new_pr')){
 
                        if(checked_checkboxes.length>1){
 
                            YUD.setStyle('open_new_pr','display','none');
 
                        } else {
 
@@ -179,32 +178,35 @@ ${self.context_bar('changelog')}
 

	
 
                        var link = (rev_start == rev_end)
 
                            ? _TM['Show selected changeset __S']
 
                            : _TM['Show selected changesets __S -> __E'];
 

	
 
                        link = link.replace('__S',rev_start.substr(0,6));
 
                        link = link.replace('__E',rev_end.substr(0,6));
 
                        YUD.get('rev_range_container').href = url;
 
                        YUD.get('rev_range_container').innerHTML = link;
 
                        YUD.setStyle('rev_range_container','display','');
 
                        YUD.setStyle('rev_range_clear','display','');
 

	
 
                        YUD.get('open_new_pr').href = pr_tmpl + '?rev_start={0}&rev_end={1}'.format(rev_start,rev_end);
 
                        var pr_tmpl = "${h.url('pullrequest_home',repo_name=c.repo_name,rev_start='{0}',rev_end='{1}')}";
 
                        YUD.get('open_new_pr').href = pr_tmpl.format(rev_start,rev_end);
 
                        YUD.setStyle('compare_fork','display','none');
 
                    }else{
 
                        YUD.setStyle('rev_range_container','display','none');
 
                        YUD.setStyle('rev_range_clear','display','none');
 
                        if (checkboxes){
 
                            YUD.get('open_new_pr').href = pr_tmpl + '?rev_end={0}'.format(checkboxes[0].name);
 
                        }
 
                        %if c.branch_name:
 
                            YUD.get('open_new_pr').href = "${h.url('pullrequest_home',repo_name=c.repo_name,branch=c.branch_name)}";
 
                        %else:
 
                            YUD.get('open_new_pr').href = "${h.url('pullrequest_home',repo_name=c.repo_name)}";
 
                        %endif
 
                        YUD.setStyle('compare_fork','display','');
 
                    }
 
                };
 
                YUE.onDOMReady(checkbox_checker);
 
                YUE.on(checkboxes,'click', checkbox_checker);
 

	
 
                YUE.on('rev_range_clear','click',function(e){
 
                    for (var i=0; i<checkboxes.length; i++){
 
                        var cb = checkboxes[i];
 
                        cb.checked = false;
 
                    }
 
                    checkbox_checker();
0 comments (0 inline, 0 general)