diff mercurial/localrepo.py @ 5967:f8ad3b76e923

Provide better context for custom Python encode/decode filters. While some can function with just some text and an optional command name, others may want a repository object, a ui object, and a file path. Use the enhanced information to good effect in win32text.dumbdecode's warning.
author Jesse Glick <jesse.glick@sun.com>
date Fri, 21 Dec 2007 23:21:17 -0500
parents 11af38a592ae
children 30d2fecaab76
line wrap: on
line diff
--- a/mercurial/localrepo.py	Mon Jan 28 21:39:47 2008 +0100
+++ b/mercurial/localrepo.py	Fri Dec 21 23:21:17 2007 -0500
@@ -10,7 +10,7 @@
 import repo, changegroup
 import changelog, dirstate, filelog, manifest, context, weakref
 import re, lock, transaction, tempfile, stat, errno, ui
-import os, revlog, time, util, extensions, hook
+import os, revlog, time, util, extensions, hook, inspect
 
 class localrepository(repo.repository):
     capabilities = util.set(('lookup', 'changegroupsubset'))
@@ -492,14 +492,18 @@
                         fn = filterfn
                         break
                 if not fn:
-                    fn = lambda s, c: util.filter(s, c)
+                    fn = lambda s, c, **kwargs: util.filter(s, c)
+                # Wrap old filters not supporting keyword arguments
+                if not inspect.getargspec(fn)[2]:
+                    oldfn = fn
+                    fn = lambda s, c, **kwargs: oldfn(s, c)
                 l.append((mf, fn, cmd))
             self.filterpats[filter] = l
 
         for mf, fn, cmd in self.filterpats[filter]:
             if mf(filename):
                 self.ui.debug(_("filtering %s through %s\n") % (filename, cmd))
-                data = fn(data, cmd)
+                data = fn(data, cmd, ui=self.ui, repo=self, filename=filename)
                 break
 
         return data