diff mercurial/fileset.py @ 18842:3ce3f2b059a1

filesets: add eol predicate
author Matt Mackall <mpm@selenic.com>
date Fri, 29 Mar 2013 16:48:32 -0700
parents 6252b4f1c4b4
children 1d08df65cd3c
line wrap: on
line diff
--- a/mercurial/fileset.py	Fri Mar 29 15:27:33 2013 -0700
+++ b/mercurial/fileset.py	Fri Mar 29 16:48:32 2013 -0700
@@ -353,6 +353,29 @@
 
     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('(?<!\r)\n', d):
+            s.append(f)
+        elif enc == 'mac' and re.search('\r(?!\n)', d):
+            s.append(f)
+    return s
+
 def copied(mctx, x):
     """``copied()``
     File that is recorded as being copied.
@@ -395,6 +418,7 @@
     'copied': copied,
     'deleted': deleted,
     'encoding': encoding,
+    'eol': eol,
     'exec': exec_,
     'grep': grep,
     'ignored': ignored,