From 7e2553e2101310e9ddfce2ca93c1c923b062ad1e Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Tue, 19 Aug 2014 15:07:22 +0000 Subject: Cache configuration values in GitDirectory. This reduces the vast number of 'git config -z core.bare' which we used to get a lot of, to one or two per run. It doesn't save much time, but it does make logs less full of confusion. Reviewed-By: Richard maw +2 --- morphlib/gitdir.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'morphlib') diff --git a/morphlib/gitdir.py b/morphlib/gitdir.py index fea26c2e..6b04b773 100644 --- a/morphlib/gitdir.py +++ b/morphlib/gitdir.py @@ -355,6 +355,7 @@ class GitDirectory(object): # so we just use the provided dirname if not self.dirname: self.dirname = dirname + self._config = {} def _runcmd(self, argv, **kwargs): '''Run a command at the root of the git directory. @@ -447,12 +448,15 @@ class GitDirectory(object): ''' self._runcmd(['git', 'config', key, value]) + self._config[key] = value def get_config(self, key): '''Return value for a git repository configuration variable.''' - value = self._runcmd(['git', 'config', '-z', key]) - return value.rstrip('\0') + if key not in self._config: + value = self._runcmd(['git', 'config', '-z', key]) + self._config[key] = value.rstrip('\0') + return self._config[key] def get_remote(self, *args, **kwargs): '''Get a remote for this Repository. -- cgit v1.2.1