# HG changeset patch # User Matt Mackall # Date 2013-03-29 23:48:32 # Node ID 3ce3f2b059a1c1ab2b7b125a864bb48d20030f16 # Parent e978fb3038e08e8611e978e88f0b0bd31dd406e3 filesets: add eol predicate diff --git a/mercurial/fileset.py b/mercurial/fileset.py --- a/mercurial/fileset.py +++ b/mercurial/fileset.py @@ -353,6 +353,29 @@ def encoding(mctx, x): return s +def eol(mctx, x): + """``eol(style)`` + File contains newlines of the given style (dos, unix, mac). Binary + files are excluded, files with mixed line endings match multiple + styles. + """ + + # i18n: "encoding" is a keyword + enc = getstring(x, _("encoding requires an encoding name")) + + s = [] + for f in mctx.existing(): + d = mctx.ctx[f].data() + if util.binary(d): + continue + if (enc == 'dos' or enc == 'win') and '\r\n' in d: + s.append(f) + elif enc == 'unix' and re.search('(?>> open('dos', 'wb').write("dos\r\n") + >>> open('mixed', 'wb').write("dos\r\nunix\n") + >>> open('mac', 'wb').write("mac\r") + $ hg add dos mixed mac + + $ fileset 'eol(dos)' + dos + mixed + $ fileset 'eol(unix)' + .hgsub + .hgsubstate + a1 + b1 + b2 + c1 + mixed + $ fileset 'eol(mac)' + mac