~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-10-01 07:56:03 UTC
  • mfrom: (3224.5.40 faster-startup)
  • Revision ID: pqm@pqm.ubuntu.com-20081001075603-s9nynw8y85fmrprj
Reduce startup time by a small amount. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
121
121
STORE_BRANCH = 3
122
122
STORE_GLOBAL = 4
123
123
 
124
 
 
125
 
class ConfigObj(configobj.ConfigObj):
126
 
 
127
 
    def get_bool(self, section, key):
128
 
        return self[section].as_bool(key)
129
 
 
130
 
    def get_value(self, section, name):
131
 
        # Try [] for the old DEFAULT section.
132
 
        if section == "DEFAULT":
133
 
            try:
134
 
                return self[name]
135
 
            except KeyError:
136
 
                pass
137
 
        return self[section][name]
 
124
_ConfigObj = None
 
125
def ConfigObj(*args, **kwargs):
 
126
    global _ConfigObj
 
127
    if _ConfigObj is None:
 
128
        class ConfigObj(configobj.ConfigObj):
 
129
 
 
130
            def get_bool(self, section, key):
 
131
                return self[section].as_bool(key)
 
132
 
 
133
            def get_value(self, section, name):
 
134
                # Try [] for the old DEFAULT section.
 
135
                if section == "DEFAULT":
 
136
                    try:
 
137
                        return self[name]
 
138
                    except KeyError:
 
139
                        pass
 
140
                return self[section][name]
 
141
        _ConfigObj = ConfigObj
 
142
    return _ConfigObj(*args, **kwargs)
138
143
 
139
144
 
140
145
class Config(object):
224
229
        """
225
230
        v = os.environ.get('BZR_EMAIL')
226
231
        if v:
227
 
            return v.decode(bzrlib.user_encoding)
 
232
            return v.decode(osutils.get_user_encoding())
228
233
 
229
234
        v = self._get_user_id()
230
235
        if v:
232
237
 
233
238
        v = os.environ.get('EMAIL')
234
239
        if v:
235
 
            return v.decode(bzrlib.user_encoding)
 
240
            return v.decode(osutils.get_user_encoding())
236
241
 
237
242
        name, email = _auto_user_id()
238
243
        if name:
657
662
        """
658
663
        try:
659
664
            return (self.branch._transport.get_bytes("email")
660
 
                    .decode(bzrlib.user_encoding)
 
665
                    .decode(osutils.get_user_encoding())
661
666
                    .rstrip("\r\n"))
662
667
        except errors.NoSuchFile, e:
663
668
            pass
845
850
            encoding = 'utf-8'
846
851
        except UnicodeError:
847
852
            try:
848
 
                gecos = w.pw_gecos.decode(bzrlib.user_encoding)
849
 
                encoding = bzrlib.user_encoding
 
853
                encoding = osutils.get_user_encoding()
 
854
                gecos = w.pw_gecos.decode(encoding)
850
855
            except UnicodeError:
851
856
                raise errors.BzrCommandError('Unable to determine your name.  '
852
857
                   'Use "bzr whoami" to set it.')
867
872
    except ImportError:
868
873
        import getpass
869
874
        try:
870
 
            realname = username = getpass.getuser().decode(bzrlib.user_encoding)
 
875
            user_encoding = osutils.get_user_encoding()
 
876
            realname = username = getpass.getuser().decode(user_encoding)
871
877
        except UnicodeDecodeError:
872
878
            raise errors.BzrError("Can't decode username as %s." % \
873
 
                    bzrlib.user_encoding)
 
879
                    user_encoding)
874
880
 
875
881
    return realname, (username + '@' + socket.gethostname())
876
882