~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: John Arbash Meinel
  • Date: 2010-05-11 10:45:26 UTC
  • mto: This revision was merged to the branch mainline in revision 5225.
  • Revision ID: john@arbash-meinel.com-20100511104526-zxnstcxta22hzw2n
Implement a compiled extension for parsing the text key out of a CHKInventory value.

Related to bug #562666. This seems to shave 5-10% out of the time spent doing a complete
branch of bzr.dev/launchpad/etc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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: An object with an unlock method which will release the lock
299
 
            obtained.
300
 
        """
301
290
        raise NotImplementedError(self.lock_read)
302
291
 
303
292
    def unlock(self):
1357
1346
        """
1358
1347
        # XXX: Fix the bzrdir API to allow getting the branch back from the
1359
1348
        # clone call. Or something. 20090224 RBC/spiv.
 
1349
        # XXX: Should this perhaps clone colocated branches as well, 
 
1350
        # rather than just the default branch? 20100319 JRV
1360
1351
        if revision_id is None:
1361
1352
            revision_id = self.last_revision()
1362
1353
        dir_to = self.bzrdir.clone_on_transport(to_transport,
1532
1523
        """Return the current default format."""
1533
1524
        return klass._default_format
1534
1525
 
1535
 
    def get_reference(self, a_bzrdir):
 
1526
    def get_reference(self, a_bzrdir, name=None):
1536
1527
        """Get the target reference of the branch in a_bzrdir.
1537
1528
 
1538
1529
        format probing must have been completed before calling
1540
1531
        in a_bzrdir is correct.
1541
1532
 
1542
1533
        :param a_bzrdir: The bzrdir to get the branch data from.
 
1534
        :param name: Name of the colocated branch to fetch
1543
1535
        :return: None if the branch is not a reference branch.
1544
1536
        """
1545
1537
        return None
1546
1538
 
1547
1539
    @classmethod
1548
 
    def set_reference(self, a_bzrdir, to_branch):
 
1540
    def set_reference(self, a_bzrdir, name, to_branch):
1549
1541
        """Set the target reference of the branch in a_bzrdir.
1550
1542
 
1551
1543
        format probing must have been completed before calling
1553
1545
        in a_bzrdir is correct.
1554
1546
 
1555
1547
        :param a_bzrdir: The bzrdir to set the branch reference for.
 
1548
        :param name: Name of colocated branch to set, None for default
1556
1549
        :param to_branch: branch that the checkout is to reference
1557
1550
        """
1558
1551
        raise NotImplementedError(self.set_reference)
2168
2161
        """See BranchFormat.get_format_description()."""
2169
2162
        return "Checkout reference format 1"
2170
2163
 
2171
 
    def get_reference(self, a_bzrdir):
 
2164
    def get_reference(self, a_bzrdir, name=None):
2172
2165
        """See BranchFormat.get_reference()."""
2173
 
        transport = a_bzrdir.get_branch_transport(None)
 
2166
        transport = a_bzrdir.get_branch_transport(None, name=name)
2174
2167
        return transport.get_bytes('location')
2175
2168
 
2176
 
    def set_reference(self, a_bzrdir, to_branch):
 
2169
    def set_reference(self, a_bzrdir, name, to_branch):
2177
2170
        """See BranchFormat.set_reference()."""
2178
 
        transport = a_bzrdir.get_branch_transport(None)
 
2171
        transport = a_bzrdir.get_branch_transport(None, name=name)
2179
2172
        location = transport.put_bytes('location', to_branch.base)
2180
2173
 
2181
2174
    def initialize(self, a_bzrdir, name=None, target_branch=None):
2232
2225
                raise AssertionError("wrong format %r found for %r" %
2233
2226
                    (format, self))
2234
2227
        if location is None:
2235
 
            location = self.get_reference(a_bzrdir)
 
2228
            location = self.get_reference(a_bzrdir, name)
2236
2229
        real_bzrdir = bzrdir.BzrDir.open(
2237
2230
            location, possible_transports=possible_transports)
2238
2231
        result = real_bzrdir.open_branch(name=name, 
2276
2269
    _legacy_formats[0].network_name(), _legacy_formats[0].__class__)
2277
2270
 
2278
2271
 
2279
 
class BranchWriteLockResult(object):
2280
 
    """The result of write locking a branch.
2281
 
 
2282
 
    :ivar branch_token: The token obtained from the underlying branch lock, or
2283
 
        None.
2284
 
    :ivar unlock: A callable which will unlock the lock.
2285
 
    """
2286
 
 
2287
 
    def __init__(self, unlock, branch_token):
2288
 
        self.branch_token = branch_token
2289
 
        self.unlock = unlock
2290
 
 
2291
 
    def __str__(self):
2292
 
        return "BranchWriteLockResult(%s, %s)" % (self.branch_token,
2293
 
            self.unlock)
2294
 
 
2295
 
 
2296
2272
class BzrBranch(Branch, _RelockDebugMixin):
2297
2273
    """A branch stored in the actual filesystem.
2298
2274
 
2352
2328
        return self.control_files.is_locked()
2353
2329
 
2354
2330
    def lock_write(self, token=None):
2355
 
        """Lock the branch for write operations.
2356
 
 
2357
 
        :param token: A token to permit reacquiring a previously held and
2358
 
            preserved lock.
2359
 
        :return: A BranchWriteLockResult.
2360
 
        """
2361
2331
        if not self.is_locked():
2362
2332
            self._note_lock('w')
2363
2333
        # All-in-one needs to always unlock/lock.
2369
2339
        else:
2370
2340
            took_lock = False
2371
2341
        try:
2372
 
            return BranchWriteLockResult(self.unlock,
2373
 
                self.control_files.lock_write(token=token))
 
2342
            return self.control_files.lock_write(token=token)
2374
2343
        except:
2375
2344
            if took_lock:
2376
2345
                self.repository.unlock()
2377
2346
            raise
2378
2347
 
2379
2348
    def lock_read(self):
2380
 
        """Lock the branch for read operations.
2381
 
 
2382
 
        :return: An object with an unlock method which will release the lock
2383
 
            obtained.
2384
 
        """
2385
2349
        if not self.is_locked():
2386
2350
            self._note_lock('r')
2387
2351
        # All-in-one needs to always unlock/lock.
2394
2358
            took_lock = False
2395
2359
        try:
2396
2360
            self.control_files.lock_read()
2397
 
            return self
2398
2361
        except:
2399
2362
            if took_lock:
2400
2363
                self.repository.unlock()