diff --git a/mercurial/context.py b/mercurial/context.py
index c010cb6fdef787d3493725e1403d0a6f19b704d9_bWVyY3VyaWFsL2NvbnRleHQucHk=..36067f5baf2475580a519468e347569181d945d9_bWVyY3VyaWFsL2NvbnRleHQucHk= 100644
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -713,6 +713,7 @@
                         curr = pair(hist[p], curr)
                     if needed[p] == 1:
                         del hist[p]
+                        del needed[p]
                     else:
                         needed[p] -= 1