~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Andrew Bennetts
  • Date: 2007-08-30 08:11:54 UTC
  • mfrom: (2766 +trunk)
  • mto: (2535.3.55 repo-refactor)
  • mto: This revision was merged to the branch mainline in revision 2772.
  • Revision ID: andrew.bennetts@canonical.com-20070830081154-16hebp2xwr15x2hc
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
from bzrlib.errors import (BzrError, BzrCheckError, DivergedBranches,
50
50
                           HistoryMissing, InvalidRevisionId,
51
51
                           InvalidRevisionNumber, LockError, NoSuchFile,
52
 
                           NoSuchRevision, NoWorkingTree, NotVersionedError,
 
52
                           NoSuchRevision, NotVersionedError,
53
53
                           NotBranchError, UninitializableFormat,
54
54
                           UnlistableStore, UnlistableBranch,
55
55
                           )
59
59
                                      DEPRECATED_PARAMETER,
60
60
                                      deprecated_passed,
61
61
                                      zero_eight, zero_nine, zero_sixteen,
 
62
                                      zero_ninetyone,
62
63
                                      )
63
64
from bzrlib.trace import mutter, note
64
65
 
116
117
            master.break_lock()
117
118
 
118
119
    @staticmethod
119
 
    @deprecated_method(zero_eight)
120
 
    def open_downlevel(base):
121
 
        """Open a branch which may be of an old format."""
122
 
        return Branch.open(base, _unsupported=True)
123
 
 
124
 
    @staticmethod
125
120
    def open(base, _unsupported=False):
126
121
        """Open the branch rooted at base.
127
122
 
153
148
                                                         possible_transports)
154
149
        return control.open_branch(), relpath
155
150
 
156
 
    @staticmethod
157
 
    @deprecated_function(zero_eight)
158
 
    def initialize(base):
159
 
        """Create a new working tree and branch, rooted at 'base' (url)
160
 
 
161
 
        NOTE: This will soon be deprecated in favour of creation
162
 
        through a BzrDir.
163
 
        """
164
 
        return bzrdir.BzrDir.create_standalone_workingtree(base).branch
165
 
 
166
 
    @deprecated_function(zero_eight)
167
 
    def setup_caching(self, cache_root):
168
 
        """Subclasses that care about caching should override this, and set
169
 
        up cached stores located under cache_root.
170
 
        
171
 
        NOTE: This is unused.
172
 
        """
173
 
        pass
174
 
 
175
151
    def get_config(self):
176
152
        return BranchConfig(self)
177
153
 
376
352
        """Print `file` to stdout."""
377
353
        raise NotImplementedError(self.print_file)
378
354
 
379
 
    def append_revision(self, *revision_ids):
380
 
        raise NotImplementedError(self.append_revision)
381
 
 
382
355
    def set_revision_history(self, rev_history):
383
356
        raise NotImplementedError(self.set_revision_history)
384
357
 
464
437
        if ph:
465
438
            return ph[-1]
466
439
        else:
467
 
            return None
 
440
            return _mod_revision.NULL_REVISION
468
441
 
469
442
    def last_revision_info(self):
470
443
        """Return information about the last revision.
524
497
    def get_rev_id(self, revno, history=None):
525
498
        """Find the revision id of the specified revno."""
526
499
        if revno == 0:
527
 
            return None
 
500
            return _mod_revision.NULL_REVISION
528
501
        if history is None:
529
502
            history = self.revision_history()
530
503
        if revno <= 0 or revno > len(history):
1139
1112
 
1140
1113
 
1141
1114
class BzrBranchFormat6(BzrBranchFormat5):
1142
 
    """Branch format with last-revision
 
1115
    """Branch format with last-revision and tags.
1143
1116
 
1144
1117
    Unlike previous formats, this has no explicit revision history. Instead,
1145
1118
    this just stores the last-revision, and the left-hand history leading
1146
1119
    up to there is the history.
1147
1120
 
1148
1121
    This format was introduced in bzr 0.15
 
1122
    and became the default in 0.91.
1149
1123
    """
1150
1124
 
1151
1125
    def get_format_string(self):
1264
1238
 
1265
1239
# formats which have no format string are not discoverable
1266
1240
# and not independently creatable, so are not registered.
1267
 
__default_format = BzrBranchFormat5()
1268
 
BranchFormat.register_format(__default_format)
 
1241
__format5 = BzrBranchFormat5()
 
1242
__format6 = BzrBranchFormat6()
 
1243
BranchFormat.register_format(__format5)
1269
1244
BranchFormat.register_format(BranchReferenceFormat())
1270
 
BranchFormat.register_format(BzrBranchFormat6())
1271
 
BranchFormat.set_default_format(__default_format)
 
1245
BranchFormat.register_format(__format6)
 
1246
BranchFormat.set_default_format(__format6)
1272
1247
_legacy_formats = [BzrBranchFormat4(),
1273
1248
                   ]
1274
1249
 
1366
1341
        """See Branch.print_file."""
1367
1342
        return self.repository.print_file(file, revision_id)
1368
1343
 
1369
 
    @needs_write_lock
1370
 
    def append_revision(self, *revision_ids):
1371
 
        """See Branch.append_revision."""
1372
 
        revision_ids = [osutils.safe_revision_id(r) for r in revision_ids]
1373
 
        for revision_id in revision_ids:
1374
 
            _mod_revision.check_not_reserved_id(revision_id)
1375
 
            mutter("add {%s} to revision-history" % revision_id)
1376
 
        rev_history = self.revision_history()
1377
 
        rev_history.extend(revision_ids)
1378
 
        self.set_revision_history(rev_history)
1379
 
 
1380
1344
    def _write_revision_history(self, history):
1381
1345
        """Factored out of set_revision_history.
