/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: Robert Collins
  • Date: 2005-08-24 08:34:10 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-20050824083410-98aa4eeb52653394
import and use TestUtil to do regex based partial test runs

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
from bzrlib.progress import ProgressBar
 
35
 
34
36
BZR_BRANCH_FORMAT = "Bazaar-NG branch, format 0.0.4\n"
35
37
## TODO: Maybe include checks for common corruption of newlines, etc?
36
38
 
39
41
# repeatedly to calculate deltas.  We could perhaps have a weakref
40
42
# cache in memory to make this faster.
41
43
 
 
44
# TODO: please move the revision-string syntax stuff out of the branch
 
45
# object; it's clutter
 
46
 
42
47
 
43
48
def find_branch(f, **args):
44
49
    if f and (f.startswith('http://') or f.startswith('https://')):
101
106
    It is not necessary that f exists.
102
107
 
103
108
    Basically we keep looking up until we find the control directory or
104
 
    run into the root."""
 
109
    run into the root.  If there isn't one, raises NotBranchError.
 
110
    """
105
111
    if f == None:
106
112
        f = os.getcwd()
107
113
    elif hasattr(os.path, 'realpath'):
120
126
        head, tail = os.path.split(f)
121
127
        if head == f:
122
128
            # reached the root, whatever that may be
123
 
            raise BzrError('%r is not in a branch' % orig_f)
 
129
            raise bzrlib.errors.NotBranchError('%s is not in a branch' % orig_f)
124
130
        f = head
125
 
    
 
131
 
 
132
 
 
133
 
 
134
# XXX: move into bzrlib.errors; subclass BzrError    
126
135
class DivergedBranches(Exception):
127
136
    def __init__(self, branch1, branch2):
128
137
        self.branch1 = branch1
316
325
            self.controlfile(f, 'w').write('')
317
326
        mutter('created control directory in ' + self.base)
318
327
 
319
 
        pack_xml(Inventory(gen_root_id()), self.controlfile('inventory','w'))
 
328
        # if we want per-tree root ids then this is the place to set
 
329
        # them; they're not needed for now and so ommitted for
 
330
        # simplicity.
 
331
        pack_xml(Inventory(), self.controlfile('inventory','w'))
320
332
 
321
333
 
322
334
    def _check_format(self):
594
606
            try:
595
607
                return self.revision_store[revision_id]
596
608
            except IndexError:
597
 
                raise bzrlib.errors.NoSuchRevision(revision_id)
 
609
                raise bzrlib.errors.NoSuchRevision(self, revision_id)
598
610
        finally:
599
611
            self.unlock()
600
612
 
657
669
        from bzrlib.inventory import Inventory
658
670
        from bzrlib.xml import unpack_xml
659
671
 
660
 
        return unpack_xml(Inventory, self.inventory_store[inventory_id])
 
672
        return unpack_xml(Inventory, self.get_inventory_xml(inventory_id))
 
673
 
 
674
 
 
675
    def get_inventory_xml(self, inventory_id):
 
676
        """Get inventory XML as a file object."""
 
677
        return self.inventory_store[inventory_id]
661
678
            
662
679
 
663
680
    def get_inventory_sha1(self, inventory_id):
664
681
        """Return the sha1 hash of the inventory entry
665
682
        """
666
 
        return sha_file(self.inventory_store[inventory_id])
 
683
        return sha_file(self.get_inventory_xml(inventory_id))
667
684
 
668
685
 
669
686
    def get_revision_inventory(self, revision_id):
755
772
            return None
756
773
 
757
774
 
758
 
    def missing_revisions(self, other, stop_revision=None):
 
775
    def missing_revisions(self, other, stop_revision=None, diverged_ok=False):
759
776
        """
760
777
        If self and other have not diverged, return a list of the revisions
761
778
        present in other, but missing from self.
794
811
        if stop_revision is None:
795
812
            stop_revision = other_len
796
813
        elif stop_revision > other_len:
797
 
            raise NoSuchRevision(self, stop_revision)
 
814
            raise bzrlib.errors.NoSuchRevision(self, stop_revision)
798
815
        
799
816
        return other_history[self_len:stop_revision]
800
817
 
822
839
        >>> br1.text_store.total_size() == br2.text_store.total_size()
823
840
        True
824
841
        """
825
 
        from bzrlib.progress import ProgressBar
826
 
 
827
842
        pb = ProgressBar()
828
 
 
829
843
        pb.update('comparing histories')
830
844
        revision_ids = self.missing_revisions(other, stop_revision)
831
 
 
 
845
        count = self.install_revisions(other, revision_ids, pb=pb)
 
846
        self.append_revision(*revision_ids)
 
847
        print "Added %d revisions." % count
 
848
                    
 
849
    def install_revisions(self, other, revision_ids, pb=None):
 
850
        if pb is None:
 
851
            pb = ProgressBar()
832
852
        if hasattr(other.revision_store, "prefetch"):
833
853
            other.revision_store.prefetch(revision_ids)
834
854
        if hasattr(other.inventory_store, "prefetch"):
862
882
        revision_ids = [ f.revision_id for f in revisions]
863
883
        count = self.revision_store.copy_multi(other.revision_store, 
864
884
                                               revision_ids)
865
 
        for revision_id in revision_ids:
866
 
            self.append_revision(revision_id)
867
 
        print "Added %d revisions." % count
868
 
                    
869
 
        
 
885
        return count
 
886
       
870
887
    def commit(self, *args, **kw):
871
888
        from bzrlib.commit import commit
872
889
        commit(self, *args, **kw)