/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/config.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:
74
74
up=pull
75
75
"""
76
76
 
77
 
from __future__ import absolute_import
78
77
import os
79
78
import sys
80
79
 
81
80
import configobj
 
81
from io import BytesIO
82
82
 
83
83
import breezy
84
84
from .lazy_import import lazy_import
90
90
import stat
91
91
 
92
92
from breezy import (
93
 
    atomicfile,
94
93
    cmdline,
95
94
    controldir,
96
95
    debug,
115
114
    lazy_regex,
116
115
    registry,
117
116
    )
118
 
from .sixish import (
119
 
    binary_type,
120
 
    BytesIO,
121
 
    PY3,
122
 
    string_types,
123
 
    text_type,
124
 
    )
125
117
 
126
118
 
127
119
CHECK_IF_POSSIBLE = 0
258
250
                     % signature_string)
259
251
 
260
252
 
261
 
def _has_decode_bug():
262
 
    """True if configobj will fail to decode to unicode on Python 2."""
263
 
    if PY3:
264
 
        return False
265
 
    conf = configobj.ConfigObj()
266
 
    decode = getattr(conf, "_decode", None)
267
 
    if decode:
268
 
        result = decode(b"\xc2\xa7", "utf-8")
269
 
        if isinstance(result[0], str):
270
 
            return True
271
 
    return False
272
 
 
273
 
 
274
253
def _has_triplequote_bug():
275
254
    """True if triple quote logic is reversed, see lp:710410."""
276
255
    conf = configobj.ConfigObj()
288
267
                                        interpolation=False,
289
268
                                        **kwargs)
290
269
 
291
 
    if _has_decode_bug():
292
 
        def _decode(self, infile, encoding):
293
 
            if isinstance(infile, str) and encoding:
294
 
                return infile.decode(encoding).splitlines(True)
295
 
            return super(ConfigObj, self)._decode(infile, encoding)
296
 
 
297
270
    if _has_triplequote_bug():
298
271
        def _get_triple_quote(self, value):
299
272
            quot = super(ConfigObj, self)._get_triple_quote(value)
520
493
            otherwise.
521
494
        """
522
495
        l = self.get_user_option(option_name, expand=expand)
523
 
        if isinstance(l, string_types):
 
496
        if isinstance(l, str):
524
497
            # A single value, most probably the user forgot (or didn't care to
525
498
            # add) the final ','
526
499
            l = [l]
