[PATCH] convert: normalize paths in convert (issue3612)

Huayang Guo huayang at fb.com
Tue Oct 16 19:45:44 CDT 2012


# HG changeset patch
# User Huayang <huayang at fb.com>
# Date 1349479654 25200
# Node ID 4ec508992e447cff2186fe2212ffd6dfeec6d397
# Parent  fa714f3ed2989aff64c267c9935251d9fc4f31ee
convert: normalize paths in convert (issue3612)

convert doesn't normalise double slashes in paths. Path normalization
is applied when a path is loaded into filemap and when a file lookup
request is issued to filemap.

diff -r fa714f3ed298 -r 4ec508992e44 hgext/convert/filemap.py
--- a/hgext/convert/filemap.py	Mon Oct 01 23:05:02 2012 -0500
+++ b/hgext/convert/filemap.py	Fri Oct 05 16:27:34 2012 -0700
@@ -4,6 +4,7 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
+import posixpath
 import shlex
 from mercurial.i18n import _
 from mercurial import util
@@ -53,21 +54,21 @@
         cmd = lex.get_token()
         while cmd:
             if cmd == 'include':
-                name = lex.get_token()
+                name = posixpath.normpath(lex.get_token())
                 errs += check(name, self.exclude, 'exclude')
                 self.include[name] = name
             elif cmd == 'exclude':
-                name = lex.get_token()
+                name = posixpath.normpath(lex.get_token())
                 errs += check(name, self.include, 'include')
                 errs += check(name, self.rename, 'rename')
                 self.exclude[name] = name
             elif cmd == 'rename':
-                src = lex.get_token()
-                dest = lex.get_token()
+                src = posixpath.normpath(lex.get_token())
+                dest = posixpath.normpath(lex.get_token())
                 errs += check(src, self.exclude, 'exclude')
                 self.rename[src] = dest
             elif cmd == 'source':
-                errs += self.parse(lex.get_token())
+                errs += self.parse(posixpath.normpath(lex.get_token()))
             else:
                 self.ui.warn(_('%s:%d: unknown directive %r\n') %
                              (lex.infile, lex.lineno, cmd))
@@ -76,6 +77,7 @@
         return errs
 
     def lookup(self, name, mapping):
+        name = posixpath.normpath(name)
         for pre, suf in rpairs(name):
             try:
                 return mapping[pre], pre, suf
diff -r fa714f3ed298 -r 4ec508992e44 tests/test-issue3612.sh
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-issue3612.sh	Fri Oct 05 16:27:34 2012 -0700
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+rm -rf a
+rm -rf b
+rm -rf f
+
+mkdir a
+cd a
+~/hg/hg init
+mkdir foo
+echo a > foo/a
+echo b > foo/b
+echo c > foo/c
+echo d > foo/d
+~/hg/hg addremove
+~/hg/hg ci -m "abcd"
+cd ..
+echo "rename foo/a foo//bar//a" > f
+echo "rename foo/b foo/../foo///./bar/./b" >> f
+echo "rename foo/c foo//bar/c" >> f
+echo "rename foo/d foo//bar/d" >> f
+echo
+echo
+echo "converting"
+~/hg/hg convert --filemap f a b
+cd b
+~/hg/hg up
+~/hg/hg st            ## File foo/bar/a is untracked??
+echo 
+echo 
+echo "Printing manifest: "
+~/hg/hg manifest      ## Double slashes in manifest??
+echo 
+echo 
+echo "Adding foo/bar/a again: "
+~/hg/hg add foo/bar//a ## Ok, fine, let's add it again.
+~/hg/hg add foo///bar/b ## Ok, fine, let's add it again.
+~/hg/hg add foo/bar/../bar/./c ## Ok, fine, let's add it again.
+~/hg/hg add foo/bar/d ## Ok, fine, let's add it again.
+~/hg/hg ci -m "lol"
+echo 
+echo 
+echo "Printing manifest again: "
+~/hg/hg manifest      ## Double slashes in manifest??
+echo 
+echo 
+echo "Verifying: "
+~/hg/hg verify        ## Repo corruption?


More information about the Mercurial-devel mailing list