def test_one_path(self): c = helpers.common_directory([b'foo']) self.assertEqual(c, b'') c = helpers.common_directory([b'foo/']) self.assertEqual(c, b'foo/') c = helpers.common_directory([b'foo/bar']) self.assertEqual(c, b'foo/')
def test_two_paths(self): c = helpers.common_directory([b'foo', b'bar']) self.assertEqual(c, b'') c = helpers.common_directory([b'foo/', b'bar']) self.assertEqual(c, b'') c = helpers.common_directory([b'foo/', b'foo/bar']) self.assertEqual(c, b'foo/') c = helpers.common_directory([b'foo/bar/x', b'foo/bar/y']) self.assertEqual(c, b'foo/bar/') c = helpers.common_directory([b'foo/bar/aa_x', b'foo/bar/aa_y']) self.assertEqual(c, b'foo/bar/')
def pre_process(self): self.includes = self.params.get(b'include_paths') self.excludes = self.params.get(b'exclude_paths') self.squash_empty_commits = bool( self.params.get(b'squash_empty_commits', True)) # What's the new root, if any self.new_root = helpers.common_directory(self.includes) # Buffer of blobs until we know we need them: mark -> cmd self.blobs = {} # These are the commits we've squashed so far self.squashed_commits = set() # Map of commit-id to list of parents self.parents = {}
def pre_process(self): # compile regex for every pattern or use the regex object directly if isinstance(self.params.get('include_patterns'), basestring): include_patterns = self.params['include_patterns'].split(",") self.includes = re.compile( self._paths_to_regex(include_patterns)) # truncate the includes until the '*' and find the common directory self.new_root = helpers.common_directory( [(x[:i] if i > -1 else x) for i, x in ((x.find('*'), x) for x in include_patterns)]) print 'M ', self.new_root else: self.includes = self.params.get('include_patterns') # compile exclude patterns if isinstance(self.params.get('exclude_patterns'), basestring): self.excludes = re.compile( self._paths_to_regex( self.params['exclude_patterns'].split(","))) else: self.excludes = self.params.get('exclude_patterns') super(FilterProcessor, self).pre_process()
def test_lots_of_paths(self): c = helpers.common_directory([b'foo/bar/x', b'foo/bar/y', b'foo/bar/z']) self.assertEqual(c, b'foo/bar/')
def test_no_paths(self): c = helpers.common_directory(None) self.assertEqual(c, None) c = helpers.common_directory([]) self.assertEqual(c, None)
def test_lots_of_paths(self): c = helpers.common_directory( [b'foo/bar/x', b'foo/bar/y', b'foo/bar/z']) self.assertEqual(c, b'foo/bar/')