mercurial/ui.py
changeset 8143 507c49e297e1
parent 8142 912bfef12ba6
child 8144 fca54469480e
equal deleted inserted replaced
8142:912bfef12ba6 8143:507c49e297e1
     6 # of the GNU General Public License, incorporated herein by reference.
     6 # of the GNU General Public License, incorporated herein by reference.
     7 
     7 
     8 from i18n import _
     8 from i18n import _
     9 import errno, getpass, os, re, socket, sys, tempfile
     9 import errno, getpass, os, re, socket, sys, tempfile
    10 import ConfigParser, traceback, util
    10 import ConfigParser, traceback, util
    11 
       
    12 def dupconfig(orig):
       
    13     new = util.configparser(orig.defaults())
       
    14     updateconfig(orig, new)
       
    15     return new
       
    16 
    11 
    17 def updateconfig(source, dest, sections=None):
    12 def updateconfig(source, dest, sections=None):
    18     if not sections:
    13     if not sections:
    19         sections = source.sections()
    14         sections = source.sections()
    20     for section in sections:
    15     for section in sections:
    28 class ui(object):
    23 class ui(object):
    29     def __init__(self, parentui=None):
    24     def __init__(self, parentui=None):
    30         self.buffers = []
    25         self.buffers = []
    31         self.quiet = self.verbose = self.debugflag = self.traceback = False
    26         self.quiet = self.verbose = self.debugflag = self.traceback = False
    32         self.interactive = self.report_untrusted = True
    27         self.interactive = self.report_untrusted = True
    33 
    28         self.overlay = util.configparser()
    34         if parentui is None:
    29         self.cdata = util.configparser()
    35             # this is the parent of all ui children
    30         self.ucdata = util.configparser()
    36             self.parentui = None
    31         self.parentui = None
    37             self.trusted_users = {}
    32         self.trusted_users = {}
    38             self.trusted_groups = {}
    33         self.trusted_groups = {}
    39             self.overlay = util.configparser()
    34 
    40             self.cdata = util.configparser()
    35         if parentui:
    41             self.ucdata = util.configparser()
    36             # parentui may point to an ui object which is already a child
    42 
    37             self.parentui = parentui.parentui or parentui
       
    38             updateconfig(self.parentui.cdata, self.cdata)
       
    39             updateconfig(self.parentui.ucdata, self.ucdata)
       
    40             # we want the overlay from the parent, not the root
       
    41             updateconfig(parentui.overlay, self.overlay)
       
    42             self.buffers = parentui.buffers
       
    43             self.trusted_users = parentui.trusted_users.copy()
       
    44             self.trusted_groups = parentui.trusted_groups.copy()
       
    45             self.fixconfig()
       
    46         else:
    43             # we always trust global config files
    47             # we always trust global config files
    44             for f in util.rcpath():
    48             for f in util.rcpath():
    45                 self.readconfig(f, assumetrusted=True)
    49                 self.readconfig(f, assumetrusted=True)
    46         else:
       
    47             # parentui may point to an ui object which is already a child
       
    48             self.parentui = parentui.parentui or parentui
       
    49             self.buffers = parentui.buffers
       
    50             self.trusted_users = parentui.trusted_users.copy()
       
    51             self.trusted_groups = parentui.trusted_groups.copy()
       
    52             self.cdata = dupconfig(self.parentui.cdata)
       
    53             self.ucdata = dupconfig(self.parentui.ucdata)
       
    54 
       
    55             # we want the overlay from the parent, not the root
       
    56             self.overlay = dupconfig(parentui.overlay)
       
    57             self.fixconfig()
       
    58 
    50 
    59     def __getattr__(self, key):
    51     def __getattr__(self, key):
    60         return getattr(self.parentui, key)
    52         return getattr(self.parentui, key)
    61 
    53 
    62     _isatty = None
    54     _isatty = None