~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Patch Queue Manager
  • Date: 2012-02-14 18:29:43 UTC
  • mfrom: (6404.6.11 cached-branch-store)
  • Revision ID: pqm@pqm.ubuntu.com-20120214182943-vso6j0mqdnxfkp7s
(vila) Cache the branch config store to avoid useless IOs. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3416
3416
        self.branch = branch
3417
3417
        self.id = 'branch'
3418
3418
 
3419
 
    def lock_write(self, token=None):
3420
 
        return self.branch.lock_write(token)
3421
 
 
3422
 
    def unlock(self):
3423
 
        return self.branch.unlock()
3424
 
 
3425
 
    @needs_write_lock
3426
 
    def save(self):
3427
 
        # We need to be able to override the undecorated implementation
3428
 
        self.save_without_locking()
3429
 
 
3430
 
    def save_without_locking(self):
3431
 
        super(BranchStore, self).save()
3432
 
 
3433
3419
 
3434
3420
class ControlStore(LockableIniFileStore):
3435
3421
 
3939
3925
            lstore, mutable_section_id=location)
3940
3926
 
3941
3927
 
3942
 
class BranchStack(_CompatibleStack):
 
3928
class BranchStack(Stack):
3943
3929
    """Per-location options falling back to branch then global options stack.
3944
3930
 
3945
3931
    The following sections are queried:
3970
3956
            bstore)
3971
3957
        self.branch = branch
3972
3958
 
 
3959
    def lock_write(self, token=None):
 
3960
        return self.branch.lock_write(token)
 
3961
 
 
3962
    def unlock(self):
 
3963
        return self.branch.unlock()
 
3964
 
 
3965
    @needs_write_lock
 
3966
    def set(self, name, value):
 
3967
        super(BranchStack, self).set(name, value)
 
3968
        # Unlocking the branch will trigger a store.save_changes() so the last
 
3969
        # unlock saves all the changes.
 
3970
 
 
3971
    @needs_write_lock
 
3972
    def remove(self, name):
 
3973
        super(BranchStack, self).remove(name)
 
3974
        # Unlocking the branch will trigger a store.save_changes() so the last
 
3975
        # unlock saves all the changes.
 
3976
 
3973
3977
 
3974
3978
class RemoteControlStack(_CompatibleStack):
3975
3979
    """Remote control-only options stack."""
3986
3990
        self.bzrdir = bzrdir
3987
3991
 
3988
3992
 
3989
 
class BranchOnlyStack(_CompatibleStack):
 
3993
class BranchOnlyStack(Stack):
3990
3994
    """Branch-only options stack."""
3991
3995
 
3992
3996
    # FIXME: _BranchOnlyStack only uses branch.conf and is used only for the
4000
4004
            bstore)
4001
4005
        self.branch = branch
4002
4006
 
 
4007
    def lock_write(self, token=None):
 
4008
        return self.branch.lock_write(token)
 
4009
 
 
4010
    def unlock(self):
 
4011
        return self.branch.unlock()
 
4012
 
 
4013
    @needs_write_lock
 
4014
    def set(self, name, value):
 
4015
        super(BranchOnlyStack, self).set(name, value)
 
4016
        # Force a write to persistent storage
 
4017
        self.store.save_changes()
 
4018
 
 
4019
    @needs_write_lock
 
4020
    def remove(self, name):
 
4021
        super(BranchOnlyStack, self).remove(name)
 
4022
        # Force a write to persistent storage
 
4023
        self.store.save_changes()
 
4024
 
4003
4025
 
4004
4026
# Use a an empty dict to initialize an empty configobj avoiding all
4005
4027
# parsing and encoding checks
4072
4094
                # Set the option value
4073
4095
                self._set_config_option(name, value, directory, scope)
4074
4096
 
4075
 
    def _get_stack(self, directory, scope=None):
 
4097
    def _get_stack(self, directory, scope=None, write_access=False):
4076
4098
        """Get the configuration stack specified by ``directory`` and ``scope``.
4077
4099
 
4078
4100
        :param directory: Where the configurations are derived from.
4079
4101
 
4080
4102
        :param scope: A specific config to start from.
 
4103
 
 
4104
        :param write_access: Whether a write access to the stack will be
 
4105
            attempted.
4081
4106
        """
4082
4107
        # FIXME: scope should allow access to plugin-specific stacks (even
4083
4108
        # reduced to the plugin-specific store), related to
4091
4116
                (_, br, _) = (
4092
4117
                    controldir.ControlDir.open_containing_tree_or_branch(
4093
4118
                        directory))
 
4119
                if write_access:
 
4120
                    self.add_cleanup(br.lock_write().unlock)
4094
4121
                return br.get_config_stack()
4095
4122
            raise errors.NoSuchConfig(scope)
4096
4123
        else:
4098
4125
                (_, br, _) = (
4099
4126
                    controldir.ControlDir.open_containing_tree_or_branch(
4100
4127
                        directory))
 
4128
                if write_access:
 
4129
                    self.add_cleanup(br.lock_write().unlock)
4101
4130
                return br.get_config_stack()
4102
4131
            except errors.NotBranchError:
4103
4132
                return LocationStack(directory)
4148
4177
                        self.outf.write('  %s = %s\n' % (oname, value))
4149
4178
 
4150
4179
    def _set_config_option(self, name, value, directory, scope):
4151
 
        conf = self._get_stack(directory, scope)
 
4180
        conf = self._get_stack(directory, scope, write_access=True)
4152
4181
        conf.set(name, value)
4153
4182
 
4154
4183
    def _remove_config_option(self, name, directory, scope):
4155
4184
        if name is None:
4156
4185
            raise errors.BzrCommandError(
4157
4186
                '--remove expects an option to remove.')
4158
 
        conf = self._get_stack(directory, scope)
 
4187
        conf = self._get_stack(directory, scope, write_access=True)
4159
4188
        try:
4160
4189
            conf.remove(name)
4161
4190
        except KeyError: