diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2010-09-12 02:46:46 +0200 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2010-09-12 02:46:46 +0200 |
commit | a2b7d57515c835878004b26c76c523b2d6d21bb8 (patch) | |
tree | 7a7872885bd11272459d407f78d369e15486d942 | |
parent | f9ba58d75e62aceb87391e2ac1fca126d5ac9b34 (diff) | |
download | python-fastimport-a2b7d57515c835878004b26c76c523b2d6d21bb8.tar.gz |
remove dependency on bzrlib.
-rw-r--r-- | fastimport/helpers.py | 33 | ||||
-rw-r--r-- | fastimport/processors/filter_processor.py | 5 |
2 files changed, 33 insertions, 5 deletions
diff --git a/fastimport/helpers.py b/fastimport/helpers.py index 8e9a383..a80a1f4 100644 --- a/fastimport/helpers.py +++ b/fastimport/helpers.py @@ -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 diff --git a/fastimport/processors/filter_processor.py b/fastimport/processors/filter_processor.py index 3b35a0c..0228132 100644 --- a/fastimport/processors/filter_processor.py +++ b/fastimport/processors/filter_processor.py @@ -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): |