Changeset - fa4ef7f0f440
[Not reviewed]
default
0 2 0
Mads Kiilerich - 12 years ago 2013-06-28 11:50:13
madski@unity3d.com
compare: calculate changesets and calculate and show ancestor also for non-merge diffs
2 files changed with 12 insertions and 16 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/compare.py
Show inline comments
 
@@ -95,28 +95,26 @@ class CompareController(BaseRepoControll
 
            log.error(traceback.format_exc())
 
            h.flash(safe_str(e), category='warning')
 
            if not partial:
 
                redirect(h.url('summary_home', repo_name=repo.repo_name))
 
            raise HTTPBadRequest()
 

	
 
    def _get_changesets(self, alias, org_repo, org_rev, other_repo, other_rev, merge):
 
    def _get_changesets(self, alias, org_repo, org_rev, other_repo, other_rev):
 
        """
 
        Returns a list of changesets that can be merged from org_repo at org_rev
 
        to other_repo at other_rev ... and the ancestor that would be used for merge.
 

	
 
        :param org_repo: repo object, that is most likely the orginal repo we forked from
 
        :param org_rev: the revision we want our compare to be made
 
        :param other_repo: repo object, mostl likely the fork of org_repo. It hass
 
            all changesets that we need to obtain
 
        :param other_rev: revision we want out compare to be made on other_repo
 

	
 
        """
 
        ancestor = None
 
        if org_rev == other_rev:
 
            changesets = []
 
            if merge:
 
                ancestor = org_rev
 

	
 
        elif alias == 'hg':
 
            #case two independent repos
 
            if org_repo != other_repo:
 
                hgrepo = unionrepo.unionrepository(other_repo.baseui,
 
@@ -126,26 +124,20 @@ class CompareController(BaseRepoControll
 
                # so rev numbers from hgrepo can be used in other_repo
 

	
 
            #no remote compare do it on the same repository
 
            else:
 
                hgrepo = other_repo._repo
 

	
 
            if merge:
 
                revs = hgrepo.revs(
 
                    "ancestors(id(%s)) and not ancestors(id(%s)) and not id(%s)",
 
                    other_rev, org_rev, org_rev)
 

	
 
                ancestors = hgrepo.revs("ancestor(id(%s), id(%s))", org_rev,
 
                                        other_rev)
 
            ancestors = hgrepo.revs("ancestor(id(%s), id(%s))", org_rev, other_rev)
 
                if ancestors:
 
                    # pick arbitrary ancestor - but there is usually only one
 
                    ancestor = hgrepo[ancestors[0]].hex()
 
            else:
 

	
 
                # TODO: have both + and - changesets
 
                revs = hgrepo.revs("id(%s) :: id(%s) - id(%s)",
 
                                   org_rev, other_rev, org_rev)
 
            revs = hgrepo.revs("ancestors(id(%s)) and not ancestors(id(%s)) and not id(%s)",
 
                               other_rev, org_rev, org_rev)
 

	
 
            changesets = [other_repo.get_changeset(rev) for rev in revs]
 

	
 
        elif alias == 'git':
 
            if org_repo != other_repo:
 
                from dulwich.repo import Repo
 
@@ -258,20 +250,19 @@ class CompareController(BaseRepoControll
 
        c.other_ref_name = other_ref_name
 
        c.org_ref_type = org_ref_type
 
        c.other_ref_type = other_ref_type
 

	
 
        c.cs_ranges, c.ancestor = self._get_changesets(
 
            org_repo.scm_instance.alias, org_repo.scm_instance, c.org_rev,
 
            other_repo.scm_instance, c.other_rev, merge)
 
            other_repo.scm_instance, c.other_rev)
 
        c.statuses = c.db_repo.statuses(
 
            [x.raw_id for x in c.cs_ranges])
 

	
 
        if partial:
 
            return render('compare/compare_cs.html')
 
        if c.ancestor:
 
            assert merge
 
        if merge and c.ancestor:
 
            # case we want a simple diff without incoming changesets,
 
            # previewing what will be merged.
 
            # Make the diff on the other repo (which is known to have other_rev)
 
            log.debug('Using ancestor %s as rev1 instead of %s'
 
                      % (c.ancestor, c.org_rev))
 
            rev1 = c.ancestor
kallithea/templates/compare/compare_cs.html
Show inline comments
 
@@ -37,12 +37,17 @@
 
            <i class="icon-resize-vertical" style="color:#DDD"></i>
 
        </td>
 
        <td><div id="C-${cs.raw_id}" class="message" style="white-space:normal; height:1.1em; padding:0">${h.urlify_commit(cs.message, c.repo_name)}</div></td>
 
        </tr>
 
    %endfor
 
    </table>
 
    %if c.ancestor:
 
      <div class="ancestor">${_('Ancestor')}:
 
        ${h.link_to(h.short_id(c.ancestor),h.url('changeset_home',repo_name=c.repo_name,revision=c.ancestor))}
 
      </div>
 
    %endif
 
    %if c.as_form:
 
      ${h.hidden('ancestor_rev',c.ancestor)}
 
      ${h.hidden('merge_rev',c.cs_ranges[-1].raw_id)}
 
    %endif
 
  %endif
 
</div>
0 comments (0 inline, 0 general)