[PATCH] convert: changed the filemapper filtering algorithm to prefer more specific include/exclude rules

Štefan Šimek simek at triaxis.sk
Wed Nov 18 13:16:37 CST 2009


Hi,

I'm resubmitting this patch (originally submitted on 2009-11-10)

This is a patch to make the filemapper filtering functionality in the
convert extension a bit more usable.

I've noticed that currently even the example specified in the wiki
doesn't work. Using a file filter such as:

exclude "doc"
include "doc/foo.txt"

will not include the foo.txt simply because an exclusion exists (if
not inc or exc).

I've modified the algorithm to honor the length of the inclusion or
exclusion string, so that a longer (more specific) directive takes
precedence.

I've also had to move the '.', name in rparse() to the end, otherwise
it wouldn't be possible to use filemaps such as

include "."
exclude "bin"
include "bin/something"

because the '.' would be matched first for bin/something/** (and end
up being too short to avoid exclusion against bin)

Regards,
Stefan

# HG changeset patch
# User Stefan Simek <simek at triaxis.sk>
# Date 1257854643 -3600
# Node ID 43625323c297dfcdb814208affb60e5cbae4923b
# Parent  a40ec11795c3fd9df7b8b22da797ba1974a46326
convert: changed the filemapper filtering algorithm to prefer more
specific include/exclude rules

diff --git a/hgext/convert/filemap.py b/hgext/convert/filemap.py
--- a/hgext/convert/filemap.py
+++ b/hgext/convert/filemap.py
@@ -10,11 +10,11 @@
 from common import SKIPREV, converter_source

 def rpairs(name):
-    yield '.', name
    e = len(name)
    while e != -1:
        yield name[:e], name[e+1:]
        e = name.rfind('/', 0, e)
+    yield '.', name

 class filemapper(object):
    '''Map and filter filenames when importing.
@@ -82,7 +82,7 @@
            exc = self.lookup(name, self.exclude)[0]
        else:
            exc = ''
-        if not inc or exc:
+        if (not self.include and exc) or (len(inc) <= len(exc)):
            return None
        newpre, pre, suf = self.lookup(name, self.rename)
        if newpre:


More information about the Mercurial-devel mailing list