/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: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

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,
283
283
        new_history.reverse()
284
284
        return new_history
285
285
 
286
 
    def lock_write(self, token=None):
287
 
        """Lock the branch for write operations.
288
 
 
289
 
        :param token: A token to permit reacquiring a previously held and
290
 
            preserved lock.
291
 
        :return: A BranchWriteLockResult.
292
 
        """
 
286
    def lock_write(self):
293
287
        raise NotImplementedError(self.lock_write)
294
288
 
295
289
    def lock_read(self):
296
 
        """Lock the branch for read operations.
297
 
 
298
 
        :return: A bzrlib.lock.LogicalLockResult.
299
 
        """
300
290
        raise NotImplementedError(self.lock_read)
301
291
 
302
292
    def unlock(self):
1356
1346
        """
1357
1347
        # XXX: Fix the bzrdir API to allow getting the branch back from the
1358
1348
        # 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
1349
        if revision_id is None:
1362
1350
            revision_id = self.last_revision()
1363
1351
        dir_to = self.bzrdir.clone_on_transport(to_transport,
1533
1521
        """Return the current default format."""
1534
1522
        return klass._default_format
1535
1523
 
1536
 
    def get_reference(self, a_bzrdir, name=None):
 
1524
    def get_reference(self, a_bzrdir):
1537
1525
        """Get the target reference of the branch in a_bzrdir.
1538
1526
 
1539
1527
        format probing must have been completed before calling
1541
1529
        in a_bzrdir is correct.
1542
1530
 
1543
1531
        :param a_bzrdir: The bzrdir to get the branch data from.
1544
 
        :param name: Name of the colocated branch to fetch
1545
1532
        :return: None if the branch is not a reference branch.
1546
1533
        """
1547
1534
        return None
1548
1535
 
1549
1536
    @classmethod
1550
 
    def set_reference(self, a_bzrdir, name, to_branch):
 
1537
    def set_reference(self, a_bzrdir, to_branch):
1551
1538
        """Set the target reference of the branch in a_bzrdir.
1552
1539
 
1553
1540
        format probing must have been completed before calling
1555
1542
        in a_bzrdir is correct.
1556
1543
 
1557
1544
        :param a_bzrdir: The bzrdir to set the branch reference for.
1558
 
        :param name: Name of colocated branch to set, None for default
1559
1545
        :param to_branch: branch that the checkout is to reference
1560
1546
        """
1561
1547
        raise NotImplementedError(self.set_reference)
2171
2157
        """See BranchFormat.get_format_description()."""
2172
2158
        return "Checkout reference format 1"
2173
2159
 
2174
 
    def get_reference(self, a_bzrdir, name=None):
 
2160
    def get_reference(self, a_bzrdir):
2175
2161
        """See BranchFormat.get_reference()."""
2176
 
        transport = a_bzrdir.get_branch_transport(None, name=name)
 
2162
        transport = a_bzrdir.get_branch_transport(None)
2177
2163
        return transport.get_bytes('location')
2178
2164
 
2179
 
    def set_reference(self, a_bzrdir, name, to_branch):
 
2165
    def set_reference(self, a_bzrdir, to_branch):
2180
2166
        """See BranchFormat.set_reference()."""
2181
 
        transport = a_bzrdir.get_branch_transport(None, name=name)
 
2167
        transport = a_bzrdir.get_branch_transport(None)
2182
2168
        location = transport.put_bytes('location', to_branch.base)
2183
2169
 
2184
2170
    def initialize(self, a_bzrdir, name=None, target_branch=None):
2235
2221
                raise AssertionError("wrong format %r found for %r" %
2236
2222
                    (format, self))
2237
2223
        if location is None:
2238
 
            location = self.get_reference(a_bzrdir, name)
 
2224
            location = self.get_reference(a_bzrdir)
2239
2225
        real_bzrdir = bzrdir.BzrDir.open(
2240
2226
            location, possible_transports=possible_transports)
2241
2227
        result = real_bzrdir.open_branch(name=name, 
2279
2265
    _legacy_formats[0].network_name(), _legacy_formats[0].__class__)
2280
2266
 
2281
2267
 
2282
 
class BranchWriteLockResult(LogicalLockResult):
2283
 
    """The result of write locking a branch.
2284
 
 
2285
 
    :ivar branch_token: The token obtained from the underlying branch lock, or
2286
 
        None.
2287
 
    :ivar unlock: A callable which will unlock the lock.
2288
 
    """
2289
 
 
2290
 
    def __init__(self, unlock, branch_token):
2291
 
        LogicalLockResult.__init__(self, unlock)
2292
 
        self.branch_token = branch_token
2293
 
 
2294
 
    def __repr__(self):
2295
 
        return "BranchWriteLockResult(%s, %s)" % (self.branch_token,
2296
 
            self.unlock)
2297
 
 
2298
 
 
2299
2268
class BzrBranch(Branch, _RelockDebugMixin):
2300
2269
    """A branch stored in the actual filesystem.
2301
2270
 
2355
2324
        return self.control_files.is_locked()
2356
2325
 
2357
2326
    def lock_write(self, token=None):
2358
 
        """Lock the branch for write operations.
2359
 
 
2360
 
        :param token: A token to permit reacquiring a previously held and
2361
 
            preserved lock.
2362
 
        :return: A BranchWriteLockResult.
2363
 
        """
2364
2327
        if not self.is_locked():
2365
2328
            self._note_lock('w')
2366
2329
        # All-in-one needs to always unlock/lock.
2372
2335
        else:
2373
2336
            took_lock = False
2374
2337
        try:
2375
 
            return BranchWriteLockResult(self.unlock,
2376
 
                self.control_files.lock_write(token=token))
 
2338
            return self.control_files.lock_write(token=token)
2377
2339
        except:
2378
2340
            if took_lock:
2379
2341
                self.repository.unlock()
2380
2342
            raise
2381
2343
 
2382
2344
    def lock_read(self):
2383
 
        """Lock the branch for read operations.
2384
 
 
2385
 
        :return: A bzrlib.lock.LogicalLockResult.
2386
 
        """
2387
2345
        if not self.is_locked():
2388
2346
            self._note_lock('r')
2389
2347
        # All-in-one needs to always unlock/lock.
2396
2354
            took_lock = False
2397
2355
        try:
2398
2356
            self.control_files.lock_read()
2399
 
            return LogicalLockResult(self.unlock)
2400
2357
        except:
2401
2358
            if took_lock:
2402
2359
                self.repository.unlock()