/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Martin Pool
  • Date: 2005-08-25 08:54:29 UTC
  • Revision ID: mbp@sourcefrog.net-20050825085429-d815c4dcf7cc2067
- fix bad method declaration

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from bzrlib.osutils import isdir, quotefn, compact_date, rand_bytes, \
24
24
     splitpath, \
25
25
     sha_file, appendpath, file_kind
 
26
 
26
27
from bzrlib.errors import BzrError, InvalidRevisionNumber, InvalidRevisionId
27
28
import bzrlib.errors
28
29
from bzrlib.textui import show_status
30
31
from bzrlib.xml import unpack_xml
31
32
from bzrlib.delta import compare_trees
32
33
from bzrlib.tree import EmptyTree, RevisionTree
33
 
        
 
34
import bzrlib.ui
 
35
 
 
36
 
 
37
 
34
38
BZR_BRANCH_FORMAT = "Bazaar-NG branch, format 0.0.4\n"
35
39
## TODO: Maybe include checks for common corruption of newlines, etc?
36
40
 
39
43
# repeatedly to calculate deltas.  We could perhaps have a weakref
40
44
# cache in memory to make this faster.
41
45
 
 
46
# TODO: please move the revision-string syntax stuff out of the branch
 
47
# object; it's clutter
 
48
 
42
49
 
43
50
def find_branch(f, **args):
44
51
    if f and (f.startswith('http://') or f.startswith('https://')):
101
108
    It is not necessary that f exists.
102
109
 
103
110
    Basically we keep looking up until we find the control directory or
104
 
    run into the root."""
 
111
    run into the root.  If there isn't one, raises NotBranchError.
 
112
    """
105
113
    if f == None:
106
114
        f = os.getcwd()
107
115
    elif hasattr(os.path, 'realpath'):
120
128
        head, tail = os.path.split(f)
121
129
        if head == f:
122
130
            # reached the root, whatever that may be
123
 
            raise BzrError('%r is not in a branch' % orig_f)
 
131
            raise bzrlib.errors.NotBranchError('%s is not in a branch' % orig_f)
124
132
        f = head
125
 
    
 
133
 
 
134
 
 
135
 
 
136
# XXX: move into bzrlib.errors; subclass BzrError    
126
137
class DivergedBranches(Exception):
127
138
    def __init__(self, branch1, branch2):
128
139
        self.branch1 = branch1
316
327
            self.controlfile(f, 'w').write('')
317
328
        mutter('created control directory in ' + self.base)
318
329
 
319
 
        pack_xml(Inventory(gen_root_id()), self.controlfile('inventory','w'))
 
330
        # if we want per-tree root ids then this is the place to set
 
331
        # them; they're not needed for now and so ommitted for
 
332
        # simplicity.
 
333
        pack_xml(Inventory(), self.controlfile('inventory','w'))
320
334
 
321
335
 
322
336
    def _check_format(self):
594
608
            try:
595
609
                return self.revision_store[revision_id]
596
610
            except IndexError:
597
 
                raise bzrlib.errors.NoSuchRevision(revision_id)
 
611
                raise bzrlib.errors.NoSuchRevision(self, revision_id)
598
612
        finally:
599
613
            self.unlock()
600
614
 
657
671
        from bzrlib.inventory import Inventory
658
672
        from bzrlib.xml import unpack_xml
659
673
 
660
 
        return unpack_xml(Inventory, self.inventory_store[inventory_id])
 
674
        return unpack_xml(Inventory, self.get_inventory_xml(inventory_id))
 
675
 
 
676
 
 
677
    def get_inventory_xml(self, inventory_id):
 
678
        """Get inventory XML as a file object."""
 
679
        return self.inventory_store[inventory_id]
661
680
            
662
681
 
663
682
    def get_inventory_sha1(self, inventory_id):
664
683
        """Return the sha1 hash of the inventory entry
665
684
        """
666
 
        return sha_file(self.inventory_store[inventory_id])
 
685
        return sha_file(self.get_inventory_xml(inventory_id))
667
686
 
668
687
 
669
688
    def get_revision_inventory(self, revision_id):
755
774
            return None
756
775
 
757
776
 
758
 
    def missing_revisions(self, other, stop_revision=None):
 
777
    def missing_revisions(self, other, stop_revision=None, diverged_ok=False):
759
778
        """
760
779
        If self and other have not diverged, return a list of the revisions
761
780
        present in other, but missing from self.
794
813
        if stop_revision is None:
795
814
            stop_revision = other_len
796
815
        elif stop_revision > other_len:
797
 
            raise NoSuchRevision(self, stop_revision)
 
816
            raise bzrlib.errors.NoSuchRevision(self, stop_revision)
798
817
        
799
818
        return other_history[self_len:stop_revision]
800
819
 
801
820
 
802
821
    def update_revisions(self, other, stop_revision=None):
803
822
        """Pull in all new revisions from other branch.
