Show More
@@ -1119,6 +1119,46 def sort(repo, subset, x): | |||
|
1119 | 1119 | l.sort() |
|
1120 | 1120 | return [e[-1] for e in l] |
|
1121 | 1121 | |
|
1122 | def _stringmatcher(pattern): | |
|
1123 | """ | |
|
1124 | accepts a string, possibly starting with 're:' or 'literal:' prefix. | |
|
1125 | returns the matcher name, pattern, and matcher function. | |
|
1126 | missing or unknown prefixes are treated as literal matches. | |
|
1127 | ||
|
1128 | helper for tests: | |
|
1129 | >>> def test(pattern, *tests): | |
|
1130 | ... kind, pattern, matcher = _stringmatcher(pattern) | |
|
1131 | ... return (kind, pattern, [bool(matcher(t)) for t in tests]) | |
|
1132 | ||
|
1133 | exact matching (no prefix): | |
|
1134 | >>> test('abcdefg', 'abc', 'def', 'abcdefg') | |
|
1135 | ('literal', 'abcdefg', [False, False, True]) | |
|
1136 | ||
|
1137 | regex matching ('re:' prefix) | |
|
1138 | >>> test('re:a.+b', 'nomatch', 'fooadef', 'fooadefbar') | |
|
1139 | ('re', 'a.+b', [False, False, True]) | |
|
1140 | ||
|
1141 | force exact matches ('literal:' prefix) | |
|
1142 | >>> test('literal:re:foobar', 'foobar', 're:foobar') | |
|
1143 | ('literal', 're:foobar', [False, True]) | |
|
1144 | ||
|
1145 | unknown prefixes are ignored and treated as literals | |
|
1146 | >>> test('foo:bar', 'foo', 'bar', 'foo:bar') | |
|
1147 | ('literal', 'foo:bar', [False, False, True]) | |
|
1148 | """ | |
|
1149 | if pattern.startswith('re:'): | |
|
1150 | pattern = pattern[3:] | |
|
1151 | try: | |
|
1152 | regex = re.compile(pattern) | |
|
1153 | except re.error, e: | |
|
1154 | raise error.ParseError(_('invalid regular expression: %s') | |
|
1155 | % e) | |
|
1156 | return 're', pattern, regex.search | |
|
1157 | elif pattern.startswith('literal:'): | |
|
1158 | pattern = pattern[8:] | |
|
1159 | return 'literal', pattern, pattern.__eq__ | |
|
1160 | ||
|
1161 | ||
|
1122 | 1162 | def tag(repo, subset, x): |
|
1123 | 1163 | """``tag([name])`` |
|
1124 | 1164 | The specified tag by name, or all tagged revisions if no name is given. |
General Comments 0
You need to be logged in to leave comments.
Login now