[PATCH] clone/pull: abort on reserved filenames on Windows (2nd update)

Adrian Buehlmann adrian at cadifra.com
Fri Jun 13 08:29:44 CDT 2008


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1213350646 -7200
# Node ID 19ac628fc2ff53d908bcb7304d78aababaa76af5
# Parent  034f444902d91be51c5938463a1e25fdb5d0f0c3
clone/pull: abort on reserved filenames on Windows

hg clone hangs forever on Windows when pulling from
a remote repository (on unix) containing a file with
a filename equal to a Windows reserved filename.
With this change, hg clone now aborts with an error
message (see issue793)

diff -r 034f444902d9 -r 19ac628fc2ff mercurial/localrepo.py
--- a/mercurial/localrepo.py	Thu Jun 12 07:38:15 2008 -0500
+++ b/mercurial/localrepo.py	Fri Jun 13 11:50:46 2008 +0200
@@ -2005,6 +2005,8 @@
                 f = changegroup.getchunk(source)
                 if not f:
                     break
+                if util.unsupported_path(f):
+                    raise util.Abort(_("path '%s' is not supported") % f)
                 self.ui.debug(_("adding %s revisions\n") % f)
                 fl = self.file(f)
                 o = fl.count()
diff -r 034f444902d9 -r 19ac628fc2ff mercurial/util.py
--- a/mercurial/util.py	Thu Jun 12 07:38:15 2008 -0500
+++ b/mercurial/util.py	Fri Jun 13 11:50:46 2008 +0200
@@ -936,10 +936,23 @@
 def lookup_reg(key, name=None, scope=None):
     return None

+_reserved_windows_filenames = '''CON PRN AUX NUL
+    COM1 COM2 COM3 COM4 COM5 COM6 COM7 COM8 COM9
+    LPT1 LPT2 LPT3 LPT4 LPT5 LPT6 LPT7 LPT8 LPT9'''.split()
+def win_unsupported_path(p):
+    '''True, if tracked path p cannot be stored below .hg on Windows
+    (using the current path encoding and repo layout).
+    p is repo-relative and must use '/' as path separator'''
+    for n in p.split('/'):
+        if n and n.upper() in _reserved_windows_filenames:
+            return True
+    return False
+
 # Platform specific variants
 if os.name == 'nt':
     import msvcrt
     nulldev = 'NUL:'
+    unsupported_path = win_unsupported_path

     class winstdout:
         '''stdout on windows misbehaves if sent through a pipe'''
@@ -1131,6 +1144,7 @@

 else:
     nulldev = '/dev/null'
+    unsupported_path = lambda p: False # no unsupported paths

     def rcfiles(path):
         rcs = [os.path.join(path, 'hgrc')]



More information about the Mercurial-devel mailing list