~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
294
294
 
295
295
    def revision_history(self):
296
296
        """Return sequence of revision hashes on to this branch."""
297
 
        raise NotImplementedError('revision_history is abstract')
 
297
        raise NotImplementedError(self.revision_history)
298
298
 
299
299
    def revno(self):
300
300
        """Return current revision number for this branch.
617
617
                to_location, force_new_tree=False, format=format)
618
618
            checkout = checkout_branch.bzrdir
619
619
            checkout_branch.bind(self)
620
 
            if revision_id is not None:
621
 
                rh = checkout_branch.revision_history()
622
 
                new_rh = rh[:rh.index(revision_id) + 1]
623
 
                checkout_branch.set_revision_history(new_rh)
 
620
            # pull up to the specified revision_id to set the initial 
 
621
            # branch tip correctly, and seed it with history.
 
622
            checkout_branch.pull(self, stop_revision=revision_id)
624
623
        return checkout.create_workingtree(revision_id)
625
624
 
626
625
 
1186
1185
        try:
1187
1186
            old_count = len(self.revision_history())
1188
1187
            try:
1189
 
                self.update_revisions(source,stop_revision)
 
1188
                self.update_revisions(source, stop_revision)
1190
1189
            except DivergedBranches:
1191
1190
                if not overwrite:
1192
1191
                    raise
1327
1326
 
1328
1327
    @needs_write_lock
1329
1328
    def bind(self, other):
1330
 
        """Bind the local branch the other branch.
 
1329
        """Bind this branch to the branch other.
1331
1330
 
 
1331
        This does not push or pull data between the branches, though it does
 
1332
        check for divergence to raise an error when the branches are not
 
1333
        either the same, or one a prefix of the other. That behaviour may not
 
1334
        be useful, so that check may be removed in future.
 
1335
        
1332
1336
        :param other: The branch to bind to
1333
1337
        :type other: Branch
1334
1338
        """
1339
1343
        #       but binding itself may not be.
1340
1344
        #       Since we *have* to check at commit time, we don't
1341
1345
        #       *need* to check here
1342
 
        self.pull(other)
1343
 
 
1344
 
        # we are now equal to or a suffix of other.
1345
 
 
1346
 
        # Since we have 'pulled' from the remote location,
1347
 
        # now we should try to pull in the opposite direction
1348
 
        # in case the local tree has more revisions than the
1349
 
        # remote one.
1350
 
        # There may be a different check you could do here
1351
 
        # rather than actually trying to install revisions remotely.
1352
 
        # TODO: capture an exception which indicates the remote branch
1353
 
        #       is not writable. 
1354
 
        #       If it is up-to-date, this probably should not be a failure
1355
 
        
1356
 
        # lock other for write so the revision-history syncing cannot race
1357
 
        other.lock_write()
1358
 
        try:
1359
 
            other.pull(self)
1360
 
            # if this does not error, other now has the same last rev we do
1361
 
            # it can only error if the pull from other was concurrent with
1362
 
            # a commit to other from someone else.
1363
 
 
1364
 
            # until we ditch revision-history, we need to sync them up:
1365
 
            self.set_revision_history(other.revision_history())
1366
 
            # now other and self are up to date with each other and have the
1367
 
            # same revision-history.
1368
 
        finally:
1369
 
            other.unlock()
1370
 
 
 
1346
 
 
1347
        # we want to raise diverged if:
 
1348
        # last_rev is not in the other_last_rev history, AND
 
1349
        # other_last_rev is not in our history, and do it without pulling
 
1350
        # history around
 
1351
        last_rev = self.last_revision()
 
1352
        if last_rev is not None:
 
1353
            other.lock_read()
 
1354
            try:
 
1355
                other_last_rev = other.last_revision()
 
1356
                if other_last_rev is not None:
 
1357
                    # neither branch is new, we have to do some work to
 
1358
                    # ascertain diversion.
 
1359
                    remote_graph = other.repository.get_revision_graph(
 
1360
                        other_last_rev)
 
1361
                    local_graph = self.repository.get_revision_graph(last_rev)
 
1362
                    if (last_rev not in remote_graph and
 
1363
                        other_last_rev not in local_graph):
 
1364
                        raise errors.DivergedBranches(self, other)
 
1365
            finally:
 
1366
                other.unlock()
1371
1367
        self.set_bound_location(other.base)
1372
1368
 
1373
1369
    @needs_write_lock