[patch] syntax:plain for .hgignore
Johannes Hofmann
Johannes.Hofmann at gmx.de
Wed Sep 5 09:57:00 CDT 2007
In a project at work we have a large repository with many generated
files that have no specific extension (mostly executables).
Therefore the .hgignore file is pretty large (more than 500 lines).
In this setup "syntax:plain" (see patch below) speeds up hg status
from 2.5s to about 1s.
I'm not really familiar with python so this can probabely done more
elegantly.
Johannes
diff --git a/mercurial/ignore.py b/mercurial/ignore.py
--- a/mercurial/ignore.py
+++ b/mercurial/ignore.py
@@ -41,7 +41,7 @@ def ignore(root, files, warn):
glob:pattern # non-rooted glob
pattern # pattern of the current default type'''
- syntaxes = {'re': 'relre:', 'regexp': 'relre:', 'glob': 'relglob:'}
+ syntaxes = {'re': 'relre:', 'regexp': 'relre:', 'glob': 'relglob:', 'plain': 'plain:'}
pats = {}
for f in files:
try:
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -271,7 +271,7 @@ def patkind(name, dflt_pat='glob'):
def patkind(name, dflt_pat='glob'):
"""Split a string into an optional pattern kind prefix and the
actual pattern."""
- for prefix in 're', 'glob', 'path', 'relglob', 'relpath', 'relre':
+ for prefix in 're', 'glob', 'path', 'relglob', 'relpath', 'relre', 'plain':
if name.startswith(prefix + ':'): return name.split(':', 1)
return dflt_pat, name
@@ -475,8 +475,11 @@ def _matcher(canonroot, cwd, names, inc,
if not pats:
return
try:
+ plainpats = [p for (k,p) in pats if k == 'plain']
+ pats = [(k,p) for (k,p) in pats if not k == 'plain']
pat = '(?:%s)' % '|'.join([regex(k, p, tail) for (k, p) in pats])
- return re.compile(pat).match
+ comppat = re.compile(pat)
+ return lambda a : a in plainpats or pats and comppat.match(a)
except OverflowError:
# We're using a Python with a tiny regex engine and we
# made it explode, so we'll divide the pattern list in two
diff --git a/tests/test-hgignore b/tests/test-hgignore
--- a/tests/test-hgignore
+++ b/tests/test-hgignore
@@ -63,5 +63,8 @@ echo "relglob:*" > .hgignore
echo "relglob:*" > .hgignore
echo "--" ; hg status
+echo "plain:dir/c.o" > .hgignore
+echo "--" ; hg status
+
cd dir
echo "--" ; hg status .
diff --git a/tests/test-hgignore.out b/tests/test-hgignore.out
--- a/tests/test-hgignore.out
+++ b/tests/test-hgignore.out
@@ -50,4 +50,10 @@ A dir/b.o
--
A dir/b.o
--
+A dir/b.o
+? .hgignore
+? a.c
+? a.o
+? syntax
+--
A b.o
More information about the Mercurial
mailing list