[PATCH] move checkfilename from util to scmutil

Adrian Buehlmann adrian at cadifra.com
Thu Apr 21 07:21:38 CDT 2011


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1303384732 -7200
# Node ID 23f2736abce3788eea5e9b08c558bc5654196760
# Parent  366fa83f9820b97b438cb2972b1f2f7b9edab037
move checkfilename from util to scmutil

checkfilename is specific to Mercurial, since it contains the knowledege
that Mercurial can't track files with \n or \r in the name.

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -7,7 +7,7 @@
 
 from node import nullid
 from i18n import _
-import util, ignore, osutil, parsers, encoding
+import scmutil, util, ignore, osutil, parsers, encoding
 import struct, os, stat, errno
 import cStringIO
 
@@ -269,7 +269,7 @@
     def _addpath(self, f, check=False):
         oldstate = self[f]
         if check or oldstate == "r":
-            util.checkfilename(f)
+            scmutil.checkfilename(f)
             if f in self._dirs:
                 raise util.Abort(_('directory %r already in dirstate') % f)
             # shadows
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -9,9 +9,14 @@
 import util, error
 import os, errno, stat
 
+def checkfilename(f):
+    '''Check that the filename f is an acceptable filename for a tracked file'''
+    if '\r' in f or '\n' in f:
+        raise util.Abort(_("'\\n' and '\\r' disallowed in filenames: %r") % f)
+
 def checkportable(ui, f):
     '''Check if filename f is portable and warn or abort depending on config'''
-    util.checkfilename(f)
+    checkfilename(f)
     val = ui.config('ui', 'portablefilenames', 'warn')
     lval = val.lower()
     abort = os.name == 'nt' or lval == 'abort'
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -445,11 +445,6 @@
 
     return hardlink, num
 
-def checkfilename(f):
-    '''Check that the filename f is an acceptable filename for a tracked file'''
-    if '\r' in f or '\n' in f:
-        raise Abort(_("'\\n' and '\\r' disallowed in filenames: %r") % f)
-
 _windows_reserved_filenames = '''con prn aux nul
     com1 com2 com3 com4 com5 com6 com7 com8 com9
     lpt1 lpt2 lpt3 lpt4 lpt5 lpt6 lpt7 lpt8 lpt9'''.split()


More information about the Mercurial-devel mailing list