~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revisionspec.py

Add submit: specifier, for merge-directive-like diffs

Show diffs side-by-side

added added

removed removed

Lines of Context:
668
668
        return RevisionInfo(branch, revno, revision_b)
669
669
        
670
670
SPEC_TYPES.append(RevisionSpec_branch)
 
671
 
 
672
 
 
673
class RevisionSpec_ancestor(RevisionSpec):
 
674
    """Selects a common ancestor with a submit branch."""
 
675
 
 
676
    help_txt = """Selects a common ancestor with the submit branch.
 
677
 
 
678
    Diffing against this shows all the changes that were made in this branch,
 
679
    and is a good predictor of what merge will do.  The submit branch is
 
680
    used by the bundle and merge directive comands.  If no submit branch
 
681
    is specified, the parent branch is used instead.
 
682
 
 
683
    The common ancestor is the last revision that existed in both
 
684
    branches. Usually this is the branch point, but it could also be
 
685
    a revision that was merged.
 
686
 
 
687
    examples:
 
688
      $ bzr diff -r submit:
 
689
    """
 
690
    prefix = 'submit:'
 
691
 
 
692
    def _match_on(self, branch, revs):
 
693
        from bzrlib.branch import Branch
 
694
 
 
695
        trace.mutter('matching ancestor: on: %s, %s', self.spec, branch)
 
696
        submit_location = branch.get_submit_branch()
 
697
        if submit_location is None:
 
698
            submit_location = branch.get_parent()
 
699
        if submit_location is None:
 
700
            raise errors.NoSubmitBranch(branch)
 
701
 
 
702
 
 
703
        other_branch = Branch.open(submit_location)
 
704
        revision_a = branch.last_revision()
 
705
        revision_b = other_branch.last_revision()
 
706
        for r, b in ((revision_a, branch), (revision_b, other_branch)):
 
707
            if r in (None, revision.NULL_REVISION):
 
708
                raise errors.NoCommits(b)
 
709
        revision_source = revision.MultipleRevisionSources(
 
710
                branch.repository, other_branch.repository)
 
711
        rev_id = revision.common_ancestor(revision_a, revision_b,
 
712
                                          revision_source)
 
713
        try:
 
714
            revno = branch.revision_id_to_revno(rev_id)
 
715
        except errors.NoSuchRevision:
 
716
            revno = None
 
717
        return RevisionInfo(branch, revno, rev_id)
 
718
 
 
719
SPEC_TYPES.append(RevisionSpec_ancestor)