[PATCH] convert: warn on superfluous / in paths

Mads Kiilerich mads at kiilerich.com
Tue Jul 20 08:50:48 CDT 2010


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1279633768 -7200
# Node ID 216f9a07e1bc41ae4faba1da017279aa7f114b43
# Parent  fda0e478fb7945b15110738885b8f54bcf2ff576
convert: warn on superfluous / in paths

shlex is really a bad parser for this line-based format ...

diff --git a/hgext/convert/filemap.py b/hgext/convert/filemap.py
--- a/hgext/convert/filemap.py
+++ b/hgext/convert/filemap.py
@@ -33,10 +33,20 @@
     def parse(self, path):
         errs = 0
         def check(name, mapping, listname):
+            if not name:
+                self.ui.warn(_('%s:%d: path to %s is missing\n') %
+                             (lex.infile, lex.lineno, listname))
+                return 1
             if name in mapping:
                 self.ui.warn(_('%s:%d: %r already in %s list\n') %
                              (lex.infile, lex.lineno, name, listname))
                 return 1
+            if (name.startswith('/') or
+                name.endswith('/') or
+                '//' in name):
+                self.ui.warn(_('%s:%d: superfluous / in %s %r\n') %
+                             (lex.infile, lex.lineno, listname, name))
+                return 1
             return 0
         lex = shlex.shlex(open(path), path, True)
         lex.wordchars += '!@#$%^&*()-=+[]{}|;:,./<>?'
diff --git a/tests/test-convert-filemap b/tests/test-convert-filemap
--- a/tests/test-convert-filemap
+++ b/tests/test-convert-filemap
@@ -128,3 +128,14 @@
 hg --cwd source cat copied
 echo 'copied2:'
 hg --cwd renames.repo cat copied2
+
+echo % filemap errors
+cat > errors.fmap <<EOF
+include dir/ # beware that comments changes error line numbers!
+exclude /dir
+rename dir//dir /dir//dir/ "out of sync"
+include
+EOF
+hg -q convert --filemap errors.fmap source errors.repo
+
+true # happy ending
diff --git a/tests/test-convert-filemap.out b/tests/test-convert-filemap.out
--- a/tests/test-convert-filemap.out
+++ b/tests/test-convert-filemap.out
@@ -157,3 +157,11 @@
 foo
 copied2:
 foo
+% filemap errors
+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


More information about the Mercurial-devel mailing list