563
536
        """
564
537
        v = os.environ.get('BRZ_EMAIL') or os.environ.get('BZR_EMAIL')
565
538
        if v:
566
 
            if not PY3:
567
 
                v = v.decode(osutils.get_user_encoding())
568
539
            return v
569
540
        v = self._get_user_id()
570
541
        if v:
730
701
        return conf
731
702
 
732
703
    def _create_from_string(self, str_or_unicode, save):
733
 
        if isinstance(str_or_unicode, text_type):
 
704
        if isinstance(str_or_unicode, str):
734
705
            str_or_unicode = str_or_unicode.encode('utf-8')
735
706
        self._content = BytesIO(str_or_unicode)
736
707
        # Some tests use in-memory configs, some other always need the config
931
902
    def _write_config_file(self):
932
903
        if self.file_name is None:
933
904
            raise AssertionError('We cannot save, self.file_name is None')
 
905
        from . import atomicfile
934
906
        conf_dir = os.path.dirname(self.file_name)
935
907
        bedding.ensure_config_dir_exists(conf_dir)
936
908
        with atomicfile.AtomicFile(self.file_name) as atomic_file:
2129
2101
                raise AssertionError(
2130
2102
                    'Only empty lists are supported as default values')
2131
2103
            self.default = u','
2132
 
        elif isinstance(default, (binary_type, text_type, bool, int, float)):
 
2104
        elif isinstance(default, (bytes, str, bool, int, float)):
2133
2105
            # Rely on python to convert strings, booleans and integers
2134
2106
            self.default = u'%s' % (default,)
2135
2107
        elif callable(default):
2176
2148
            try:
2177
2149
                # If the env variable is defined, its value takes precedence
2178
2150
                value = os.environ[var]
2179
 
                if not PY3:
2180
 
                    value = value.decode(osutils.get_user_encoding())
2181
2151
                break
2182
2152
            except KeyError:
2183
2153
                continue
2189
2159
            try:
2190
2160
                # If the env variable is defined, its value is the default one
2191
2161
                value = os.environ[var]
2192
 
                if not PY3:
2193
 
                    value = value.decode(osutils.get_user_encoding())
2194
2162
                break
2195
2163
            except KeyError:
2196
2164
                continue
2198
2166
            # Otherwise, fallback to the value defined at registration
2199
2167
            if callable(self.default):
2200
2168
                value = self.default()
2201
 
                if not isinstance(value, text_type):
 
2169
                if not isinstance(value, str):
2202
2170
                    raise AssertionError(
2203
2171
                        "Callable default value for '%s' should be unicode"
2204
2172
                        % (self.name))
2283
2251
            invalid=invalid, unquote=False)
2284
2252
 
2285
2253
    def from_unicode(self, unicode_str):
2286
 
        if not isinstance(unicode_str, string_types):
 
2254
        if not isinstance(unicode_str, str):
2287
2255
            raise TypeError
2288
2256
        # Now inject our string directly as unicode. All callers got their
2289
2257
        # value from configobj, so values that need to be quoted are already
2291
2259
        _list_converter_config.reset()
2292
2260
        _list_converter_config._parse([u"list=%s" % (unicode_str,)])
2293
2261
        maybe_list = _list_converter_config['list']
2294
 
        if isinstance(maybe_list, string_types):
 
2262
        if isinstance(maybe_list, str):
2295
2263
            if maybe_list:
2296
2264
                # A single value, most probably the user forgot (or didn't care
2297
2265
                # to add) the final ','
2323
2291
        self.registry = registry
2324
2292
 
2325
2293
    def from_unicode(self, unicode_str):
2326
 
        if not isinstance(unicode_str, string_types):
 
2294
        if not isinstance(unicode_str, str):
2327
2295
            raise TypeError
2328
2296
        try:
2329
2297
            return self.registry.get(unicode_str)
2934
2902
            try:
2935
2903
                name, value = over.split('=', 1)
2936
2904
            except ValueError:
2937
 
                raise errors.BzrCommandError(
 
2905
                raise errors.CommandError(
2938
2906
                    gettext("Invalid '%s', should be of the form 'name=value'")
2939
2907
                    % (over,))
2940
2908
            self.options[name] = value
3082
3050
            self._config_obj.list_values = False
3083
3051
 
3084
3052
    def unquote(self, value):
3085
 
        if value and isinstance(value, string_types):
 
3053
        if value and isinstance(value, str):
3086
3054
            # _unquote doesn't handle None nor empty strings nor anything that
3087
3055
            # is not a string, really.
3088
3056
            value = self._config_obj._unquote(value)
3499
3467
            # None or ends up being None during expansion or conversion.
3500
3468
            if val is not None:
3501
3469
                if expand:
3502
 
                    if isinstance(val, string_types):
 
3470
                    if isinstance(val, str):
3503
3471
                        val = self._expand_options_in_string(val)
3504
3472
                    else:
3505
3473
                        trace.warning('Cannot expand "%s":'
3906
3874
        # http://pad.lv/788991 -- vila 20101115
3907
3875
        commands.Option('scope', help='Reduce the scope to the specified'
3908
3876
                        ' configuration file.',
3909
 
                        type=text_type),
 
3877
                        type=str),
3910
3878
        commands.Option('all',
3911
3879
                        help='Display all the defined values for the matching options.',
3912
3880
                        ),
4035
4003
 
4036
4004
    def _remove_config_option(self, name, directory, scope):
4037
4005
        if name is None:
4038
 
            raise errors.BzrCommandError(
 
4006
            raise errors.CommandError(
4039
4007
                '--remove expects an option to remove.')
4040
4008
        conf = self._get_stack(directory, scope, write_access=True)
4041
4009
        try: