remove dependency on bzrlib.
authorJelmer Vernooij <jelmer@samba.org>
Sun, 12 Sep 2010 00:46:46 +0000 (02:46 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Sun, 12 Sep 2010 00:46:46 +0000 (02:46 +0200)
fastimport/helpers.py
fastimport/processors/filter_processor.py

index 8e9a38395bfa7665f804ed36b197adcc55cfd3af..a80a1f45ebc7c18b7d1054964b1e70534835814d 100644 (file)
@@ -99,12 +99,12 @@ def common_directory(paths):
       if there is no common directory, '' is returned;
       otherwise the common directory with a trailing / is returned.
     """
-    from bzrlib import osutils
+    import posixpath
     def get_dir_with_slash(path):
         if path == '' or path.endswith('/'):
             return path
         else:
-            dirname, basename = osutils.split(path)
+            dirname, basename = posixpath.split(path)
             if dirname == '':
                 return dirname
             else:
@@ -121,4 +121,33 @@ def common_directory(paths):
         return get_dir_with_slash(common)
 
 
+def is_inside(dir, fname):
+    """True if fname is inside dir.
 
+    The parameters should typically be passed to osutils.normpath first, so
+    that . and .. and repeated slashes are eliminated, and the separators
+    are canonical for the platform.
+
+    The empty string as a dir name is taken as top-of-tree and matches
+    everything.
+    """
+    # XXX: Most callers of this can actually do something smarter by
+    # looking at the inventory
+    if dir == fname:
+        return True
+
+    if dir == '':
+        return True
+
+    if dir[-1] != '/':
+        dir += '/'
+
+    return fname.startswith(dir)
+
+
+def is_inside_any(dir_list, fname):
+    """True if fname is inside any of given dirs."""
+    for dirname in dir_list:
+        if is_inside(dirname, fname):
+            return True
+    return False
index 3b35a0cffe81f1ba5a81758c194ba41d98aacf8a..0228132a2bf0a564a805db6266dc267073465a59 100644 (file)
@@ -17,7 +17,6 @@
 """Import processor that filters the input (and doesn't import)."""
 
 
-from bzrlib import osutils
 from fastimport import (
     commands,
     helpers,
@@ -191,11 +190,11 @@ class FilterProcessor(processor.ImportProcessor):
     def _path_to_be_kept(self, path):
         """Does the given path pass the filtering criteria?"""
         if self.excludes and (path in self.excludes
-                or osutils.is_inside_any(self.excludes, path)):
+                or helpers.is_inside_any(self.excludes, path)):
             return False
         if self.includes:
             return (path in self.includes
-                or osutils.is_inside_any(self.includes, path))
+                or helpers.is_inside_any(self.includes, path))
         return True
 
     def _adjust_for_new_root(self, path):