~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Martin Pool
  • Date: 2005-08-25 05:58:05 UTC
  • mfrom: (974.1.36)
  • Revision ID: mbp@sourcefrog.net-20050825055805-8c892bc3c2d75131
- merge aaron's merge improvements:

  * When merging, pull in all missing revisions from the source
    branch. 

  * Detect common ancestors by looking at the whole ancestry graph, 
    rather than just mainline history.

  Some changes to reconcile this with parallel updates to the test and
  trace code.

aaron.bentley@utoronto.ca-20050823052551-f3401a8b57d9126f

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
 
819
820
 
820
821
    def update_revisions(self, other, stop_revision=None):
821
822
        """Pull in all new revisions from other branch.
822
 
        
823
 
        >>> from bzrlib.commit import commit
824
 
        >>> bzrlib.trace.silent = True
825
 
        >>> br1 = ScratchBranch(files=['foo', 'bar'])
826
 
        >>> br1.add('foo')
827
 
        >>> br1.add('bar')
828
 
        >>> commit(br1, "lala!", rev_id="REVISION-ID-1", verbose=False)
829
 
        >>> br2 = ScratchBranch()
830
 
        >>> br2.update_revisions(br1)
831
 
        Added 2 texts.
832
 
        Added 1 inventories.
833
 
        Added 1 revisions.
834
 
        >>> br2.revision_history()
835
 
        [u'REVISION-ID-1']
836
 
        >>> br2.update_revisions(br1)
837
 
        Added 0 texts.
838
 
        Added 0 inventories.
839
 
        Added 0 revisions.
840
 
        >>> br1.text_store.total_size() == br2.text_store.total_size()
841
 
        True
842
823
        """
843
 
        progress = bzrlib.ui.ui_factory.progress_bar()
844
 
        progress.update('comparing histories')
 
824
        from bzrlib.fetch import greedy_fetch
 
825
 
 
826
        pb = bzrlib.ui.ui_factory.progress_bar()
 
827
        pb.update('comparing histories')
 
828
 
845
829
        revision_ids = self.missing_revisions(other, stop_revision)
846
 
        count = self.install_revisions(other, revision_ids, progress=progress)
 
830
 
 
831
        if len(revision_ids) > 0:
 
832
            count = greedy_fetch(self, other, revision_ids[-1], pb)[0]
 
833
        else:
 
834
            count = 0
847
835
        self.append_revision(*revision_ids)
848
 
        print "Added %d revisions." % count
849
 
                    
 
836
        ## note("Added %d revisions." % count)
850
837
 
851
 
    def install_revisions(self, other, revision_ids, progress=None):
 
838
        
 
839
    def install_revisions(self, other, revision_ids, pb):
852
840
        if hasattr(other.revision_store, "prefetch"):
853
841
            other.revision_store.prefetch(revision_ids)
854
842
        if hasattr(other.inventory_store, "prefetch"):
855
843
            inventory_ids = [other.get_revision(r).inventory_id
856
844
                             for r in revision_ids]
857
845
            other.inventory_store.prefetch(inventory_ids)
 
846
 
 
847
        if pb is None:
 
848
            pb = bzrlib.ui.ui_factory.progress_bar()
858
849
                
859
850
        revisions = []
860
851
        needed_texts = set()
861
852
        i = 0
862
 
        for rev_id in revision_ids:
863
 
            i += 1
864
 
            if progress:
865
 
                progress.update('fetching revision', i, len(revision_ids))
866
 
            rev = other.get_revision(rev_id)
 
853
 
 
854
        failures = set()
 
855
        for i, rev_id in enumerate(revision_ids):
 
856
            pb.update('fetching revision', i+1, len(revision_ids))
 
857
            try:
 
858
                rev = other.get_revision(rev_id)
 
859
            except bzrlib.errors.NoSuchRevision:
 
860
                failures.add(rev_id)
 
861
                continue
 
862
 
867
863
            revisions.append(rev)
868
864
            inv = other.get_inventory(str(rev.inventory_id))
869
865
            for key, entry in inv.iter_entries():
872
868
                if entry.text_id not in self.text_store:
873
869
                    needed_texts.add(entry.text_id)
874
870
 
875
 
        if progress:
876
 
            progress.clear()
 
871
        pb.clear()
877
872
                    
878
 
        count = self.text_store.copy_multi(other.text_store, needed_texts)
 
873
        count, cp_fail = self.text_store.copy_multi(other.text_store, 
 
874
                                                    needed_texts)
879
875
        print "Added %d texts." % count 
880
876
        inventory_ids = [ f.inventory_id for f in revisions ]
881
 
        count = self.inventory_store.copy_multi(other.inventory_store, 
882
 
                                                inventory_ids)
 
877
        count, cp_fail = self.inventory_store.copy_multi(other.inventory_store, 
 
878
                                                         inventory_ids)
883
879
        print "Added %d inventories." % count 
884
880
        revision_ids = [ f.revision_id for f in revisions]
885
 
        count = self.revision_store.copy_multi(other.revision_store, 
886
 
                                               revision_ids)
887
 
        return count
 
881
 
 
882
        count, cp_fail = self.revision_store.copy_multi(other.revision_store, 
 
883
                                                          revision_ids,
 
884
                                                          permit_failure=True)
 
885
        assert len(cp_fail) == 0 
 
886
        return count, failures
888
887
       
 
888
 
889
889
    def commit(self, *args, **kw):
890
890
        from bzrlib.commit import commit
891
891
        commit(self, *args, **kw)