diff options
Diffstat (limited to 'git/config.py')
-rw-r--r-- | git/config.py | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/git/config.py b/git/config.py index ad6192ff..3c6a32eb 100644 --- a/git/config.py +++ b/git/config.py @@ -17,6 +17,8 @@ import logging import abc import os +from functools import wraps + from git.odict import OrderedDict from git.util import LockFile from git.compat import ( @@ -67,11 +69,11 @@ class MetaParserBuilder(abc.ABCMeta): def needs_values(func): """Returns method assuring we read values (on demand) before we try to access them""" + @wraps(func) def assure_data_present(self, *args, **kwargs): self.read() return func(self, *args, **kwargs) # END wrapper method - assure_data_present.__name__ = func.__name__ return assure_data_present @@ -477,20 +479,15 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje is_file_lock = isinstance(fp, string_types + (FileType, )) if is_file_lock: self._lock._obtain_lock() - try: - if not hasattr(fp, "seek"): - with open(self._file_or_files, "wb") as fp: - self._write(fp) - else: - fp.seek(0) - # make sure we do not overwrite into an existing file - if hasattr(fp, 'truncate'): - fp.truncate() + if not hasattr(fp, "seek"): + with open(self._file_or_files, "wb") as fp: self._write(fp) - finally: - # we release the lock - it will not vanish automatically in PY3.5+ - if is_file_lock: - self._lock._release_lock() + else: + fp.seek(0) + # make sure we do not overwrite into an existing file + if hasattr(fp, 'truncate'): + fp.truncate() + self._write(fp) def _assure_writable(self, method_name): if self.read_only: |