Show More
@@ -2730,6 +2730,29 b' def funcsused(tree):' | |||
|
2730 | 2730 | funcs.add(tree[1][1]) |
|
2731 | 2731 | return funcs |
|
2732 | 2732 | |
|
2733 | def _formatsetrepr(r): | |
|
2734 | """Format an optional printable representation of a set | |
|
2735 | ||
|
2736 | ======== ================================= | |
|
2737 | type(r) example | |
|
2738 | ======== ================================= | |
|
2739 | tuple ('<not %r>', other) | |
|
2740 | str '<branch closed>' | |
|
2741 | callable lambda: '<branch %r>' % sorted(b) | |
|
2742 | object other | |
|
2743 | ======== ================================= | |
|
2744 | """ | |
|
2745 | if r is None: | |
|
2746 | return '' | |
|
2747 | elif isinstance(r, tuple): | |
|
2748 | return r[0] % r[1:] | |
|
2749 | elif isinstance(r, str): | |
|
2750 | return r | |
|
2751 | elif callable(r): | |
|
2752 | return r() | |
|
2753 | else: | |
|
2754 | return repr(r) | |
|
2755 | ||
|
2733 | 2756 | class abstractsmartset(object): |
|
2734 | 2757 | |
|
2735 | 2758 | def __nonzero__(self): |
@@ -2810,7 +2833,7 b' class abstractsmartset(object):' | |||
|
2810 | 2833 | This is part of the mandatory API for smartset.""" |
|
2811 | 2834 | if isinstance(other, fullreposet): |
|
2812 | 2835 | return self |
|
2813 | return self.filter(other.__contains__, cache=False) | |
|
2836 | return self.filter(other.__contains__, condrepr=other, cache=False) | |
|
2814 | 2837 | |
|
2815 | 2838 | def __add__(self, other): |
|
2816 | 2839 | """Returns a new object with the union of the two collections. |
@@ -2823,19 +2846,21 b' class abstractsmartset(object):' | |||
|
2823 | 2846 | |
|
2824 | 2847 | This is part of the mandatory API for smartset.""" |
|
2825 | 2848 | c = other.__contains__ |
|
2826 |
return self.filter(lambda r: not c(r), c |
|
|
2827 | ||
|
2828 | def filter(self, condition, cache=True): | |
|
2849 | return self.filter(lambda r: not c(r), condrepr=('<not %r>', other), | |
|
2850 | cache=False) | |
|
2851 | ||
|
2852 | def filter(self, condition, condrepr=None, cache=True): | |
|
2829 | 2853 | """Returns this smartset filtered by condition as a new smartset. |
|
2830 | 2854 | |
|
2831 | 2855 | `condition` is a callable which takes a revision number and returns a |
|
2832 | boolean. | |
|
2856 | boolean. Optional `condrepr` provides a printable representation of | |
|
2857 | the given `condition`. | |
|
2833 | 2858 | |
|
2834 | 2859 | This is part of the mandatory API for smartset.""" |
|
2835 | 2860 | # builtin cannot be cached. but do not needs to |
|
2836 | 2861 | if cache and util.safehasattr(condition, 'func_code'): |
|
2837 | 2862 | condition = util.cachefunc(condition) |
|
2838 | return filteredset(self, condition) | |
|
2863 | return filteredset(self, condition, condrepr) | |
|
2839 | 2864 | |
|
2840 | 2865 | class baseset(abstractsmartset): |
|
2841 | 2866 | """Basic data structure that represents a revset and contains the basic |
@@ -2939,13 +2964,16 b' class filteredset(abstractsmartset):' | |||
|
2939 | 2964 | the subset and contains a function which tests for membership in the |
|
2940 | 2965 | revset |
|
2941 | 2966 | """ |
|
2942 | def __init__(self, subset, condition=lambda x: True): | |
|
2967 | def __init__(self, subset, condition=lambda x: True, condrepr=None): | |
|
2943 | 2968 | """ |
|
2944 | 2969 | condition: a function that decide whether a revision in the subset |
|
2945 | 2970 | belongs to the revset or not. |
|
2971 | condrepr: a tuple of (format, obj, ...), a function or an object that | |
|
2972 | provides a printable representation of the given condition. | |
|
2946 | 2973 | """ |
|
2947 | 2974 | self._subset = subset |
|
2948 | 2975 | self._condition = condition |
|
2976 | self._condrepr = condrepr | |
|
2949 | 2977 | |
|
2950 | 2978 | def __contains__(self, x): |
|
2951 | 2979 | return x in self._subset and self._condition(x) |
@@ -3025,7 +3053,11 b' class filteredset(abstractsmartset):' | |||
|
3025 | 3053 | return x |
|
3026 | 3054 | |
|
3027 | 3055 | def __repr__(self): |
|
3028 | return '<%s %r>' % (type(self).__name__, self._subset) | |
|
3056 | xs = [repr(self._subset)] | |
|
3057 | s = _formatsetrepr(self._condrepr) | |
|
3058 | if s: | |
|
3059 | xs.append(s) | |
|
3060 | return '<%s %s>' % (type(self).__name__, ', '.join(xs)) | |
|
3029 | 3061 | |
|
3030 | 3062 | def _iterordered(ascending, iter1, iter2): |
|
3031 | 3063 | """produce an ordered iteration from two iterators with the same order |
@@ -169,7 +169,9 b' names that should work without quoting' | |||
|
169 | 169 | ('symbol', 'a')) |
|
170 | 170 | * set: |
|
171 | 171 | <filteredset |
|
172 |
<baseset [1]> |
|
|
172 | <baseset [1]>, | |
|
173 | <not | |
|
174 | <baseset [0]>>> | |
|
173 | 175 | 1 |
|
174 | 176 | $ try _a_b_c_ |
|
175 | 177 | ('symbol', '_a_b_c_') |
@@ -182,7 +184,9 b' names that should work without quoting' | |||
|
182 | 184 | ('symbol', 'a')) |
|
183 | 185 | * set: |
|
184 | 186 | <filteredset |
|
185 |
<baseset [6]> |
|
|
187 | <baseset [6]>, | |
|
188 | <not | |
|
189 | <baseset [0]>>> | |
|
186 | 190 | 6 |
|
187 | 191 | $ try .a.b.c. |
|
188 | 192 | ('symbol', '.a.b.c.') |
@@ -195,7 +199,9 b' names that should work without quoting' | |||
|
195 | 199 | ('symbol', 'a')) |
|
196 | 200 | * set: |
|
197 | 201 | <filteredset |
|
198 |
<baseset [7]> |
|
|
202 | <baseset [7]>, | |
|
203 | <not | |
|
204 | <baseset [0]>>> | |
|
199 | 205 | 7 |
|
200 | 206 | |
|
201 | 207 | names that should be caught by fallback mechanism |
@@ -278,7 +284,9 b' quoting needed' | |||
|
278 | 284 | ('symbol', 'a')) |
|
279 | 285 | * set: |
|
280 | 286 | <filteredset |
|
281 |
<baseset [4]> |
|
|
287 | <baseset [4]>, | |
|
288 | <not | |
|
289 | <baseset [0]>>> | |
|
282 | 290 | 4 |
|
283 | 291 | |
|
284 | 292 | $ log '1 or 2' |
General Comments 0
You need to be logged in to leave comments.
Login now