~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Robert Collins
  • Date: 2005-08-25 06:14:17 UTC
  • mto: (974.1.50) (1185.1.10) (1092.3.1)
  • mto: This revision was merged to the branch mainline in revision 1139.
  • Revision ID: robertc@robertcollins.net-20050825061417-3c01eb11acb37ff0
merge from mpool up to rev 1110

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
import bzrlib.ui
35
35
 
36
36
 
 
37
 
37
38
BZR_BRANCH_FORMAT = "Bazaar-NG branch, format 0.0.4\n"
38
39
## TODO: Maybe include checks for common corruption of newlines, etc?
39
40
 
809
810
 
810
811
    def update_revisions(self, other, stop_revision=None):
811
812
        """Pull in all new revisions from other branch.
812
 
        
813
 
        >>> from bzrlib.commit import commit
814
 
        >>> bzrlib.trace.silent = True
815
 
        >>> br1 = ScratchBranch(files=['foo', 'bar'])
816
 
        >>> br1.add('foo')
817
 
        >>> br1.add('bar')
818
 
        >>> commit(br1, "lala!", rev_id="REVISION-ID-1", verbose=False)
819
 
        >>> br2 = ScratchBranch()
820
 
        >>> br2.update_revisions(br1)
821
 
        Added 2 texts.
822
 
        Added 1 inventories.
823
 
        Added 1 revisions.
824
 
        >>> br2.revision_history()
825
 
        [u'REVISION-ID-1']
826
 
        >>> br2.update_revisions(br1)
827
 
        Added 0 texts.
828
 
        Added 0 inventories.
829
 
        Added 0 revisions.
830
 
        >>> br1.text_store.total_size() == br2.text_store.total_size()
831
 
        True
832
813
        """
833
 
        progress = bzrlib.ui.ui_factory.progress_bar()
834
 
        progress.update('comparing histories')
 
814
        from bzrlib.fetch import greedy_fetch
 
815
 
 
816
        pb = bzrlib.ui.ui_factory.progress_bar()
 
817
        pb.update('comparing histories')
 
818
 
835
819
        revision_ids = self.missing_revisions(other, stop_revision)
836
 
        count = self.install_revisions(other, revision_ids, progress=progress)
 
820
 
 
821
        if len(revision_ids) > 0:
 
822
            count = greedy_fetch(self, other, revision_ids[-1], pb)[0]
 
823
        else:
 
824
            count = 0
837
825
        self.append_revision(*revision_ids)
838
 
        print "Added %d revisions." % count
839
 
                    
 
826
        ## note("Added %d revisions." % count)
840
827
 
841
 
    def install_revisions(self, other, revision_ids, progress=None):
 
828
        
 
829
    def install_revisions(self, other, revision_ids, pb):
842
830
        if hasattr(other.revision_store, "prefetch"):
843
831
            other.revision_store.prefetch(revision_ids)
844
832
        if hasattr(other.inventory_store, "prefetch"):
845
833
            inventory_ids = [other.get_revision(r).inventory_id
846
834
                             for r in revision_ids]
847
835
            other.inventory_store.prefetch(inventory_ids)
 
836
 
 
837
        if pb is None:
 
838
            pb = bzrlib.ui.ui_factory.progress_bar()
848
839
                
849
840
        revisions = []
850
841
        needed_texts = set()
851
842
        i = 0
852
 
        for rev_id in revision_ids:
853
 
            i += 1
854
 
            if progress:
855
 
                progress.update('fetching revision', i, len(revision_ids))
856
 
            rev = other.get_revision(rev_id)
 
843
 
 
844
        failures = set()
 
845
        for i, rev_id in enumerate(revision_ids):
 
846
            pb.update('fetching revision', i+1, len(revision_ids))
 
847
            try:
 
848
                rev = other.get_revision(rev_id)
 
849
            except bzrlib.errors.NoSuchRevision:
 
850
                failures.add(rev_id)
 
851
                continue
 
852
 
857
853
            revisions.append(rev)
858
854
            inv = other.get_inventory(str(rev.inventory_id))
859
855
            for key, entry in inv.iter_entries():
862
858
                if entry.text_id not in self.text_store:
863
859
                    needed_texts.add(entry.text_id)
864
860
 
865
 
        if progress:
866
 
            progress.clear()
 
861
        pb.clear()
867
862
                    
868
 
        count = self.text_store.copy_multi(other.text_store, needed_texts)
 
863
        count, cp_fail = self.text_store.copy_multi(other.text_store, 
 
864
                                                    needed_texts)
869
865
        print "Added %d texts." % count 
870
866
        inventory_ids = [ f.inventory_id for f in revisions ]
871
 
        count = self.inventory_store.copy_multi(other.inventory_store, 
872
 
                                                inventory_ids)
 
867
        count, cp_fail = self.inventory_store.copy_multi(other.inventory_store, 
 
868
                                                         inventory_ids)
873
869
        print "Added %d inventories." % count 
874
870
        revision_ids = [ f.revision_id for f in revisions]
875
 
        count = self.revision_store.copy_multi(other.revision_store, 
876
 
                                               revision_ids)
877
 
        return count
 
871
 
 
872
        count, cp_fail = self.revision_store.copy_multi(other.revision_store, 
 
873
                                                          revision_ids,
 
874
                                                          permit_failure=True)
 
875
        assert len(cp_fail) == 0 
 
876
        return count, failures
878
877
       
 
878
 
879
879
    def commit(self, *args, **kw):
880
880
        from bzrlib.commit import commit
881
881
        commit(self, *args, **kw)