~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: John Arbash Meinel
  • Date: 2008-10-15 21:34:10 UTC
  • mto: This revision was merged to the branch mainline in revision 3791.
  • Revision ID: john@arbash-meinel.com-20081015213410-g19sy2rpgxcl2sew
Change the name to ChunkWriter.set_optimize()

Also allow it to be passed during __init__ and pass it in from
BTreeBuilder.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1743
1743
        """
1744
1744
        # TODO: Public option to disable running hooks - should be trivial but
1745
1745
        # needs tests.
1746
 
        return _run_with_write_locked_target(
1747
 
            target, self._push_with_bound_branches, target, overwrite,
1748
 
            stop_revision,
1749
 
            _override_hook_source_branch=_override_hook_source_branch)
 
1746
        target.lock_write()
 
1747
        try:
 
1748
            result = self._push_with_bound_branches(target, overwrite,
 
1749
                    stop_revision,
 
1750
                    _override_hook_source_branch=_override_hook_source_branch)
 
1751
            return result
 
1752
        finally:
 
1753
            target.unlock()
1750
1754
 
1751
1755
    def _push_with_bound_branches(self, target, overwrite,
1752
1756
            stop_revision,
2441
2445
        branch._set_config_location('stacked_on_location', '')
2442
2446
        # update target format
2443
2447
        branch._transport.put_bytes('format', format.get_format_string())
2444
 
 
2445
 
 
2446
 
 
2447
 
def _run_with_write_locked_target(target, callable, *args, **kwargs):
2448
 
    """Run ``callable(*args, **kwargs)``, write-locking target for the
2449
 
    duration.
2450
 
 
2451
 
    _run_with_write_locked_target will attempt to release the lock it acquires.
2452
 
 
2453
 
    If an exception is raised by callable, then that exception *will* be
2454
 
    propagated, even if the unlock attempt raises its own error.  Thus
2455
 
    _run_with_write_locked_target should be preferred to simply doing::
2456
 
 
2457
 
        target.lock_write()
2458
 
        try:
2459
 
            return callable(*args, **kwargs)
2460
 
        finally:
2461
 
            target.unlock()
2462
 
    
2463
 
    """
2464
 
    # This is very similar to bzrlib.decorators.needs_write_lock.  Perhaps they
2465
 
    # should share code?
2466
 
    target.lock_write()
2467
 
    try:
2468
 
        result = callable(*args, **kwargs)
2469
 
    except:
2470
 
        exc_info = sys.exc_info()
2471
 
        try:
2472
 
            target.unlock()
2473
 
        finally:
2474
 
            raise exc_info[0], exc_info[1], exc_info[2]
2475
 
    else:
2476
 
        target.unlock()
2477
 
        return result