|
2 | 2 | import dataclasses
|
3 | 3 | import datetime
|
4 | 4 | import re
|
5 |
| -import subprocess |
6 | 5 | import typing
|
7 | 6 |
|
8 |
| -import pkg_resources |
9 |
| - |
10 | 7 | from . import commands
|
11 | 8 | from . import output
|
12 | 9 |
|
@@ -230,66 +227,28 @@ def get_known_future_tags(directory, annotation_regex, future_tag_regex, whiteli
|
230 | 227 | return set(lines)
|
231 | 228 |
|
232 | 229 |
|
233 |
| -def git_supports_only_matching(): |
234 |
| - out = subprocess.check_output(["git", "--version"]).decode("utf-8") |
235 |
| - # output looks like "git version 2.26.0" |
236 |
| - git_version = pkg_resources.parse_version(out.split()[2]) |
237 |
| - # `git grep --only-matching` appeared in Git 2.19.0 |
238 |
| - # https://github.com/git/git/blob/v2.19.0/Documentation/RelNotes/2.19.0.txt#L41 |
239 |
| - minimal_version = pkg_resources.parse_version("2.19.0") |
240 |
| - return git_version >= minimal_version |
241 |
| - |
242 |
| - |
243 | 230 | def get_all_futures(directory, future_tag_regex, whitelist):
|
244 | 231 | """Get all occurrences of FUTURE tags."""
|
245 |
| - # Old versions of Git (such as Git 2.1.4 that is shipped by Debian |
246 |
| - # Jessie) do not support the `--only-matching` option. Pipe to |
247 |
| - # `sed` instead. |
248 |
| - if git_supports_only_matching(): |
249 |
| - grep = [ |
250 |
| - "git", |
251 |
| - "grep", |
252 |
| - "-I", # ignore binary files |
253 |
| - "--line-number", |
254 |
| - "--extended-regexp", |
255 |
| - "--only-matching", |
256 |
| - "-e", |
257 |
| - future_tag_regex, |
258 |
| - "--and", |
259 |
| - "--not", |
260 |
| - "-e", |
261 |
| - IGNORE_PRAGMA, |
262 |
| - ] |
263 |
| - grep.extend([f":(exclude){glob}" for glob in whitelist]) |
264 |
| - lines = commands.get_output( |
265 |
| - grep, |
266 |
| - cwd=directory, |
267 |
| - valid_return_codes=(0, 1), # 0 if there are matches, 1 otherwise |
268 |
| - ) |
269 |
| - else: |
270 |
| - grep = [ |
271 |
| - "git", |
272 |
| - "grep", |
273 |
| - "-I", # ignore binary files |
274 |
| - "--line-number", |
275 |
| - "--extended-regexp", |
276 |
| - "-e", |
277 |
| - future_tag_regex, |
278 |
| - "--and", |
279 |
| - "--not", |
280 |
| - "-e", |
281 |
| - IGNORE_PRAGMA, |
282 |
| - "--", # needed on old versions... |
283 |
| - ".", # ... of git |
284 |
| - ] |
285 |
| - grep.extend([f":(exclude){glob}" for glob in whitelist]) |
286 |
| - sed = f'sed --regexp-extended "s/(.*?):.*?({future_tag_regex}).*?/\\1:\\2/g"' |
287 |
| - lines = commands.get_pipe_command_output( |
288 |
| - grep, |
289 |
| - piped_to=sed, |
290 |
| - cwd=directory, |
291 |
| - valid_return_codes=(0, 1), # 0 if there are matches, 1 otherwise |
292 |
| - ) |
| 232 | + grep = [ |
| 233 | + "git", |
| 234 | + "grep", |
| 235 | + "-I", # ignore binary files |
| 236 | + "--line-number", |
| 237 | + "--extended-regexp", |
| 238 | + "--only-matching", |
| 239 | + "-e", |
| 240 | + future_tag_regex, |
| 241 | + "--and", |
| 242 | + "--not", |
| 243 | + "-e", |
| 244 | + IGNORE_PRAGMA, |
| 245 | + ] |
| 246 | + grep.extend([f":(exclude){glob}" for glob in whitelist]) |
| 247 | + lines = commands.get_output( |
| 248 | + grep, |
| 249 | + cwd=directory, |
| 250 | + valid_return_codes=(0, 1), # 0 if there are matches, 1 otherwise |
| 251 | + ) |
293 | 252 |
|
294 | 253 | occurrences = collections.defaultdict(list)
|
295 | 254 | for line in lines:
|
|
0 commit comments