Commits

vitalif  committed 0de18c5

Respect filemap rule order (rules that come first are overridden by rules that come later)

  • Participants
  • Parent commits 7ca3d1b

Comments (0)

Files changed (2)

File hgsubversion/maps.py

             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):
             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')

File tests/test_fetch_mappings.py

         # 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')