~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Robert Collins
  • Date: 2010-05-06 23:54:05 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506235405-wii4elupfhzl3jvy
Add __str__ to the new helper classes.

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