/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: Lukáš Lalinský
  • Date: 2007-12-17 17:28:25 UTC
  • mfrom: (3120 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3123.
  • Revision ID: lalinsky@gmail.com-20071217172825-tr3pqm1mhvs3gwnn
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
425
425
        That is equivalent to the number of revisions committed to
426
426
        this branch.
427
427
        """
428
 
        return len(self.revision_history())
 
428
        return self.last_revision_info()[0]
429
429
 
430
430
    def unbind(self):
431
431
        """Older format branches cannot bind or unbind."""
771
771
        if lightweight:
772
772
            format = self._get_checkout_format()
773
773
            checkout = format.initialize_on_transport(t)
774
 
            BranchReferenceFormat().initialize(checkout, self)
 
774
            from_branch = BranchReferenceFormat().initialize(checkout, self)
775
775
        else:
776
776
            format = self._get_checkout_format()
777
777
            checkout_branch = bzrdir.BzrDir.create_branch_convenience(
781
781
            # pull up to the specified revision_id to set the initial 
782
782
            # branch tip correctly, and seed it with history.
783
783
            checkout_branch.pull(self, stop_revision=revision_id)
784
 
        tree = checkout.create_workingtree(revision_id)
 
784
            from_branch=None
 
785
        tree = checkout.create_workingtree(revision_id,
 
786
                                           from_branch=from_branch)
785
787
        basis_tree = tree.basis_tree()
786
788
        basis_tree.lock_read()
787
789
        try:
866
868
        """
867
869
        return None
868
870
 
 
871
    @classmethod
 
872
    def set_reference(self, a_bzrdir, to_branch):
 
873
        """Set the target reference of the branch in a_bzrdir.
 
874
 
 
875
        format probing must have been completed before calling
 
876
        this method - it is assumed that the format of the branch
 
877
        in a_bzrdir is correct.
 
878
 
 
879
        :param a_bzrdir: The bzrdir to set the branch reference for.
 
880
        :param to_branch: branch that the checkout is to reference
 
881
        """
 
882
        raise NotImplementedError(self.set_reference)
 
883
 
869
884
    def get_format_string(self):
870
885
        """Return the ASCII format string that identifies this format."""
871
886
        raise NotImplementedError(self.get_format_string)
1146
1161
    def initialize(self, a_bzrdir):
1147
1162
        """Create a branch of this format in a_bzrdir."""
1148
1163
        utf8_files = [('last-revision', '0 null:\n'),
1149
 
                      ('branch-name', ''),
1150
1164
                      ('branch.conf', ''),
1151
1165
                      ('tags', ''),
1152
1166
                      ]
1191
1205
    def get_format_description(self):
1192
1206
        """See BranchFormat.get_format_description()."""
1193
1207
        return "Checkout reference format 1"
1194
 
        
 
1208
 
1195
1209
    def get_reference(self, a_bzrdir):
1196
1210
        """See BranchFormat.get_reference()."""
1197
1211
        transport = a_bzrdir.get_branch_transport(None)
1198
1212
        return transport.get('location').read()
1199
1213
 
 
1214
    def set_reference(self, a_bzrdir, to_branch):
 
1215
        """See BranchFormat.set_reference()."""
 
1216
        transport = a_bzrdir.get_branch_transport(None)
 
1217
        location = transport.put_bytes('location', to_branch.base)
 
1218
 
1200
1219
    def initialize(self, a_bzrdir, target_branch=None):
1201
1220
        """Create a branch of this format in a_bzrdir."""
1202
1221
        if target_branch is None:
1208
1227
        branch_transport.put_bytes('location',
1209
1228
            target_branch.bzrdir.root_transport.base)
1210
1229
        branch_transport.put_bytes('format', self.get_format_string())
1211
 
        return self.open(a_bzrdir, _found=True)
 
1230
        return self.open(
 
1231
            a_bzrdir, _found=True,
 
1232
            possible_transports=[target_branch.bzrdir.root_transport])
1212
1233
 
1213
1234
    def __init__(self):
1214
1235
        super(BranchReferenceFormat, self).__init__()
1224
1245
            # emit some sort of warning/error to the caller ?!
1225
1246
        return clone
1226
1247
 
1227
 
    def open(self, a_bzrdir, _found=False, location=None):
 
1248
    def open(self, a_bzrdir, _found=False, location=None,
 
1249
             possible_transports=None):
1228
1250
        """Return the branch that the branch reference in a_bzrdir points at.
1229
1251
 
1230
1252
        _found is a private parameter, do not use it. It is used to indicate
1235
1257
            assert format.__class__ == self.__class__
1236
1258
        if location is None:
1237
1259
            location = self.get_reference(a_bzrdir)
1238
 
        real_bzrdir = bzrdir.BzrDir.open(location)
 
1260
        real_bzrdir = bzrdir.BzrDir.open(
 
1261
            location, possible_transports=possible_transports)
1239
1262
        result = real_bzrdir.open_branch()
1240
1263
        # this changes the behaviour of result.clone to create a new reference
1241
1264
        # rather than a copy of the content of the branch.
1308
1331
    def get_root_id(self):
1309
1332
        """See Branch.get_root_id."""
1310
1333
        tree = self.repository.revision_tree(self.last_revision())
1311
 
        return tree.inventory.root.file_id
 
1334
        return tree.get_root_id()
1312
1335
 
1313
1336
    def is_locked(self):
1314
1337
        return self.control_files.is_locked()
1434
1457
            last_rev, other_branch))
1435
1458
 
1436
1459
    @needs_write_lock
1437
 
    def update_revisions(self, other, stop_revision=None):
 
1460
    def update_revisions(self, other, stop_revision=None, overwrite=False):
1438
1461
        """See Branch.update_revisions."""
1439
1462
        other.lock_read()
1440
1463
        try:
 
1464
            other_last_revno, other_last_revision = other.last_revision_info()
1441
1465
            if stop_revision is None:
1442
 
                stop_revision = other.last_revision()
1443
 
                if stop_revision is None:
 
1466
                stop_revision = other_last_revision
 
1467
                if _mod_revision.is_null(stop_revision):
1444
1468
                    # if there are no commits, we're done.
1445
1469
                    return
1446
1470
            # whats the current last revision, before we fetch [and change it
1451
1475
            # already merged can operate on the just fetched graph, which will
1452
1476
            # be cached in memory.
1453
1477
            self.fetch(other, stop_revision)
1454
 
            if self.repository.get_graph().is_ancestor(stop_revision,
1455
 
                                                       last_rev):
1456
 
                return
1457
 
            self.generate_revision_history(stop_revision, last_rev=last_rev,
1458
 
                other_branch=other)
 
1478
            # Check to see if one is an ancestor of the other
 
1479
            if not overwrite:
 
1480
                heads = self.repository.get_graph().heads([stop_revision,
 
1481
                                                           last_rev])
 
1482
                if heads == set([last_rev]):
 
1483
                    # The current revision is a decendent of the target,
 
1484
                    # nothing to do
 
1485
                    return
 
1486
                elif heads == set([stop_revision, last_rev]):
 
1487
                    # These branches have diverged
 
1488
                    raise errors.DivergedBranches(self, other)
 
1489
                assert heads == set([stop_revision])
 
1490
            if other_last_revision == stop_revision:
 
1491
                self.set_last_revision_info(other_last_revno,
 
1492
                                            other_last_revision)
 
1493
            else:
 
1494
                # TODO: jam 2007-11-29 Is there a way to determine the
 
1495
                #       revno without searching all of history??
 
1496
                if overwrite:
 
1497
                    self.generate_revision_history(stop_revision)
 
1498
                else:
 
1499
                    self.generate_revision_history(stop_revision,
 
1500
                        last_rev=last_rev, other_branch=other)
1459
1501
        finally:
1460
1502
            other.unlock()
1461
1503
 
1480
1522
        source.lock_read()
1481
1523
        try:
1482
1524
            result.old_revno, result.old_revid = self.last_revision_info()
1483
 
            try:
1484
 
                self.update_revisions(source, stop_revision)
1485
 
            except DivergedBranches:
1486
 
                if not overwrite:
1487
 
                    raise
1488
 
            if overwrite:
1489
 
                if stop_revision is None:
1490
 
                    stop_revision = source.last_revision()
1491
 
                self.generate_revision_history(stop_revision)
 
1525
            self.update_revisions(source, stop_revision, overwrite=overwrite)
1492
1526
            result.tag_conflicts = source.tags.merge_to(self.tags, overwrite)
1493
1527
            result.new_revno, result.new_revid = self.last_revision_info()
1494
1528
            if _hook_master:
1760
1794
        # last_rev is not in the other_last_rev history, AND
1761
1795
        # other_last_rev is not in our history, and do it without pulling
1762
1796
        # history around
1763
 
        last_rev = _mod_revision.ensure_null(self.last_revision())
1764
 
        if last_rev != _mod_revision.NULL_REVISION:
1765
 
            other.lock_read()
1766
 
            try:
1767
 
                other_last_rev = other.last_revision()
1768
 
                if not _mod_revision.is_null(other_last_rev):
1769
 
                    # neither branch is new, we have to do some work to
1770
 
                    # ascertain diversion.
1771
 
                    remote_graph = other.repository.get_revision_graph(
1772
 
                        other_last_rev)
1773
 
                    local_graph = self.repository.get_revision_graph(last_rev)
1774
 
                    if (last_rev not in remote_graph and
1775
 
                        other_last_rev not in local_graph):
1776
 
                        raise errors.DivergedBranches(self, other)
1777
 
            finally:
1778
 
                other.unlock()
1779
1797
        self.set_bound_location(other.base)
1780
1798
 
1781
1799
    @needs_write_lock
1844
1862
        return None
1845
1863
 
1846
1864
    @classmethod
 
1865
    def set_reference(self, a_bzrdir, to_branch):
 
1866
        """Set the target reference of the branch in a_bzrdir.
 
1867
 
 
1868
        format probing must have been completed before calling
 
1869
        this method - it is assumed that the format of the branch
 
1870
        in a_bzrdir is correct.
 
1871
 
 
1872
        :param a_bzrdir: The bzrdir to set the branch reference for.
 
1873
        :param to_branch: branch that the checkout is to reference
 
1874
        """
 
1875
        raise NotImplementedError(self.set_reference)
 
1876
 
 
1877
    @classmethod
1847
1878
    def _initialize_control_files(cls, a_bzrdir, utf8_files, lock_filename,
1848
1879
            lock_class):
1849
1880
        branch_transport = a_bzrdir.get_branch_transport(cls)