1382
1346
 
1397
1361
 
1398
1362
    @needs_write_lock
1399
1363
    def set_last_revision_info(self, revno, revision_id):
 
1364
        """Set the last revision of this branch.
 
1365
 
 
1366
        The caller is responsible for checking that the revno is correct
 
1367
        for this revision id.
 
1368
 
 
1369
        It may be possible to set the branch last revision to an id not
 
1370
        present in the repository.  However, branches can also be 
 
1371
        configured to check constraints on history, in which case this may not
 
1372
        be permitted.
 
1373
        """
1400
1374
        revision_id = osutils.safe_revision_id(revision_id)
1401
1375
        history = self._lefthand_history(revision_id)
1402
1376
        assert len(history) == revno, '%d != %d' % (len(history), revno)
1475
1449
        """See Branch.basis_tree."""
1476
1450
        return self.repository.revision_tree(self.last_revision())
1477
1451
 
1478
 
    @deprecated_method(zero_eight)
1479
 
    def working_tree(self):
1480
 
        """Create a Working tree object for this branch."""
1481
 
 
1482
 
        from bzrlib.transport.local import LocalTransport
1483
 
        if (self.base.find('://') != -1 or 
1484
 
            not isinstance(self._transport, LocalTransport)):
1485
 
            raise NoWorkingTree(self.base)
1486
 
        return self.bzrdir.open_workingtree()
1487
 
 
1488
1452
    @needs_write_lock
1489
1453
    def pull(self, source, overwrite=False, stop_revision=None,
1490
1454
             _hook_master=None, run_hooks=True):
1672
1636
            assert isinstance(url, str)
1673
1637
            self.control_files.put_bytes('parent', url + '\n')
1674
1638
 
1675
 
    @deprecated_function(zero_nine)
1676
 
    def tree_config(self):
1677
 
        """DEPRECATED; call get_config instead.  
1678
 
        TreeConfig has become part of BranchConfig."""
1679
 
        return TreeConfig(self)
1680
 
 
1681
1639
 
1682
1640
class BzrBranch5(BzrBranch):
1683
1641
    """A format 5 branch. This supports new features over plan branches.
1942
1900
    def last_revision(self):
1943
1901
        """Return last revision id, or None"""
1944
1902
        revision_id = self.last_revision_info()[1]
1945
 
        if revision_id == _mod_revision.NULL_REVISION:
1946
 
            revision_id = None
1947
1903
        return revision_id
1948
1904
 
1949
1905
    def _write_last_revision_info(self, revno, revision_id):
2000
1956
        self._write_last_revision_info(len(history), last_revision)
2001
1957
 
2002
1958
    @needs_write_lock
2003
 
    def append_revision(self, *revision_ids):
2004
 
        revision_ids = [osutils.safe_revision_id(r) for r in revision_ids]
2005
 
        if len(revision_ids) == 0:
2006
 
            return
2007
 
        prev_revno, prev_revision = self.last_revision_info()
2008
 
        for revision in self.repository.get_revisions(revision_ids):
2009
 
            if prev_revision == _mod_revision.NULL_REVISION:
2010
 
                if revision.parent_ids != []:
2011
 
                    raise errors.NotLeftParentDescendant(self, prev_revision,
2012
 
                                                         revision.revision_id)
2013
 
            else:
2014
 
                if revision.parent_ids[0] != prev_revision:
2015
 
                    raise errors.NotLeftParentDescendant(self, prev_revision,
2016
 
                                                         revision.revision_id)
2017
 
            prev_revision = revision.revision_id
2018
 
        self.set_last_revision_info(prev_revno + len(revision_ids),
2019
 
                                    revision_ids[-1])
2020
 
 
2021
 
    @needs_write_lock
2022
1959
    def _set_parent_location(self, url):
2023
1960
        """Set the parent branch"""
2024
1961
        self._set_config_location('parent_location', url, make_relative=True)
2090
2027
        :param revision_id: The revision-id to truncate history at.  May
2091
2028
          be None to copy complete history.
2092
2029
        """
 
2030
        source_revno, source_revision_id = self.last_revision_info()
2093
2031
        if revision_id is None:
2094
 
            revno, revision_id = self.last_revision_info()
 
2032
            revno, revision_id = source_revno, source_revision_id
 
2033
        elif source_revision_id == revision_id:
 
2034
            # we know the revno without needing to walk all of history
 
2035
            revno = source_revno
2095
2036
        else:
2096
2037
            # To figure out the revno for a random revision, we need to build
2097
2038
            # the revision history, and count its length.