# HG changeset patch # User Matt Mackall # Date 2011-06-18 21:53:49 # Node ID 87b9d6a7d807979d3ff64df99348b05db0da0636 # Parent 281102f37b243b7b7a576cd931249e6288a4e3f2 fileset: add encoding() predicate diff --git a/mercurial/fileset.py b/mercurial/fileset.py --- a/mercurial/fileset.py +++ b/mercurial/fileset.py @@ -313,11 +313,34 @@ def size(mctx, x): return [f for f in mctx.subset if m(mctx.ctx[f].size())] +def encoding(mctx, x): + """``encoding(name)`` + File can be successfully decoded with the given character + encoding. May not be useful for encodings other than ASCII and + UTF-8. + """ + + enc = getstring(x, _("encoding requires an encoding name")) + + s = [] + for f in mctx.subset: + d = mctx.ctx[f].data() + try: + d.decode(enc) + except LookupError: + raise util.Abort(_("unknown encoding '%s'") % enc) + except UnicodeDecodeError: + continue + s.append(f) + + return s + symbols = { 'added': added, 'binary': binary, 'clean': clean, 'deleted': deleted, + 'encoding': encoding, 'exec': exec_, 'grep': grep, 'ignored': ignored,