censor: use a reasonable amount of memory
authorValentin Gatien-Baron <vgatien-baron@janestreet.com>
Thu, 13 Sep 2018 16:22:53 -0400
changeset 39615 a658f97c1ce4
parent 39614 a2880ac67ee0
child 39616 5a2bf7f941fa
censor: use a reasonable amount of memory Before this change, trying to censor some random revision uses an ever increasing amount of memory (I stopped at 20GB, but it was by no means finished), presumably because these contexts have a lot of information that is kept alive. After this change, the memory usage plateaus quickly. Differential Revision: https://phab.mercurial-scm.org/D4582
hgext/censor.py
--- a/hgext/censor.py	Fri Sep 14 22:25:44 2018 +0900
+++ b/hgext/censor.py	Thu Sep 13 16:22:53 2018 -0400
@@ -83,8 +83,11 @@
         raise error.Abort(_('file does not exist at revision %s') % rev)
 
     fnode = fctx.filenode()
-    headctxs = [repo[c] for c in repo.heads()]
-    heads = [c for c in headctxs if path in c and c.filenode(path) == fnode]
+    heads = []
+    for headnode in repo.heads():
+        c = repo[headnode]
+        if path in c and c.filenode(path) == fnode:
+            heads.append(c)
     if heads:
         headlist = ', '.join([short(c.node()) for c in heads])
         raise error.Abort(_('cannot censor file in heads (%s)') % headlist,