~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Martin Pool
  • Date: 2006-06-20 05:32:16 UTC
  • mfrom: (1797 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1798.
  • Revision ID: mbp@sourcefrog.net-20060620053216-817857d7ca3e9d1f
[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
        urlutils
28
28
from bzrlib.config import TreeConfig
29
29
from bzrlib.decorators import needs_read_lock, needs_write_lock
30
 
from bzrlib.delta import compare_trees
31
 
from bzrlib.errors import (InvalidRevisionNumber,
32
 
                           NotBranchError,
33
 
                           DivergedBranches,
34
 
                           NoSuchFile,
35
 
                           NoWorkingTree)
 
30
import bzrlib.errors as errors
 
31
from bzrlib.errors import (BzrError, BzrCheckError, DivergedBranches, 
 
32
                           HistoryMissing, InvalidRevisionId, 
 
33
                           InvalidRevisionNumber, LockError, NoSuchFile, 
 
34
                           NoSuchRevision, NoWorkingTree, NotVersionedError,
 
35
                           NotBranchError, UninitializableFormat, 
 
36
                           UnlistableStore, UnlistableBranch, 
 
37
                           )
36
38
from bzrlib.lockable_files import LockableFiles, TransportLock
37
39
from bzrlib.symbol_versioning import (deprecated_function,
38
40
                                      deprecated_method,
255
257
        """
256
258
        return None
257
259
 
 
260
    def get_revision_delta(self, revno):
 
261
        """Return the delta for one revision.
 
262
 
 
263
        The delta is relative to its mainline predecessor, or the
 
264
        empty tree for revision 1.
 
265
        """
 
266
        assert isinstance(revno, int)
 
267
        rh = self.revision_history()
 
268
        if not (1 <= revno <= len(rh)):
 
269
            raise InvalidRevisionNumber(revno)
 
270
        return self.repository.get_revision_delta(rh[revno-1])
 
271
 
258
272
    def get_root_id(self):
259
273
        """Return the id of this branches root"""
260
274
        raise NotImplementedError('get_root_id is abstract')
298
312
        
299
313
        If self and other have not diverged, return a list of the revisions
300
314
        present in other, but missing from self.
301
 
 
302
 
        >>> from bzrlib.workingtree import WorkingTree
303
 
        >>> bzrlib.trace.silent = True
304
 
        >>> d1 = bzrdir.ScratchDir()
305
 
        >>> br1 = d1.open_branch()
306
 
        >>> wt1 = d1.open_workingtree()
307
 
        >>> d2 = bzrdir.ScratchDir()
308
 
        >>> br2 = d2.open_branch()
309
 
        >>> wt2 = d2.open_workingtree()
310
 
        >>> br1.missing_revisions(br2)
311
 
        []
312
 
        >>> wt2.commit("lala!", rev_id="REVISION-ID-1")
313
 
        >>> br1.missing_revisions(br2)
314
 
        [u'REVISION-ID-1']
315
 
        >>> br2.missing_revisions(br1)
316
 
        []
317
 
        >>> wt1.commit("lala!", rev_id="REVISION-ID-1")
318
 
        >>> br1.missing_revisions(br2)
319
 
        []
320
 
        >>> wt2.commit("lala!", rev_id="REVISION-ID-2A")
321
 
        >>> br1.missing_revisions(br2)
322
 
        [u'REVISION-ID-2A']
323
 
        >>> wt1.commit("lala!", rev_id="REVISION-ID-2B")
324
 
        >>> br1.missing_revisions(br2)
325
 
        Traceback (most recent call last):
326
 
        DivergedBranches: These branches have diverged.  Try merge.
327
315
        """
328
316
        self_history = self.revision_history()
329
317
        self_len = len(self_history)
600
588
        except NoSuchFile:
601
589
            raise NotBranchError(path=transport.base)
602
590
        except KeyError:
603
 
            raise errors.UnknownFormatError(format_string)
 
591
            raise errors.UnknownFormatError(format=format_string)
604
592
 
605
593
    @classmethod
606
594
    def get_default_format(klass):
900
888
                 stacklevel=2)
901
889
            if (not relax_version_check
902
890
                and not self._format.is_supported()):
903
 
                raise errors.UnsupportedFormatError(
904
 
                        'sorry, branch format %r not supported' % self._format,
905
 
                        ['use a different bzr version',
906
 
                         'or remove the .bzr directory'
907
 
                         ' and "bzr init" again'])
 
891
                raise errors.UnsupportedFormatError(format=fmt)
908
892
        if deprecated_passed(transport):
909
893
            warn("BzrBranch.__init__(transport=XXX...): The transport "
910
894
                 "parameter is deprecated as of bzr 0.8. "
1049
1033
            # not really an object yet, and the transaction is for objects.
1050
1034
            # transaction.register_clean(history)
1051
1035
 
1052
 
    def get_revision_delta(self, revno):
1053
 
        """Return the delta for one revision.
1054
 
 
1055
 
        The delta is relative to its mainline predecessor, or the
1056
 
        empty tree for revision 1.
1057
 
        """
1058
 
        assert isinstance(revno, int)
1059
 
        rh = self.revision_history()
1060
 
        if not (1 <= revno <= len(rh)):
1061
 
            raise InvalidRevisionNumber(revno)
1062
 
 
1063
 
        # revno is 1-based; list is 0-based
1064
 
 
1065
 
        new_tree = self.repository.revision_tree(rh[revno-1])
1066
 
        if revno == 1:
1067
 
            old_tree = tree.EmptyTree()
1068
 
        else:
1069
 
            old_tree = self.repository.revision_tree(rh[revno-2])
1070
 
        return compare_trees(old_tree, new_tree)
1071
 
 
1072
1036
    @needs_read_lock
1073
1037
    def revision_history(self):
1074
1038
        """See Branch.revision_history."""
1132
1096
    @deprecated_method(zero_eight)
1133
1097
    def working_tree(self):
1134
1098
        """Create a Working tree object for this branch."""
 
1099
 
1135
1100
        from bzrlib.transport.local import LocalTransport
1136
1101
        if (self.base.find('://') != -1 or 
1137
1102
            not isinstance(self._transport, LocalTransport)):
1158
1123
 
1159
1124
    def get_parent(self):
1160
1125
        """See Branch.get_parent."""
 
1126
 
1161
1127
        _locs = ['parent', 'pull', 'x-pull']
1162
1128
        assert self.base[-1] == '/'
1163
1129
        for l in _locs:
1164
1130
            try:
1165
 
                return urlutils.join(self.base[:-1],
1166
 
                            self.control_files.get(l).read().strip('\n'))
 
1131
                parent = self.control_files.get(l).read().strip('\n')
1167
1132
            except NoSuchFile:
1168
 
                pass
 
1133
                continue
 
1134
            # This is an old-format absolute path to a local branch
 
1135
            # turn it into a url
 
1136
            if parent.startswith('/'):
 
1137
                parent = urlutils.local_path_to_url(parent.decode('utf8'))
 
1138
            return urlutils.join(self.base[:-1], parent)
1169
1139
        return None
1170
1140
 
1171
1141
    def get_push_location(self):