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:
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
"""Import processor that filters the input (and doesn't import)."""
-from bzrlib import osutils
from fastimport import (
commands,
helpers,
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):