Mercurial > hg
changeset 17797:e4da793998bf
convert: normalize paths in filemaps (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.
author | Huayang <huayang@fb.com> |
---|---|
date | Fri, 05 Oct 2012 16:27:34 -0700 |
parents | 1b51638bf44a |
children | 4091b0322918 |
files | hgext/convert/filemap.py tests/test-convert-filemap.t |
diffstat | 2 files changed, 17 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/convert/filemap.py Wed Oct 17 15:37:25 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 @@ -16,6 +17,13 @@ e = name.rfind('/', 0, e) yield '.', name +def normalize(path): + ''' We use posixpath.normpath to support cross-platform path format. + However, it doesn't handle None input. So we wrap it up. ''' + if path is None: + return None + return posixpath.normpath(path) + class filemapper(object): '''Map and filter filenames when importing. A name can be mapped to itself, a new name, or None (omit from new @@ -53,21 +61,21 @@ cmd = lex.get_token() while cmd: if cmd == 'include': - name = lex.get_token() + name = normalize(lex.get_token()) errs += check(name, self.exclude, 'exclude') self.include[name] = name elif cmd == 'exclude': - name = lex.get_token() + name = normalize(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 = normalize(lex.get_token()) + dest = normalize(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(normalize(lex.get_token())) else: self.ui.warn(_('%s:%d: unknown directive %r\n') % (lex.infile, lex.lineno, cmd)) @@ -76,6 +84,7 @@ return errs def lookup(self, name, mapping): + name = normalize(name) for pre, suf in rpairs(name): try: return mapping[pre], pre, suf
--- a/tests/test-convert-filemap.t Wed Oct 17 15:37:25 2012 -0500 +++ b/tests/test-convert-filemap.t Fri Oct 05 16:27:34 2012 -0700 @@ -229,11 +229,11 @@ $ cat > renames.fmap <<EOF > include dir > exclude dir/file2 - > rename dir dir2 + > rename dir dir2//../dir2/ > include foo > include copied - > rename foo foo2 - > rename copied copied2 + > rename foo foo2/ + > rename copied ./copied2 > exclude dir/subdir > include dir/subdir/file3 > EOF @@ -284,10 +284,8 @@ > include > EOF $ hg -q convert --filemap errors.fmap source errors.repo - errors.fmap:1: superfluous / in exclude 'dir/' errors.fmap:3: superfluous / in include '/dir' errors.fmap:3: superfluous / in rename '/dir' - errors.fmap:3: superfluous / in exclude 'dir//dir' errors.fmap:4: unknown directive 'out of sync' errors.fmap:5: path to exclude is missing abort: errors in filemap