804
 
        
805
 
        >>> from bzrlib.commit import commit
806
 
        >>> bzrlib.trace.silent = True
807
 
        >>> br1 = ScratchBranch(files=['foo', 'bar'])
808
 
        >>> br1.add('foo')
809
 
        >>> br1.add('bar')
810
 
        >>> commit(br1, "lala!", rev_id="REVISION-ID-1", verbose=False)
811
 
        >>> br2 = ScratchBranch()
812
 
        >>> br2.update_revisions(br1)
813
 
        Added 2 texts.
814
 
        Added 1 inventories.
815
 
        Added 1 revisions.
816
 
        >>> br2.revision_history()
817
 
        [u'REVISION-ID-1']
818
 
        >>> br2.update_revisions(br1)
819
 
        Added 0 texts.
820
 
        Added 0 inventories.
821
 
        Added 0 revisions.
822
 
        >>> br1.text_store.total_size() == br2.text_store.total_size()
823
 
        True
824
823
        """
825
 
        from bzrlib.progress import ProgressBar
826
 
 
827
 
        pb = ProgressBar()
828
 
 
 
824
        from bzrlib.fetch import greedy_fetch
 
825
 
 
826
        pb = bzrlib.ui.ui_factory.progress_bar()
829
827
        pb.update('comparing histories')
 
828
 
830
829
        revision_ids = self.missing_revisions(other, stop_revision)
831
830
 
 
831
        if len(revision_ids) > 0:
 
832
            count = greedy_fetch(self, other, revision_ids[-1], pb)[0]
 
833
        else:
 
834
            count = 0
 
835
        self.append_revision(*revision_ids)
 
836
        ## note("Added %d revisions." % count)
 
837
 
 
838
        
 
839
    def install_revisions(self, other, revision_ids, pb):
832
840
        if hasattr(other.revision_store, "prefetch"):
833
841
            other.revision_store.prefetch(revision_ids)
834
842
        if hasattr(other.inventory_store, "prefetch"):
835
843
            inventory_ids = [other.get_revision(r).inventory_id
836
844
                             for r in revision_ids]
837
845
            other.inventory_store.prefetch(inventory_ids)
 
846
 
 
847
        if pb is None:
 
848
            pb = bzrlib.ui.ui_factory.progress_bar()
838
849
                
839
850
        revisions = []
840
851
        needed_texts = set()
841
852
        i = 0
842
 
        for rev_id in revision_ids:
843
 
            i += 1
844
 
            pb.update('fetching revision', i, len(revision_ids))
845
 
            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
 
846
863
            revisions.append(rev)
847
864
            inv = other.get_inventory(str(rev.inventory_id))
848
865
            for key, entry in inv.iter_entries():
853
870
 
854
871
        pb.clear()
855
872
                    
856
 
        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)
857
875
        print "Added %d texts." % count 
858
876
        inventory_ids = [ f.inventory_id for f in revisions ]
859
 
        count = self.inventory_store.copy_multi(other.inventory_store, 
860
 
                                                inventory_ids)
 
877
        count, cp_fail = self.inventory_store.copy_multi(other.inventory_store, 
 
878
                                                         inventory_ids)
861
879
        print "Added %d inventories." % count 
862
880
        revision_ids = [ f.revision_id for f in revisions]
863
 
        count = self.revision_store.copy_multi(other.revision_store, 
864
 
                                               revision_ids)
865
 
        for revision_id in revision_ids:
866
 
            self.append_revision(revision_id)
867
 
        print "Added %d revisions." % count
868
 
                    
869
 
        
 
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
 
887
       
 
888
 
870
889
    def commit(self, *args, **kw):
871
890
        from bzrlib.commit import commit
872
891
        commit(self, *args, **kw)
877
896
        revno, info = self.get_revision_info(revision)
878
897
        return info
879
898
 
 
899
 
 
900
    def revision_id_to_revno(self, revision_id):
 
901
        """Given a revision id, return its revno"""
 
902
        history = self.revision_history()
 
903
        try:
 
904
            return history.index(revision_id) + 1
 
905
        except ValueError:
 
906
            raise bzrlib.errors.NoSuchRevision(self, revision_id)
 
907
 
 
908
 
880
909
    def get_revision_info(self, revision):
881
910
        """Return (revno, revision id) for revision identifier.
882
911