Patchwork [RFC] fileset: add a fileset for portable filenames

login
register
mail settings
Submitter Siddharth Agarwal
Date March 20, 2015, 5:33 a.m.
Message ID <3ab27df1ab6aee8cae16.1426829609@devbig136.prn2.facebook.com>
Download mbox | patch
Permalink /patch/8197/
State Accepted
Commit caa6b6c65dc37dee6db000ff33d089f52e562905
Headers show

Comments

Siddharth Agarwal - March 20, 2015, 5:33 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1426825578 25200
#      Thu Mar 19 21:26:18 2015 -0700
# Node ID 3ab27df1ab6aee8cae16f9bc690e76f930931b4a
# Parent  dc7588ce06b30a6ef347f7554e9646ac00e4456a
fileset: add a fileset for portable filenames

This has mostly the same semantics as the files that the 'ui.portablefilenames'
config option would warn or abort about. The only difference is filenames that
case-fold to the same string -- given a set of filenames we've already
checked we can check whether a new one collides with them, but we don't have a
way to tell which filename it collided with.
Matt Mackall - March 20, 2015, 7:40 p.m.
On Thu, 2015-03-19 at 22:33 -0700, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0@fb.com>
> # Date 1426825578 25200
> #      Thu Mar 19 21:26:18 2015 -0700
> # Node ID 3ab27df1ab6aee8cae16f9bc690e76f930931b4a
> # Parent  dc7588ce06b30a6ef347f7554e9646ac00e4456a
> fileset: add a fileset for portable filenames

LGTM. Queued for default.

Patch

diff --git a/mercurial/fileset.py b/mercurial/fileset.py
--- a/mercurial/fileset.py
+++ b/mercurial/fileset.py
@@ -256,6 +256,16 @@ 
     ignore = mctx.ctx.repo().dirstate._ignore
     return [f for f in mctx.subset if ignore(f)]
 
+def portable(mctx, x):
+    """``portable()``
+    File that has a portable name. (This doesn't include filenames with case
+    collisions.)
+    """
+    # i18n: "portable" is a keyword
+    getargs(x, 0, 0, _("portable takes no arguments"))
+    checkwinfilename = util.checkwinfilename
+    return [f for f in mctx.subset if checkwinfilename(f) is None]
+
 def grep(mctx, x):
     """``grep(regex)``
     File contains the given regular expression.
@@ -416,6 +426,7 @@ 
     'ignored': ignored,
     'hgignore': hgignore,
     'modified': modified,
+    'portable': portable,
     'removed': removed,
     'resolved': resolved,
     'size': size,
diff --git a/tests/test-fileset.t b/tests/test-fileset.t
--- a/tests/test-fileset.t
+++ b/tests/test-fileset.t
@@ -111,6 +111,28 @@ 
   $ hg add b2link
 #endif
 
+#if no-windows
+  $ echo foo > con.xml
+  $ echo bar > 'bar '
+  $ echo baz > 'baz\'
+  $ ls
+  b1
+  b2
+  b2link
+  bar 
+  baz\
+  bin
+  c1
+  c2
+  c3
+  con.xml
+  $ fileset 'not portable()'
+  bar 
+  baz\
+  con.xml
+  $ hg --config ui.portablefilenames=ignore add con.xml 'bar ' 'baz\'
+#endif
+
   >>> file('1k', 'wb').write(' '*1024)
   >>> file('2k', 'wb').write(' '*2048)
   $ hg add 1k 2k
@@ -220,6 +242,13 @@ 
   b2link
 #endif
 
+#if no-windows
+  $ fileset -r1 'not portable()'
+  bar 
+  baz\
+  con.xml
+#endif
+
   $ fileset -r4 'subrepo("re:su.*")'
   sub
   $ fileset -r4 'subrepo("sub")'
@@ -242,7 +271,10 @@ 
   a1
   b1
   b2
+  bar 
+  baz\
   c1
+  con.xml
   mixed
   $ fileset 'eol(mac)'
   mac