/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: 2007-08-22 00:00:26 UTC
  • mfrom: (2739 +trunk)
  • mto: (2592.3.96 repository)
  • mto: This revision was merged to the branch mainline in revision 2742.
  • Revision ID: robertc@robertcollins.net-20070822000026-kvufiqhlreokb1en
Merge 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)
1463
1437
            # we fetch here regardless of whether we need to so that we pickup
1464
1438
            # filled in ghosts.
1465
1439
            self.fetch(other, stop_revision)
1466
 
            my_ancestry = self.repository.get_ancestry(last_rev,
1467
 
                                                       topo_sorted=False)
1468
 
            if stop_revision in my_ancestry:
1469
 
                # last_revision is a descendant of stop_revision
 
1440
            if self.repository.get_graph().is_ancestor(stop_revision,
 
1441
                                                       last_rev):
1470
1442
                return
1471
1443
            self.generate_revision_history(stop_revision, last_rev=last_rev,
1472
1444
                other_branch=other)
1477
1449
        """See Branch.basis_tree."""
1478
1450
        return self.repository.revision_tree(self.last_revision())
1479
1451
 
1480
 
    @deprecated_method(zero_eight)
1481
 
    def working_tree(self):
1482
 
        """Create a Working tree object for this branch."""
1483
 
 
1484
 
        from bzrlib.transport.local import LocalTransport
1485
 
        if (self.base.find('://') != -1 or 
1486
 
            not isinstance(self._transport, LocalTransport)):
1487
 
            raise NoWorkingTree(self.base)
1488
 
        return self.bzrdir.open_workingtree()
1489
 
 
1490
1452
    @needs_write_lock
1491
1453
    def pull(self, source, overwrite=False, stop_revision=None,
1492
1454
             _hook_master=None, run_hooks=True):
1674
1636
            assert isinstance(url, str)
1675
1637
            self.control_files.put_bytes('parent', url + '\n')
1676
1638
 
1677
 
    @deprecated_function(zero_nine)
1678
 
    def tree_config(self):
1679
 
        """DEPRECATED; call get_config instead.  
1680
 
        TreeConfig has become part of BranchConfig."""
1681
 
        return TreeConfig(self)
1682
 
 
1683
1639
 
1684
1640
class BzrBranch5(BzrBranch):
1685
1641
    """A format 5 branch. This supports new features over plan branches.
1821
1777
        """
1822
1778
        master = self.get_master_branch()
1823
1779
        if master is not None:
1824
 
            old_tip = self.last_revision()
 
1780
            old_tip = _mod_revision.ensure_null(self.last_revision())
1825
1781
            self.pull(master, overwrite=True)
1826
 
            if old_tip in self.repository.get_ancestry(
1827
 
                _mod_revision.ensure_null(self.last_revision()),
1828
 
                topo_sorted=False):
 
1782
            if self.repository.get_graph().is_ancestor(old_tip,
 
1783
                _mod_revision.ensure_null(self.last_revision())):
1829
1784
                return None
1830
1785
            return old_tip
1831
1786
        return None
1945
1900
    def last_revision(self):
1946
1901
        """Return last revision id, or None"""
1947
1902
        revision_id = self.last_revision_info()[1]
1948
 
        if revision_id == _mod_revision.NULL_REVISION:
1949
 
            revision_id = None
1950
1903
        return revision_id
1951
1904
 
1952
1905
    def _write_last_revision_info(self, revno, revision_id):
2003
1956
        self._write_last_revision_info(len(history), last_revision)
2004
1957
 
2005
1958
    @needs_write_lock
2006
 
    def append_revision(self, *revision_ids):
2007
 
        revision_ids = [osutils.safe_revision_id(r) for r in revision_ids]
2008
 
        if len(revision_ids) == 0:
2009
 
            return
2010
 
        prev_revno, prev_revision = self.last_revision_info()
2011
 
        for revision in self.repository.get_revisions(revision_ids):
2012
 
            if prev_revision == _mod_revision.NULL_REVISION:
2013
 
                if revision.parent_ids != []:
2014
 
                    raise errors.NotLeftParentDescendant(self, prev_revision,
2015
 
                                                         revision.revision_id)
2016
 
            else:
2017
 
                if revision.parent_ids[0] != prev_revision:
2018
 
                    raise errors.NotLeftParentDescendant(self, prev_revision,
2019
 
                                                         revision.revision_id)
2020
 
            prev_revision = revision.revision_id
2021
 
        self.set_last_revision_info(prev_revno + len(revision_ids),
2022
 
                                    revision_ids[-1])
2023
 
 
2024
 
    @needs_write_lock
2025
1959
    def _set_parent_location(self, url):
2026
1960
        """Set the parent branch"""
2027
1961
        self._set_config_location('parent_location', url, make_relative=True)
2093
2027
        :param revision_id: The revision-id to truncate history at.  May
2094
2028
          be None to copy complete history.
2095
2029
        """
 
2030
        source_revno, source_revision_id = self.last_revision_info()
2096
2031
        if revision_id is None:
2097
 
            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
2098
2036
        else:
2099
2037
            # To figure out the revno for a random revision, we need to build
2100
2038
            # the revision history, and count its length.