[PATCH 1 of 3] match: make 'listfile:' split on LF and CRLF

Patrick Mezard pmezard at gmail.com
Sat May 7 11:54:10 CDT 2011


# HG changeset patch
# User Patrick Mezard <pmezard at gmail.com>
# Date 1304785665 -7200
# Node ID 2d0e8c441bc5b938f71107fb1c8928b97b7bc536
# Parent  c9720ada999c17cc9d1d7aa64f0851cd68df428b
match: make 'listfile:' split on LF and CRLF

We want util.readfile() to operate in binary mode, so EOLs have to be handled
correctly depending on the platform. It seems both easier and more convenient
to treat LF and CRLF the same way on all platforms.

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -273,9 +273,12 @@
         elif kind in ('relglob', 'path'):
             name = util.normpath(name)
         elif kind in ('listfile', 'listfile0'):
-            delimiter = kind == 'listfile0' and '\0' or '\n'
             try:
-                files = util.readfile(name).split(delimiter)
+                files = util.readfile(name)
+                if kind == 'listfile0':
+                    files = files.split('\0')
+                else:
+                    files = files.splitlines()
                 files = [f for f in files if f]
             except EnvironmentError:
                 raise util.Abort(_("unable to read file list (%s)") % name)
diff --git a/tests/test-walk.t b/tests/test-walk.t
--- a/tests/test-walk.t
+++ b/tests/test-walk.t
@@ -295,6 +295,18 @@
   $ hg debugwalk ignored/file
   f  ignored/file  ignored/file  exact
 
+Test listfile and listfile0
+
+  $ python -c "file('../listfile0', 'wb').write('fenugreek\0new\0')"
+  $ hg debugwalk -I 'listfile0:../listfile0'
+  f  fenugreek  fenugreek
+  f  new        new
+  $ python -c "file('../listfile', 'wb').write('fenugreek\nnew\r\nmammals/skunk\n')"
+  $ hg debugwalk -I 'listfile:../listfile'
+  f  fenugreek      fenugreek
+  f  mammals/skunk  mammals/skunk
+  f  new            new
+
   $ cd ..
   $ hg debugwalk -R t t/mammals/skunk
   f  mammals/skunk  t/mammals/skunk  exact


More information about the Mercurial-devel mailing list