@@ -62,10 +62,34 @@ def __del__(self):
6262 os .rename (self .tmp_file_path , self .file_path )
6363 # END temp file exists
6464
65+ class BlobFilter (object ):
66+ """
67+ Predicate to be used by iter_blobs allowing to filter only return blobs which
68+ match the given list of directories or files.
69+
70+ The given paths are given relative to the repository.
71+ """
72+ __slots__ = 'paths'
73+
74+ def __init__ (self , paths ):
75+ """
76+ ``paths``
77+ tuple or list of paths which are either pointing to directories or
78+ to files relative to the current repository
79+ """
80+ self .paths = paths
81+
82+ def __call__ (self , stage_blob ):
83+ path = stage_blob [1 ].path
84+ for p in self .paths :
85+ if path .startswith (p ):
86+ return True
87+ # END for each path in filter paths
88+ return False
89+
6590
6691class BaseIndexEntry (tuple ):
6792 """
68-
6993 Small Brother of an index entry which can be created to describe changes
7094 done to the index in which case plenty of additional information is not requried.
7195
@@ -621,7 +645,8 @@ def iter_blobs(self, predicate = lambda t: True):
621645
622646 ``predicate``
623647 Function(t) returning True if tuple(stage, Blob) should be yielded by the
624- iterator
648+ iterator. A default filter, the BlobFilter, allows you to yield blobs
649+ only if they match a given list of paths.
625650 """
626651 for entry in self .entries .itervalues ():
627652 mode = self ._index_mode_to_tree_index_mode (entry .mode )
0 commit comments