summaryrefslogtreecommitdiffstats
path: root/git_config.py
diff options
context:
space:
mode:
Diffstat (limited to 'git_config.py')
-rw-r--r--git_config.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/git_config.py b/git_config.py
index 9b63417e..c87d5bed 100644
--- a/git_config.py
+++ b/git_config.py
@@ -13,6 +13,7 @@
13# See the License for the specific language governing permissions and 13# See the License for the specific language governing permissions and
14# limitations under the License. 14# limitations under the License.
15 15
16import cPickle
16import os 17import os
17import re 18import re
18import sys 19import sys
@@ -57,6 +58,9 @@ class GitConfig(object):
57 self._cache_dict = None 58 self._cache_dict = None
58 self._remotes = {} 59 self._remotes = {}
59 self._branches = {} 60 self._branches = {}
61 self._pickle = os.path.join(
62 os.path.dirname(self.file),
63 '.repopickle_' + os.path.basename(self.file))
60 64
61 def Has(self, name, include_defaults = True): 65 def Has(self, name, include_defaults = True):
62 """Return true if this configuration file has the key. 66 """Return true if this configuration file has the key.
@@ -170,6 +174,40 @@ class GitConfig(object):
170 return self._cache_dict 174 return self._cache_dict
171 175
172 def _Read(self): 176 def _Read(self):
177 d = self._ReadPickle()
178 if d is None:
179 d = self._ReadGit()
180 self._SavePickle(d)
181 return d
182
183 def _ReadPickle(self):
184 try:
185 if os.path.getmtime(self._pickle) \
186 <= os.path.getmtime(self.file):
187 os.remove(self._pickle)
188 return None
189 except OSError:
190 return None
191 try:
192 return cPickle.load(open(self._pickle, 'r'))
193 except IOError:
194 os.remove(self._pickle)
195 return None
196 except cPickle.PickleError:
197 os.remove(self._pickle)
198 return None
199
200 def _SavePickle(self, cache):
201 try:
202 cPickle.dump(cache,
203 open(self._pickle, 'w'),
204 cPickle.HIGHEST_PROTOCOL)
205 except IOError:
206 os.remove(self._pickle)
207 except cPickle.PickleError:
208 os.remove(self._pickle)
209
210 def _ReadGit(self):
173 d = self._do('--null', '--list') 211 d = self._do('--null', '--list')
174 c = {} 212 c = {}
175 while d: 213 while d: