comparison 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
comparison
equal deleted inserted replaced
5966:11af38a592ae 5967:f8ad3b76e923
8 from node import * 8 from node import *
9 from i18n import _ 9 from i18n import _
10 import repo, changegroup 10 import repo, changegroup
11 import changelog, dirstate, filelog, manifest, context, weakref 11 import changelog, dirstate, filelog, manifest, context, weakref
12 import re, lock, transaction, tempfile, stat, errno, ui 12 import re, lock, transaction, tempfile, stat, errno, ui
13 import os, revlog, time, util, extensions, hook 13 import os, revlog, time, util, extensions, hook, inspect
14 14
15 class localrepository(repo.repository): 15 class localrepository(repo.repository):
16 capabilities = util.set(('lookup', 'changegroupsubset')) 16 capabilities = util.set(('lookup', 'changegroupsubset'))
17 supported = ('revlogv1', 'store') 17 supported = ('revlogv1', 'store')
18 18
490 for name, filterfn in self._datafilters.iteritems(): 490 for name, filterfn in self._datafilters.iteritems():
491 if cmd.startswith(name): 491 if cmd.startswith(name):
492 fn = filterfn 492 fn = filterfn
493 break 493 break
494 if not fn: 494 if not fn:
495 fn = lambda s, c: util.filter(s, c) 495 fn = lambda s, c, **kwargs: util.filter(s, c)
496 # Wrap old filters not supporting keyword arguments
497 if not inspect.getargspec(fn)[2]:
498 oldfn = fn
499 fn = lambda s, c, **kwargs: oldfn(s, c)
496 l.append((mf, fn, cmd)) 500 l.append((mf, fn, cmd))
497 self.filterpats[filter] = l 501 self.filterpats[filter] = l
498 502
499 for mf, fn, cmd in self.filterpats[filter]: 503 for mf, fn, cmd in self.filterpats[filter]:
500 if mf(filename): 504 if mf(filename):
501 self.ui.debug(_("filtering %s through %s\n") % (filename, cmd)) 505 self.ui.debug(_("filtering %s through %s\n") % (filename, cmd))
502 data = fn(data, cmd) 506 data = fn(data, cmd, ui=self.ui, repo=self, filename=filename)
503 break 507 break
504 508
505 return data 509 return data
506 510
507 def adddatafilter(self, name, filter): 511 def adddatafilter(self, name, filter):