Browse Source

DiskRefsContainer: don't crash deleting a ref without peeled refs

It's a valid state to have loaded packed refs but not have any peeled
refs. Prior to this change, attempting to delete a tag in that
configuration would cause a traceback when checking 'if name in
self._peeled_refs' since self._peeled_refs was None.

Change-Id: I442d8dd4c97316c6295c9dbdace088feeedddd35
Augie Fackler 15 years ago
parent
commit
fa8ef1f833
1 changed files with 3 additions and 1 deletions
  1. 3 1
      dulwich/repo.py

+ 3 - 1
dulwich/repo.py

@@ -433,7 +433,10 @@ class DiskRefsContainer(RefsContainer):
         """
         # TODO: invalidate the cache on repacking
         if self._packed_refs is None:
+            # set both to empty because we want _peeled_refs to be
+            # None if and only if _packed_refs is also None.
             self._packed_refs = {}
+            self._peeled_refs = {}
             path = os.path.join(self.path, 'packed-refs')
             try:
                 f = GitFile(path, 'rb')
@@ -445,7 +448,6 @@ class DiskRefsContainer(RefsContainer):
                 first_line = iter(f).next().rstrip()
                 if (first_line.startswith("# pack-refs") and " peeled" in
                         first_line):
-                    self._peeled_refs = {}
                     for sha, name, peeled in read_packed_refs_with_peeled(f):
                         self._packed_refs[name] = sha
                         if peeled: