##// END OF EJS Templates
revset: add expectsize to check the size of a set...
Navaneeth Suresh -
r41829:8185c8ab default
parent child Browse files
Show More
@@ -861,6 +861,37 b' def contentdivergent(repo, subset, x):'
861 contentdivergent = obsmod.getrevs(repo, 'contentdivergent')
861 contentdivergent = obsmod.getrevs(repo, 'contentdivergent')
862 return subset & contentdivergent
862 return subset & contentdivergent
863
863
864 @predicate('expectsize(set[, size])', safe=True, takeorder=True)
865 def expectsize(repo, subset, x, order):
866 """Abort if the revset doesn't expect given size"""
867 args = getargsdict(x, 'expectsize', 'set size')
868 minsize = 0
869 maxsize = len(repo) + 1
870 err = ''
871 if 'size' not in args or 'set' not in args:
872 raise error.ParseError(_('invalid set of arguments'))
873 minsize, maxsize = getintrange(args['size'],
874 _('expectsize requires a size range'
875 ' or a positive integer'),
876 _('size range bounds must be integers'),
877 minsize, maxsize)
878 if minsize < 0 or maxsize < 0:
879 raise error.ParseError(_('negative size'))
880 rev = getset(repo, fullreposet(repo), args['set'], order=order)
881 if minsize != maxsize and (len(rev) < minsize or len(rev) > maxsize):
882 err = _('revset size mismatch.'
883 ' expected between %d and %d, got %d') % (minsize, maxsize,
884 len(rev))
885 elif minsize == maxsize and len(rev) != minsize:
886 err = _('revset size mismatch.'
887 ' expected %d, got %d') % (minsize, len(rev))
888 if err:
889 raise error.RepoLookupError(err)
890 if order == followorder:
891 return subset & rev
892 else:
893 return rev & subset
894
864 @predicate('extdata(source)', safe=False, weight=100)
895 @predicate('extdata(source)', safe=False, weight=100)
865 def extdata(repo, subset, x):
896 def extdata(repo, subset, x):
866 """Changesets in the specified extdata source. (EXPERIMENTAL)"""
897 """Changesets in the specified extdata source. (EXPERIMENTAL)"""
@@ -2978,3 +2978,63 b' test multiline revset with errors'
2978 * set:
2978 * set:
2979 <baseset+ [0]>
2979 <baseset+ [0]>
2980 0
2980 0
2981
2982 abort if the revset doesn't expect given size
2983 $ log 'expectsize()'
2984 hg: parse error: invalid set of arguments
2985 [255]
2986 $ log 'expectsize(0:2, a)'
2987 hg: parse error: expectsize requires a size range or a positive integer
2988 [255]
2989 $ log 'expectsize(0:2, 3)'
2990 0
2991 1
2992 2
2993
2994 $ log 'expectsize(2:0, 3)'
2995 2
2996 1
2997 0
2998 $ log 'expectsize(0:1, 1)'
2999 abort: revset size mismatch. expected 1, got 2!
3000 [255]
3001 $ log 'expectsize(0:4, -1)'
3002 hg: parse error: negative size
3003 [255]
3004 $ log 'expectsize(0:2, 2:4)'
3005 0
3006 1
3007 2
3008 $ log 'expectsize(0:1, 3:5)'
3009 abort: revset size mismatch. expected between 3 and 5, got 2!
3010 [255]
3011 $ log 'expectsize(0:1, -1:2)'
3012 hg: parse error: negative size
3013 [255]
3014 $ log 'expectsize(0:1, 1:-2)'
3015 hg: parse error: negative size
3016 [255]
3017 $ log 'expectsize(0:2, a:4)'
3018 hg: parse error: size range bounds must be integers
3019 [255]
3020 $ log 'expectsize(0:2, 2:b)'
3021 hg: parse error: size range bounds must be integers
3022 [255]
3023 $ log 'expectsize(0:2, 2:)'
3024 0
3025 1
3026 2
3027 $ log 'expectsize(0:2, :5)'
3028 0
3029 1
3030 2
3031 $ log 'expectsize(0:2, :)'
3032 0
3033 1
3034 2
3035 $ log 'expectsize(0:2, 4:)'
3036 abort: revset size mismatch. expected between 4 and 11, got 3!
3037 [255]
3038 $ log 'expectsize(0:2, :2)'
3039 abort: revset size mismatch. expected between 0 and 2, got 3!
3040 [255]
General Comments 0
You need to be logged in to leave comments. Login now