+ self.__cache[name] = value
+ return value
+
+ def getall(self, name):
+ if self.__cache.has_key(name):
+ return self.__cache[name]
+
+ stream = os.popen('git repo-config --get-all %s' % name, 'r')
+ values = [line.strip() for line in stream]
+ stream.close()
+
+ self.__cache[name] = values
+ return values
+
+ def getint(self, name):
+ value = self.get(name)
+ if value.isdigit():
+ return int(value)
+ else:
+ raise GitConfigException, 'Value for "%s" is not an integer: "%s"' % (name, value)
+
+ def set(self, name, value):
+ self.__run('git-repo-config', [name, value])
+
+ def sections_matching(self, regexp):
+ """Takes a regexp with a single group, matches it against all
+ config variables, and returns a list whose members are the
+ group contents, for all variable names matching the regexp.
+ """
+ result = []
+ stream = os.popen('git repo-config --get-regexp "^%s$"' % regexp, 'r')
+ for line in stream:
+ m = re.match('^%s ' % regexp, line)
+ if m:
+ result.append(m.group(1))
+ stream.close()
+ return result
+
+config=GitConfig()
+
+def config_setup():
+ global config
+
+ # Set the PAGER environment to the config value (if any)
+ pager = config.get('stgit.pager')
+ if pager:
+ os.environ['PAGER'] = pager
+ # FIXME: handle EDITOR the same way ?
+
+class ConfigOption:
+ """Delayed cached reading of a configuration option.
+ """
+ def __init__(self, section, option):
+ self.__section = section
+ self.__option = option
+ self.__value = None
+
+ def __str__(self):
+ if not self.__value:
+ self.__value = config.get(self.__section + '.' + self.__option)
+ return self.__value
+
+
+# cached extensions
+__extensions = None
+
+def file_extensions():
+ """Returns a dictionary with the conflict file extensions
+ """
+ global __extensions
+
+ if not __extensions:
+ cfg_ext = config.get('stgit.extensions').split()
+ if len(cfg_ext) != 3:
+ raise CmdException, '"extensions" configuration error'
+
+ __extensions = { 'ancestor': cfg_ext[0],
+ 'current': cfg_ext[1],
+ 'patched': cfg_ext[2] }
+
+ return __extensions