##// END OF EJS Templates
ui: privatize cdata vars
Matt Mackall -
r8203:3377fa11 default
parent child Browse files
Show More
@@ -17,16 +17,16 b' class ui(object):'
17 self._buffers = []
17 self._buffers = []
18 self.quiet = self.verbose = self.debugflag = self.traceback = False
18 self.quiet = self.verbose = self.debugflag = self.traceback = False
19 self.interactive = self.report_untrusted = True
19 self.interactive = self.report_untrusted = True
20 self.overlay = config.config()
20 self._ocfg = config.config() # overlay
21 self.cdata = config.config()
21 self._tcfg = config.config() # trusted
22 self.ucdata = config.config()
22 self._ucfg = config.config() # untrusted
23 self._trustusers = {}
23 self._trustusers = {}
24 self._trustgroups = {}
24 self._trustgroups = {}
25
25
26 if src:
26 if src:
27 self.cdata = src.cdata.copy()
27 self._tcfg = src._tcfg.copy()
28 self.ucdata = src.ucdata.copy()
28 self._ucfg = src._ucfg.copy()
29 self.overlay = src.overlay.copy()
29 self._ocfg = src._ocfg.copy()
30 self._trustusers = src._trustusers.copy()
30 self._trustusers = src._trustusers.copy()
31 self._trustgroups = src._trustgroups.copy()
31 self._trustgroups = src._trustgroups.copy()
32 self.fixconfig()
32 self.fixconfig()
@@ -77,21 +77,21 b' class ui(object):'
77 return
77 return
78 raise
78 raise
79
79
80 cdata = config.config()
80 cfg = config.config()
81 trusted = sections or trust or self._is_trusted(fp, filename)
81 trusted = sections or trust or self._is_trusted(fp, filename)
82
82
83 try:
83 try:
84 cdata.read(filename, fp, sections=sections)
84 cfg.read(filename, fp, sections=sections)
85 except error.ConfigError, inst:
85 except error.ConfigError, inst:
86 if trusted:
86 if trusted:
87 raise
87 raise
88 self.warn(_("Ignored: %s\n") % str(inst))
88 self.warn(_("Ignored: %s\n") % str(inst))
89
89
90 if trusted:
90 if trusted:
91 self.cdata.update(cdata)
91 self._tcfg.update(cfg)
92 self.cdata.update(self.overlay)
92 self._tcfg.update(self._ocfg)
93 self.ucdata.update(cdata)
93 self._ucfg.update(cfg)
94 self.ucdata.update(self.overlay)
94 self._ucfg.update(self._ocfg)
95
95
96 if root is None:
96 if root is None:
97 root = os.path.expanduser('~')
97 root = os.path.expanduser('~')
@@ -100,7 +100,7 b' class ui(object):'
100 def fixconfig(self, root=None):
100 def fixconfig(self, root=None):
101 # translate paths relative to root (or home) into absolute paths
101 # translate paths relative to root (or home) into absolute paths
102 root = root or os.getcwd()
102 root = root or os.getcwd()
103 for c in self.cdata, self.ucdata, self.overlay:
103 for c in self._tcfg, self._ucfg, self._ocfg:
104 for n, p in c.items('paths'):
104 for n, p in c.items('paths'):
105 if p and "://" not in p and not os.path.isabs(p):
105 if p and "://" not in p and not os.path.isabs(p):
106 c.set("paths", n, os.path.normpath(os.path.join(root, p)))
106 c.set("paths", n, os.path.normpath(os.path.join(root, p)))
@@ -122,12 +122,12 b' class ui(object):'
122 self._trustgroups[group] = 1
122 self._trustgroups[group] = 1
123
123
124 def setconfig(self, section, name, value):
124 def setconfig(self, section, name, value):
125 for cdata in (self.overlay, self.cdata, self.ucdata):
125 for cfg in (self._ocfg, self._tcfg, self._ucfg):
126 cdata.set(section, name, value)
126 cfg.set(section, name, value)
127 self.fixconfig()
127 self.fixconfig()
128
128
129 def _data(self, untrusted):
129 def _data(self, untrusted):
130 return untrusted and self.ucdata or self.cdata
130 return untrusted and self._ucfg or self._tcfg
131
131
132 def configsource(self, section, name, untrusted=False):
132 def configsource(self, section, name, untrusted=False):
133 return self._data(untrusted).source(section, name) or 'none'
133 return self._data(untrusted).source(section, name) or 'none'
@@ -135,7 +135,7 b' class ui(object):'
135 def config(self, section, name, default=None, untrusted=False):
135 def config(self, section, name, default=None, untrusted=False):
136 value = self._data(untrusted).get(section, name, default)
136 value = self._data(untrusted).get(section, name, default)
137 if self.debugflag and not untrusted:
137 if self.debugflag and not untrusted:
138 uvalue = self.ucdata.get(section, name)
138 uvalue = self._ucfg.get(section, name)
139 if uvalue is not None and uvalue != value:
139 if uvalue is not None and uvalue != value:
140 self.warn(_("Ignoring untrusted configuration option "
140 self.warn(_("Ignoring untrusted configuration option "
141 "%s.%s = %s\n") % (section, name, uvalue))
141 "%s.%s = %s\n") % (section, name, uvalue))
@@ -166,15 +166,15 b' class ui(object):'
166 def configitems(self, section, untrusted=False):
166 def configitems(self, section, untrusted=False):
167 items = self._data(untrusted).items(section)
167 items = self._data(untrusted).items(section)
168 if self.debugflag and not untrusted:
168 if self.debugflag and not untrusted:
169 for k,v in self.ucdata.items(section):
169 for k,v in self._ucfg.items(section):
170 if self.cdata.get(section, k) != v:
170 if self._tcfg.get(section, k) != v:
171 self.warn(_("Ignoring untrusted configuration option "
171 self.warn(_("Ignoring untrusted configuration option "
172 "%s.%s = %s\n") % (section, k, v))
172 "%s.%s = %s\n") % (section, k, v))
173 return items
173 return items
174
174
175 def walkconfig(self, untrusted=False):
175 def walkconfig(self, untrusted=False):
176 cdata = self._data(untrusted)
176 cfg = self._data(untrusted)
177 for section in cdata.sections():
177 for section in cfg.sections():
178 for name, value in self.configitems(section, untrusted):
178 for name, value in self.configitems(section, untrusted):
179 yield section, name, str(value).replace('\n', '\\n')
179 yield section, name, str(value).replace('\n', '\\n')
180
180
General Comments 0
You need to be logged in to leave comments. Login now