@@ -62,10 +62,34 @@ def __del__(self):
62
62
os .rename (self .tmp_file_path , self .file_path )
63
63
# END temp file exists
64
64
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
+
65
90
66
91
class BaseIndexEntry (tuple ):
67
92
"""
68
-
69
93
Small Brother of an index entry which can be created to describe changes
70
94
done to the index in which case plenty of additional information is not requried.
71
95
@@ -621,7 +645,8 @@ def iter_blobs(self, predicate = lambda t: True):
621
645
622
646
``predicate``
623
647
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.
625
650
"""
626
651
for entry in self .entries .itervalues ():
627
652
mode = self ._index_mode_to_tree_index_mode (entry .mode )
0 commit comments