/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 breezy/rules.py

  • Committer: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

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
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Rule-based definition of preferences for selected files in selected branches.
 
17
"""Rule-based definition of preferences for selected files in selected branches
18
18
 
19
19
See ``bzr help rules`` for details.
20
20
"""
21
21
 
22
 
from bzrlib import (
23
 
    config,
 
22
import configobj
 
23
 
 
24
from . import (
 
25
    bedding,
24
26
    cmdline,
25
27
    errors,
26
28
    globbing,
27
29
    osutils,
28
30
    )
29
 
from bzrlib.util.configobj import configobj
30
31
 
31
32
 
32
33
# Name of the file holding rules in a tree
40
41
_per_user_searcher = None
41
42
 
42
43
 
 
44
class UnknownRules(errors.BzrError):
 
45
 
 
46
    _fmt = ('Unknown rules detected: %(unknowns_str)s.')
 
47
 
 
48
    def __init__(self, unknowns):
 
49
        errors.BzrError.__init__(self, unknowns_str=", ".join(unknowns))
 
50
 
 
51
 
43
52
class _RulesSearcher(object):
44
53
    """An object that provides rule-based preferences."""
45
54
 
64
73
        """
65
74
        raise NotImplementedError(self.get_selected_items)
66
75
 
 
76
    def get_single_value(self, path, preference_name):
 
77
        """Get a single preference for a single file.
 
78
 
 
79
        :returns: The string preference value, or None.
 
80
        """
 
81
        for key, value in self.get_selected_items(path, [preference_name]):
 
82
            return value
 
83
        return None
 
84
 
67
85
 
68
86
class _IniBasedRulesSearcher(_RulesSearcher):
69
87
 
74
92
 
75
93
        :param inifile: the name of the file or a sequence of lines.
76
94
        """
77
 
        options = {'encoding': 'utf-8'}
78
 
        self._cfg = configobj.ConfigObj(inifile, options=options)
 
95
        self._cfg = configobj.ConfigObj(inifile, encoding='utf-8')
79
96
        sections = self._cfg.keys()
80
97
        patterns = []
81
98
        self.pattern_to_section = {}
87
104
                    self.pattern_to_section[fp] = s
88
105
        if len(patterns) < len(sections):
89
106
            unknowns = [s for s in sections
90
 
                if not s.startswith(FILE_PREFS_PREFIX)]
91
 
            raise errors.UnknownRules(unknowns)
 
107
                        if not s.startswith(FILE_PREFS_PREFIX)]
 
108
            raise UnknownRules(unknowns)
92
109
        elif patterns:
93
110
            self._globster = globbing._OrderedGlobster(patterns)
94
111
        else:
143
160
        return ()
144
161
 
145
162
 
146
 
def rules_filename():
147
 
    """Return the default rules filename."""
148
 
    return osutils.pathjoin(config.config_dir(), 'rules')
 
163
def rules_path():
 
164
    """Return the default rules file path."""
 
165
    return osutils.pathjoin(bedding.config_dir(), 'rules')
149
166
 
150
167
 
151
168
def reset_rules():
152
169
    global _per_user_searcher
153
 
    _per_user_searcher = _IniBasedRulesSearcher(rules_filename())
 
170
    _per_user_searcher = _IniBasedRulesSearcher(rules_path())
 
171
 
154
172
 
155
173
reset_rules()