[PATCH 1 of 2] convert: Support glob exclude patterns
Tessa Starkey
testarkey at gmail.com
Tue Feb 2 13:07:18 CST 2010
# HG changeset patch
# User Tessa Starkey <testarkey at gmail.com>
# Date 1265132627 18000
# Node ID 052ab4a8d877c59c398a7ed2f52644387dc56d9b
# Parent d9aa5b368e36c10d2c29411772fef9fd339c2e9f
convert: Support glob exclude patterns
diff --git a/hgext/convert/__init__.py b/hgext/convert/__init__.py
--- a/hgext/convert/__init__.py
+++ b/hgext/convert/__init__.py
@@ -84,15 +84,19 @@
exclude path/to/file
+ glob_exclude path/to/file
+
rename from/file to/file
- The 'include' directive causes a file, or all files under a
- directory, to be included in the destination repository, and the
- exclusion of all other files and directories not explicitly
- included. The 'exclude' directive causes files or directories to
- be omitted. The 'rename' directive renames a file or directory. To
- rename from a subdirectory into the root of the repository, use
- '.' as the path to rename to.
+ The 'include' directive causes a file, or all files under
+ a directory, to be included in the destination repository,
+ and the exclusion of all other files and directories not
+ explicitly included. The 'exclude' directive causes files
+ or directories to be omitted. The 'glob_exclude' directive also
+ causes files or directories to be omitted and allows the use of
+ glob wildcards '*' and '?'.The 'rename' directive renames a file
+ or directory. To rename from a subdirectory into the root of the
+ repository, use '.' as the path to rename to.
The splicemap is a file that allows insertion of synthetic
history, letting you specify the parents of a revision. This is
diff --git a/hgext/convert/filemap.py b/hgext/convert/filemap.py
--- a/hgext/convert/filemap.py
+++ b/hgext/convert/filemap.py
@@ -4,15 +4,17 @@
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
+import fnmatch
import shlex
from mercurial.i18n import _
from mercurial import util
from common import SKIPREV, converter_source
def rpairs(name):
+ """ yields all suffix-prefix pairs of the given file path"""
e = len(name)
while e != -1:
- yield name[:e], name[e + 1:]
+ yield name[:e], name[e+1:]
e = name.rfind('/', 0, e)
yield '.', name
@@ -25,6 +27,7 @@
self.ui = ui
self.include = {}
self.exclude = {}
+ self.globexclude = []
self.rename = {}
if path:
if self.parse(path):
@@ -32,6 +35,14 @@
def parse(self, path):
errs = 0
+ def checkglob(names,globs):
+ for name in names:
+ for glob in globs:
+ if fnmatch.fnmatch(name, glob):
+ self.ui.warn(_('%s:%d: %r matches %r\n') %
+ (lex.infile, lex.lineno, name, glob))
+ return 1
+ return 0
def check(name, mapping, listname):
if name in mapping:
self.ui.warn(_('%s:%d: %r already in %s list\n') %
@@ -45,16 +56,23 @@
if cmd == 'include':
name = lex.get_token()
errs += check(name, self.exclude, 'exclude')
+ errs += checkglob([name], self.globexclude)
self.include[name] = name
elif cmd == 'exclude':
name = lex.get_token()
errs += check(name, self.include, 'include')
errs += check(name, self.rename, 'rename')
self.exclude[name] = name
+ elif cmd == 'glob_exclude':
+ name = lex.get_token()
+ errs += checkglob(self.include.keys(),[name])
+ errs += checkglob(self.rename.keys(), [name])
+ self.globexclude.append(name)
elif cmd == 'rename':
src = lex.get_token()
dest = lex.get_token()
errs += check(src, self.exclude, 'exclude')
+ errs += checkglob([src], self.globexclude);
self.rename[src] = dest
elif cmd == 'source':
errs += self.parse(lex.get_token())
@@ -72,6 +90,11 @@
except KeyError:
pass
return '', name, ''
+ def globlookup(self, name, globlist):
+ for pattern in globlist:
+ if fnmatch.fnmatch(name, pattern):
+ return name, name, ''
+ return '', name, ''
def __call__(self, name):
if self.include:
@@ -82,6 +105,8 @@
exc = self.lookup(name, self.exclude)[0]
else:
exc = ''
+ if ((not self.exclude) or exc == '') and self.globexclude:
+ exc = self.globlookup(name, self.globexclude)[0]
if (not self.include and exc) or (len(inc) <= len(exc)):
return None
newpre, pre, suf = self.lookup(name, self.rename)
More information about the Mercurial-devel
mailing list