interhg: use uisetup() instead of module-load side effects
authorAugie Fackler <durin42@gmail.com>
Sat, 16 Oct 2010 18:09:47 -0500
changeset 12766 21a50fe47a92
parent 12765 5eed9ceebd64
child 12767 c3316b6a3219
interhg: use uisetup() instead of module-load side effects This fixes an infinite recursion bug caused by visiting a bad subpage of the help handler repeatedly, which caused the wrapper for the templater's escape filter to get installed twice and resulted in infinite recursion.
hgext/interhg.py
--- a/hgext/interhg.py	Mon Oct 18 23:20:14 2010 -0500
+++ b/hgext/interhg.py	Sat Oct 16 18:09:47 2010 -0500
@@ -28,17 +28,18 @@
 from mercurial import templatefilters, extensions
 from mercurial.i18n import _
 
-orig_escape = templatefilters.filters["escape"]
-
 interhg_table = []
 
-def interhg_escape(x):
-    escstr = orig_escape(x)
-    for regexp, format in interhg_table:
-        escstr = regexp.sub(format, escstr)
-    return escstr
+def uisetup(ui):
+    orig_escape = templatefilters.filters["escape"]
 
-templatefilters.filters["escape"] = interhg_escape
+    def interhg_escape(x):
+        escstr = orig_escape(x)
+        for regexp, format in interhg_table:
+            escstr = regexp.sub(format, escstr)
+        return escstr
+
+    templatefilters.filters["escape"] = interhg_escape
 
 def interhg_refresh(orig, self, *args, **kwargs):
     interhg_table[:] = []