- def __run(self, cmd, args=None):
- """__run: runs cmd using spawnvp.
-
- Runs cmd using spawnvp. The shell is avoided so it won't mess up
- our arguments. If args is very large, the command is run multiple
- times; args is split xargs style: cmd is passed on each
- invocation. Unlike xargs, returns immediately if any non-zero
- return code is received.
- """
-
- args_l=cmd.split()
- if args is None:
- args = []
- for i in range(0, len(args)+1, 100):
- r=os.spawnvp(os.P_WAIT, args_l[0], args_l + args[i:min(i+100, len(args))])
- if r:
- return r
- return 0
-
- def get(self, name):
- if self.__cache.has_key(name):
- return self.__cache[name]
-
- stream = os.popen('git repo-config --get %s' % name, 'r')
- value = stream.readline().strip()
- stream.close()
- if len(value) > 0:
- pass
- elif (self.__defaults.has_key(name)):
- value = self.__defaults[name]
- else:
- value = None
+ def load(self):
+ """Load the whole configuration in __cache unless it has been
+ done already."""
+ if self.__cache is not None:
+ return
+ self.__cache = {}
+ lines = Run('git', 'config', '--list', '--null').raw_output()
+ for line in filter(None, lines.split('\0')):
+ key, value = line.split('\n', 1)
+ self.__cache.setdefault(key, []).append(value)