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

Huayang Guo huayang at fb.com
Wed Oct 17 12:24:37 CDT 2012


# HG changeset patch
# User Huayang <huayang at fb.com>
# Date 1349479654 25200
# Node ID d8850dd60eb381a42eadff3b79a99b00cdd20938
# 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 d8850dd60eb3 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 d8850dd60eb3 tests/test-issue3612.t
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-issue3612.t	Fri Oct 05 16:27:34 2012 -0700
@@ -0,0 +1,87 @@
+  $ cat >> $HGRCPATH <<EOF
+  > [extensions]
+  > convert=
+  > EOF
+
+Clean up and create a test repository.
+
+  $ rm -rf a
+  $ rm -rf b
+  $ rm -rf f
+  $ mkdir a
+  $ cd a
+  $ hg init
+  $ mkdir foo 
+  $ echo a > foo/a
+  $ echo b > foo/b
+  $ echo c > foo/c
+  $ echo d > foo/d
+  $ hg addremove
+  adding foo/a
+  adding foo/b
+  adding foo/c
+  adding foo/d
+  $ hg ci -m "commit original repository"
+  $ cd ..
+
+Create filemap
+
+  $ 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
+
+Convert repository
+
+  $ hg convert --filemap f a b 
+  initializing destination b repository
+  scanning source...
+  sorting...
+  converting...
+  0 commit original repository
+
+All the files should be tracked in the converted repository.
+
+  $ cd b
+  $ hg up
+  4 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg st            ## File foo/bar/a is untracked??
+
+There should be no double slashes in the manifest.
+
+  $ hg manifest
+  foo/bar/a
+  foo/bar/b
+  foo/bar/c
+  foo/bar/d
+
+Try to add duplicated files. Should fail. 
+
+  $ hg add foo/bar//a 
+  foo/bar/a already tracked!
+  $ hg add foo///bar/b 
+  foo/bar/b already tracked!
+  $ hg add foo/bar/../bar/./c 
+  foo/bar/c already tracked!
+  $ hg add foo/bar/d 
+  foo/bar/d already tracked!
+  $ hg ci -m "lol"
+  nothing changed
+  [1]
+
+Print manifest. Should be no duplicated files.
+
+  $ hg manifest
+  foo/bar/a
+  foo/bar/b
+  foo/bar/c
+  foo/bar/d
+
+Final verification.
+
+  $ hg verify
+  checking changesets
+  checking manifests
+  crosschecking files in changesets and manifests
+  checking files
+  4 files, 1 changesets, 4 total revisions


More information about the Mercurial-devel mailing list