~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/rules.py

  • Committer: Vincent Ladeuil
  • Date: 2012-01-18 14:09:19 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120118140919-rlvdrhpc0nq1lbwi
Change set/remove to require a lock for the branch config files.

This means that tests (or any plugin for that matter) do not requires an
explicit lock on the branch anymore to change a single option. This also
means the optimisation becomes "opt-in" and as such won't be as
spectacular as it may be and/or harder to get right (nothing fails
anymore).

This reduces the diff by ~300 lines.

Code/tests that were updating more than one config option is still taking
a lock to at least avoid some IOs and demonstrate the benefits through
the decreased number of hpss calls.

The duplication between BranchStack and BranchOnlyStack will be removed
once the same sharing is in place for local config files, at which point
the Stack class itself may be able to host the changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008 Canonical Ltd
 
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
19
19
See ``bzr help rules`` for details.
20
20
"""
21
21
 
 
22
from __future__ import absolute_import
 
23
 
22
24
from bzrlib import (
23
25
    config,
24
26
    cmdline,
64
66
        """
65
67
        raise NotImplementedError(self.get_selected_items)
66
68
 
 
69
    def get_single_value(self, path, preference_name):
 
70
        """Get a single preference for a single file.
 
71
        
 
72
        :returns: The string preference value, or None.
 
73
        """
 
74
        for key, value in self.get_selected_items(path, [preference_name]):
 
75
            return value
 
76
        return None
 
77
 
67
78
 
68
79
class _IniBasedRulesSearcher(_RulesSearcher):
69
80
 
74
85
 
75
86
        :param inifile: the name of the file or a sequence of lines.
76
87
        """
77
 
        options = {'encoding': 'utf-8'}
78
 
        self._cfg = configobj.ConfigObj(inifile, options=options)
 
88
        self._cfg = configobj.ConfigObj(inifile, encoding='utf-8')
79
89
        sections = self._cfg.keys()
80
90
        patterns = []
81
91
        self.pattern_to_section = {}