~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Martin Pool
  • Date: 2005-08-01 20:10:24 UTC
  • Revision ID: mbp@sourcefrog.net-20050801201024-51c865a893c759fa
- some cleanup of log code to have less special cases

- still some trouble caused by need for EmptyTree to have a root id

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from bzrlib.textui import show_status
28
28
from bzrlib.revision import Revision
29
29
from bzrlib.xml import unpack_xml
30
 
 
 
30
from bzrlib.delta import compare_trees
 
31
from bzrlib.tree import EmptyTree, RevisionTree
31
32
        
32
33
BZR_BRANCH_FORMAT = "Bazaar-NG branch, format 0.0.4\n"
33
34
## TODO: Maybe include checks for common corruption of newlines, etc?
612
613
        """
613
614
        assert isinstance(revno, int)
614
615
        rh = self.revision_history()
615
 
        if revno <= 0 or revno >= len(rh):
 
616
        if not (1 <= revno <= len(rh)):
616
617
            raise InvalidRevisionNumber(revno)
617
618
 
618
 
        new_tree = self.revision_tree(rh[revno])
619
 
        if revno == 0:
 
619
        # revno is 1-based; list is 0-based
 
620
 
 
621
        new_tree = self.revision_tree(rh[revno-1])
 
622
        if revno == 1:
620
623
            old_tree = EmptyTree()
621
624
        else:
622
 
            old_tree = self.revision_tree(rh[revno-1])
 
625
            old_tree = self.revision_tree(rh[revno-2])
623
626
 
624
627
        return compare_trees(old_tree, new_tree)
625
628
 
723
726
                return r+1, my_history[r]
724
727
        return None, None
725
728
 
726
 
    def enum_history(self, direction):
727
 
        """Return (revno, revision_id) for history of branch.
728
 
 
729
 
        direction
730
 
            'forward' is from earliest to latest
731
 
            'reverse' is from latest to earliest
732
 
        """
733
 
        rh = self.revision_history()
734
 
        if direction == 'forward':
735
 
            i = 1
736
 
            for rid in rh:
737
 
                yield i, rid
738
 
                i += 1
739
 
        elif direction == 'reverse':
740
 
            i = len(rh)
741
 
            while i > 0:
742
 
                yield i, rh[i-1]
743
 
                i -= 1
744
 
        else:
745
 
            raise ValueError('invalid history direction', direction)
746
 
 
747
729
 
748
730
    def revno(self):
749
731
        """Return current revision number for this branch.
1044
1026
 
1045
1027
        `revision_id` may be None for the null revision, in which case
1046
1028
        an `EmptyTree` is returned."""
1047
 
        from bzrlib.tree import EmptyTree, RevisionTree
1048
1029
        # TODO: refactor this to use an existing revision object
1049
1030
        # so we don't need to read it in twice.
1050
1031
        if revision_id == None:
1065
1046
 
1066
1047
        If there are no revisions yet, return an `EmptyTree`.
1067
1048
        """
1068
 
        from bzrlib.tree import EmptyTree, RevisionTree
1069
1049
        r = self.last_patch()
1070
1050
        if r == None:
1071
1051
            return EmptyTree(self.get_root_id())