~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: wang
  • Date: 2006-10-29 13:41:32 UTC
  • mto: (2104.4.1 wang_65714)
  • mto: This revision was merged to the branch mainline in revision 2109.
  • Revision ID: wang@ubuntu-20061029134132-3d7f4216f20c4aef
Replace python's difflib by patiencediff because the worst case 
performance is cubic for difflib and people commiting large data 
files are often hurt by this. The worst case performance of patience is 
quadratic. Fix bug 65714.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 by Canonical Ltd
 
1
# Copyright (C) 2005 Canonical Ltd
2
2
#   Authors: Robert Collins <robert.collins@canonical.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
61
61
up=pull
62
62
"""
63
63
 
 
64
import os
 
65
import sys
64
66
 
 
67
from bzrlib.lazy_import import lazy_import
 
68
lazy_import(globals(), """
65
69
import errno
66
70
from fnmatch import fnmatch
67
 
import os
68
71
import re
69
 
import sys
70
72
from StringIO import StringIO
71
73
 
72
74
import bzrlib
73
 
from bzrlib import errors, urlutils
74
 
from bzrlib.osutils import pathjoin
 
75
from bzrlib import (
 
76
    errors,
 
77
    osutils,
 
78
    urlutils,
 
79
    )
 
80
import bzrlib.util.configobj.configobj as configobj
 
81
""")
 
82
 
75
83
from bzrlib.trace import mutter, warning
76
 
import bzrlib.util.configobj.configobj as configobj
77
84
 
78
85
 
79
86
CHECK_IF_POSSIBLE=0
255
262
            raise errors.ParseConfigError(e.errors, e.config.filename)
256
263
        return self._parser
257
264
 
 
265
    def _get_matching_sections(self):
 
266
        """Return an ordered list of (section_name, extra_path) pairs.
 
267
 
 
268
        If the section contains inherited configuration, extra_path is
 
269
        a string containing the additional path components.
 
270
        """
 
271
        section = self._get_section()
 
272
        if section is not None:
 
273
            return [(section, '')]
 
274
        else:
 
275
            return []
 
276
 
258
277
    def _get_section(self):
259
278
        """Override this to define the section used by the config."""
260
279
        return "DEFAULT"
277
296
 
278
297
    def _get_user_option(self, option_name):
279
298
        """See Config._get_user_option."""
280
 
        try:
281
 
            return self._get_parser().get_value(self._get_section(),
282
 
                                                option_name)
283
 
        except KeyError:
284
 
            pass
 
299
        for (section, extra_path) in self._get_matching_sections():
 
300
            try:
 
301
                return self._get_parser().get_value(section, option_name)
 
302
            except KeyError:
 
303
                pass
 
304
        else:
 
305
            return None
285
306
 
286
307
    def _gpg_signing_command(self):
287
308
        """See Config.gpg_signing_command."""
379
400
            location = urlutils.local_path_from_url(location)
380
401
        self.location = location
381
402
 
382
 
    def _get_section(self):
383
 
        """Get the section we should look in for config items.
384
 
 
385
 
        Returns None if none exists. 
386
 
        TODO: perhaps return a NullSection that thunks through to the 
387
 
              global config.
388
 
        """
 
403
    def _get_matching_sections(self):
 
404
        """Return an ordered list of section names matching this location."""
389
405
        sections = self._get_parser()
390
406
        location_names = self.location.split('/')
391
407
        if self.location.endswith('/'):
422
438
                        continue
423
439
                except KeyError:
424
440
                    pass
425
 
            matches.append((len(section_names), section))
426
 
        if not len(matches):
427
 
            return None
 
441
            matches.append((len(section_names), section,
 
442
                            '/'.join(location_names[len(section_names):])))
428
443
        matches.sort(reverse=True)
429
 
        return matches[0][1]
 
444
        sections = []
 
445
        for (length, section, extra_path) in matches:
 
446
            sections.append((section, extra_path))
 
447
            # should we stop looking for parent configs here?
 
448
            try:
 
449
                if self._get_parser()[section].as_bool('ignore_parents'):
 
450
                    break
 
451
            except KeyError:
 
452
                pass
 
453
        return sections
430
454
 
431
455
    def set_user_option(self, option, value):
432
456
        """Save option and its value in the configuration."""
599
623
            base = os.environ.get('HOME', None)
600
624
        if base is None:
601
625
            raise errors.BzrError('You must have one of BZR_HOME, APPDATA, or HOME set')
602
 
        return pathjoin(base, 'bazaar', '2.0')
 
626
        return osutils.pathjoin(base, 'bazaar', '2.0')
603
627
    else:
604
628
        # cygwin, linux, and darwin all have a $HOME directory
605
629
        if base is None:
606
630
            base = os.path.expanduser("~")
607
 
        return pathjoin(base, ".bazaar")
 
631
        return osutils.pathjoin(base, ".bazaar")
608
632
 
609
633
 
610
634
def config_filename():
611
635
    """Return per-user configuration ini file filename."""
612
 
    return pathjoin(config_dir(), 'bazaar.conf')
 
636
    return osutils.pathjoin(config_dir(), 'bazaar.conf')
613
637
 
614
638
 
615
639
def branches_config_filename():
616
640
    """Return per-user configuration ini file filename."""
617
 
    return pathjoin(config_dir(), 'branches.conf')
 
641
    return osutils.pathjoin(config_dir(), 'branches.conf')
618
642
 
619
643
 
620
644
def locations_config_filename():
621
645
    """Return per-user configuration ini file filename."""
622
 
    return pathjoin(config_dir(), 'locations.conf')
 
646
    return osutils.pathjoin(config_dir(), 'locations.conf')
623
647
 
624
648
 
625
649
def user_ignore_config_filename():
626
650
    """Return the user default ignore filename"""
627
 
    return pathjoin(config_dir(), 'ignore')
 
651
    return osutils.pathjoin(config_dir(), 'ignore')
628
652
 
629
653
 
630
654
def _auto_user_id():
698
722
    """
699
723
    m = re.search(r'[\w+.-]+@[\w+.-]+', e)
700
724
    if not m:
701
 
        raise errors.BzrError("%r doesn't seem to contain "
702
 
                              "a reasonable email address" % e)
 
725
        raise errors.NoEmailInUsername(e)
703
726
    return m.group(0)
704
727
 
705
728