From 22a0289972b365b7912340501b52ca3dd98be289 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 3 May 2010 23:20:51 +0200 Subject: Index: handling an AttributeError exception raised in python 2.6.5 and newer if an unset slot is being deleted. --- lib/git/index.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'lib/git/index.py') diff --git a/lib/git/index.py b/lib/git/index.py index 6f615024..0741d71a 100644 --- a/lib/git/index.py +++ b/lib/git/index.py @@ -248,7 +248,7 @@ def clear_cache(func): """ def clear_cache_if_not_raised(self, *args, **kwargs): rval = func(self, *args, **kwargs) - del(self.entries) + self._delete_entries_cache() return rval # END wrapper method @@ -345,6 +345,15 @@ class IndexFile(LazyMixin, diff.Diffable): """ return self._file_path + def _delete_entries_cache(self): + """Safely clear the entries cache so it can be recreated""" + try: + del(self.entries) + except AttributeError: + # fails in python 2.6.5 with this exception + pass + # END exception handling + @classmethod def _read_entry(cls, stream): """Return: One entry of the given stream""" @@ -774,7 +783,7 @@ class IndexFile(LazyMixin, diff.Diffable): Returns self """ - del(self.entries) + self._delete_entries_cache() # allows to lazily reread on demand return self @@ -937,7 +946,7 @@ class IndexFile(LazyMixin, diff.Diffable): self._flush_stdin_and_wait(proc, ignore_stdout=True) # ignore stdout # force rereading our entries once it is all done - del(self.entries) + self._delete_entries_cache() entries_added.extend(self.entries[(f,0)] for f in added_files) # END path handling -- cgit v1.2.1