~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Robert Collins
  • Date: 2010-05-11 08:44:59 UTC
  • mfrom: (5221 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100511084459-pb0uinna9zs3wu59
Merge trunk - resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
from bzrlib.decorators import needs_read_lock, needs_write_lock, only_raises
50
50
from bzrlib.hooks import HookPoint, Hooks
51
51
from bzrlib.inter import InterObject
52
 
from bzrlib.lock import _RelockDebugMixin
 
52
from bzrlib.lock import _RelockDebugMixin, LogicalLockResult
53
53
from bzrlib import registry
54
54
from bzrlib.symbol_versioning import (
55
55
    deprecated_in,
295
295
    def lock_read(self):
296
296
        """Lock the branch for read operations.
297
297
 
298
 
        :return: An object with an unlock method which will release the lock
299
 
            obtained.
 
298
        :return: A bzrlib.lock.LogicalLockResult.
300
299
        """
301
300
        raise NotImplementedError(self.lock_read)
302
301
 
1357
1356
        """
1358
1357
        # XXX: Fix the bzrdir API to allow getting the branch back from the
1359
1358
        # clone call. Or something. 20090224 RBC/spiv.
 
1359
        # XXX: Should this perhaps clone colocated branches as well, 
 
1360
        # rather than just the default branch? 20100319 JRV
1360
1361
        if revision_id is None:
1361
1362
            revision_id = self.last_revision()
1362
1363
        dir_to = self.bzrdir.clone_on_transport(to_transport,
1532
1533
        """Return the current default format."""
1533
1534
        return klass._default_format
1534
1535
 
1535
 
    def get_reference(self, a_bzrdir):
 
1536
    def get_reference(self, a_bzrdir, name=None):
1536
1537
        """Get the target reference of the branch in a_bzrdir.
1537
1538
 
1538
1539
        format probing must have been completed before calling
1540
1541
        in a_bzrdir is correct.
1541
1542
 
1542
1543
        :param a_bzrdir: The bzrdir to get the branch data from.
 
1544
        :param name: Name of the colocated branch to fetch
1543
1545
        :return: None if the branch is not a reference branch.
1544
1546
        """
1545
1547
        return None
1546
1548
 
1547
1549
    @classmethod
1548
 
    def set_reference(self, a_bzrdir, to_branch):
 
1550
    def set_reference(self, a_bzrdir, name, to_branch):
1549
1551
        """Set the target reference of the branch in a_bzrdir.
1550
1552
 
1551
1553
        format probing must have been completed before calling
1553
1555
        in a_bzrdir is correct.
1554
1556
 
1555
1557
        :param a_bzrdir: The bzrdir to set the branch reference for.
 
1558
        :param name: Name of colocated branch to set, None for default
1556
1559
        :param to_branch: branch that the checkout is to reference
1557
1560
        """
1558
1561
        raise NotImplementedError(self.set_reference)
2168
2171
        """See BranchFormat.get_format_description()."""
2169
2172
        return "Checkout reference format 1"
2170
2173
 
2171
 
    def get_reference(self, a_bzrdir):
 
2174
    def get_reference(self, a_bzrdir, name=None):
2172
2175
        """See BranchFormat.get_reference()."""
2173
 
        transport = a_bzrdir.get_branch_transport(None)
 
2176
        transport = a_bzrdir.get_branch_transport(None, name=name)
2174
2177
        return transport.get_bytes('location')
2175
2178
 
2176
 
    def set_reference(self, a_bzrdir, to_branch):
 
2179
    def set_reference(self, a_bzrdir, name, to_branch):
2177
2180
        """See BranchFormat.set_reference()."""
2178
 
        transport = a_bzrdir.get_branch_transport(None)
 
2181
        transport = a_bzrdir.get_branch_transport(None, name=name)
2179
2182
        location = transport.put_bytes('location', to_branch.base)
2180
2183
 
2181
2184
    def initialize(self, a_bzrdir, name=None, target_branch=None):
2232
2235
                raise AssertionError("wrong format %r found for %r" %
2233
2236
                    (format, self))
2234
2237
        if location is None:
2235
 
            location = self.get_reference(a_bzrdir)
 
2238
            location = self.get_reference(a_bzrdir, name)
2236
2239
        real_bzrdir = bzrdir.BzrDir.open(
2237
2240
            location, possible_transports=possible_transports)
2238
2241
        result = real_bzrdir.open_branch(name=name, 
2276
2279
    _legacy_formats[0].network_name(), _legacy_formats[0].__class__)
2277
2280
 
2278
2281
 
2279
 
class BranchWriteLockResult(object):
 
2282
class BranchWriteLockResult(LogicalLockResult):
2280
2283
    """The result of write locking a branch.
2281
2284
 
2282
2285
    :ivar branch_token: The token obtained from the underlying branch lock, or
2285
2288
    """
2286
2289
 
2287
2290
    def __init__(self, unlock, branch_token):
 
2291
        LogicalLockResult.__init__(self, unlock)
2288
2292
        self.branch_token = branch_token
2289
 
        self.unlock = unlock
2290
2293
 
2291
 
    def __str__(self):
 
2294
    def __repr__(self):
2292
2295
        return "BranchWriteLockResult(%s, %s)" % (self.branch_token,
2293
2296
            self.unlock)
2294
2297
 
2379
2382
    def lock_read(self):
2380
2383
        """Lock the branch for read operations.
2381
2384
 
2382
 
        :return: An object with an unlock method which will release the lock
2383
 
            obtained.
 
2385
        :return: A bzrlib.lock.LogicalLockResult.
2384
2386
        """
2385
2387
        if not self.is_locked():
2386
2388
            self._note_lock('r')
2394
2396
            took_lock = False
2395
2397
        try:
2396
2398
            self.control_files.lock_read()
2397
 
            return self
 
2399
            return LogicalLockResult(self.unlock)
2398
2400
        except:
2399
2401
            if took_lock:
2400
2402
                self.repository.unlock()