~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

merge from aaron - fixes bare excepts, adds ancestor namespace

Show diffs side-by-side

added added

removed removed

Lines of Context:
576
576
        try:
577
577
            try:
578
578
                return self.revision_store[revision_id]
579
 
            except IndexError:
 
579
            except KeyError:
580
580
                raise bzrlib.errors.NoSuchRevision(self, revision_id)
581
581
        finally:
582
582
            self.unlock()
801
801
 
802
802
        pb = bzrlib.ui.ui_factory.progress_bar()
803
803
        pb.update('comparing histories')
804
 
 
 
804
        if stop_revision is None:
 
805
            other_revision = other.last_patch()
 
806
        else:
 
807
            other_revision = other.lookup_revision(stop_revision)
 
808
        count = greedy_fetch(self, other, other_revision, pb)[0]
805
809
        try:
806
810
            revision_ids = self.missing_revisions(other, stop_revision)
807
811
        except DivergedBranches, e:
808
812
            try:
809
 
                if stop_revision is None:
810
 
                    end_revision = other.last_patch()
811
813
                revision_ids = get_intervening_revisions(self.last_patch(), 
812
 
                                                         end_revision, other)
 
814
                                                         other_revision, self)
813
815
                assert self.last_patch() not in revision_ids
814
816
            except bzrlib.errors.NotAncestor:
815
817
                raise e
816
818
 
817
 
        if len(revision_ids) > 0:
818
 
            count = greedy_fetch(self, other, revision_ids[-1], pb)[0]
819
 
        else:
820
 
            count = 0
821
819
        self.append_revision(*revision_ids)
822
 
        ## note("Added %d revisions." % count)
823
820
        pb.clear()
824
821
 
825
822
    def install_revisions(self, other, revision_ids, pb):
826
823
        if hasattr(other.revision_store, "prefetch"):
827
824
            other.revision_store.prefetch(revision_ids)
828
825
        if hasattr(other.inventory_store, "prefetch"):
829
 
            inventory_ids = [other.get_revision(r).inventory_id
830
 
                             for r in revision_ids]
 
826
            inventory_ids = []
 
827
            for rev_id in revision_ids:
 
828
                try:
 
829
                    revision = other.get_revision(rev_id).inventory_id
 
830
                    inventory_ids.append(revision)
 
831
                except bzrlib.errors.NoSuchRevision:
 
832
                    pass
831
833
            other.inventory_store.prefetch(inventory_ids)
832
834
 
833
835
        if pb is None:
1081
1083
                    return (i+1,)
1082
1084
    REVISION_NAMESPACES['date:'] = _namespace_date
1083
1085
 
 
1086
 
 
1087
    def _namespace_ancestor(self, revs, revision):
 
1088
        from revision import common_ancestor, MultipleRevisionSources
 
1089
        other_branch = find_branch(_trim_namespace('ancestor', revision))
 
1090
        revision_a = self.last_patch()
 
1091
        revision_b = other_branch.last_patch()
 
1092
        for r, b in ((revision_a, self), (revision_b, other_branch)):
 
1093
            if r is None:
 
1094
                raise bzrlib.errors.NoCommits(b)
 
1095
        revision_source = MultipleRevisionSources(self, other_branch)
 
1096
        result = common_ancestor(revision_a, revision_b, revision_source)
 
1097
        try:
 
1098
            revno = self.revision_id_to_revno(result)
 
1099
        except bzrlib.errors.NoSuchRevision:
 
1100
            revno = None
 
1101
        return revno,result
 
1102
        
 
1103
 
 
1104
    REVISION_NAMESPACES['ancestor:'] = _namespace_ancestor
 
1105
 
1084
1106
    def revision_tree(self, revision_id):
1085
1107
        """Return Tree for a revision on this branch.
1086
1108
 
1518
1540
    br_to.update_revisions(branch_from, stop_revision=revno)
1519
1541
    merge((to_location, -1), (to_location, 0), this_dir=to_location,
1520
1542
          check_clean=False, ignore_zero=True)
1521
 
    
1522
1543
    br_to.set_parent(branch_from.base)
 
1544
    return br_to
 
1545
 
 
1546
def _trim_namespace(namespace, spec):
 
1547
    full_namespace = namespace + ':'
 
1548
    assert spec.startswith(full_namespace)
 
1549
    return spec[len(full_namespace):]