changeset 847:0de18c5c2e35

Respect filemap rule order (rules that come first are overridden by rules that come later)
author Vitaliy Filippov <vitalif@yourcmc.ru>
date Sat, 28 Jan 2012 02:18:25 +0400
parents 7ca3d1b08d67
children 4e203a47102a
files hgsubversion/maps.py tests/test_fetch_mappings.py
diffstat 2 files changed, 29 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/maps.py
+++ b/hgsubversion/maps.py
@@ -272,32 +272,34 @@ class FileMap(object):
             self._write()
 
     def _rpairs(self, name):
-        yield '.', name
         e = len(name)
         while e != -1:
             yield name[:e], name[e+1:]
             e = name.rfind('/', 0, e)
+        yield '.', name
 
     def check(self, m, path):
         m = getattr(self, m)
         for pre, _suf in self._rpairs(path):
-            if pre not in m:
-                continue
-            return m[pre]
-        return None
+            if pre in m:
+                return m[pre]
+        return -1
 
     def __contains__(self, path):
-        if len(self.include) and len(path):
+        if not len(path):
+            return True
+        if len(self.include):
             inc = self.check('include', path)
+        elif not len(self.exclude):
+            return True
         else:
-            inc = path
-        if len(self.exclude) and len(path):
+            inc = 0
+        if len(self.exclude):
             exc = self.check('exclude', path)
         else:
-            exc = None
-        if inc is None or exc is not None:
-            return False
-        return True
+            exc = -1
+        # respect rule order: newer rules override older
+        return inc > exc
 
     # Needed so empty filemaps are false
     def __len__(self):
@@ -311,7 +313,8 @@ class FileMap(object):
             return
         bits = m.strip('e'), path
         self.ui.debug('%sing %s\n' % bits)
-        mapping[path] = path
+        # respect rule order
+        mapping[path] = len(self)
         if fn != self.path:
             f = open(self.path, 'a')
             f.write(m + ' ' + path + '\n')
--- a/tests/test_fetch_mappings.py
+++ b/tests/test_fetch_mappings.py
@@ -131,6 +131,19 @@ class MapTests(test_util.TestBase):
         # TODO: re-enable test if we ever reinstate this feature
         self.assertRaises(hgutil.Abort, self.test_file_map_exclude, True)
 
+    def test_file_map_rule_order(self):
+        test_util.load_svndump_fixture(self.repo_path, 'replace_trunk_with_branch.svndump')
+        filemap = open(self.filemap, 'w')
+        filemap.write("exclude alpha\n")
+        filemap.write("include .\n")
+        filemap.close()
+        ui = self.ui(False)
+        ui.setconfig('hgsubversion', 'filemap', self.filemap)
+        commands.clone(ui, test_util.fileurl(self.repo_path),
+                       self.wc_path, filemap=self.filemap)
+        self.assertEqual(node.hex(self.repo[0].node()), '2cd09772e0f6ddf2d13c60ef3c1be11ad5a7dfae')
+        self.assertEqual(node.hex(self.repo['default'].node()), '8a525ca0671f456e6b1417187bf86c6115d2cb78')
+
     def test_branchmap(self, stupid=False):
         test_util.load_svndump_fixture(self.repo_path, 'branchmap.svndump')
         branchmap = open(self.branchmap, 'w')