Skip to content

Commit 7e7630d

Browse files
committed
Remove support of Git 2.18 and earlier versions
We maintained non-obvious code to support versions of Git that did not have the `--only-matching` option, which appeared in Git 2.19. This version was released in September 2018, it's time to move on.
1 parent 500049f commit 7e7630d

File tree

4 files changed

+24
-76
lines changed

4 files changed

+24
-76
lines changed

CHANGES.rst

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
- Add support of Python 3.12.
55

6+
- |backward-incompatible| Remove support of Git 2.18 and earlier
7+
version. You must now have Git 2.19 (or a more recent version).
8+
69
- |backward-incompatible| Remove support of Python 3.7.
710

811
- |backward-incompatible| Remove ``--xunit-file`` argument from all

docs/installation.rst

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
Installation
22
============
33

4-
You must have Python 3.8 or later, and a relatively recent version of
5-
Git. Git 2.1.4 (shipped with Debian Jessie) is known to work. More
6-
recent versions should work and are supported.
4+
You must have Python 3.8 or later, and Git 2.19.0 or later.
75

86
Install with ``pip``, preferably in a `virtual environment`_:
97

src/check_oldies/annotations.py

+20-61
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
import dataclasses
33
import datetime
44
import re
5-
import subprocess
65
import typing
76

8-
import pkg_resources
9-
107
from . import commands
118
from . import output
129

@@ -230,66 +227,28 @@ def get_known_future_tags(directory, annotation_regex, future_tag_regex, whiteli
230227
return set(lines)
231228

232229

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-
243230
def get_all_futures(directory, future_tag_regex, whitelist):
244231
"""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+
)
293252

294253
occurrences = collections.defaultdict(list)
295254
for line in lines:

tests/test_annotations.py

-12
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,3 @@ def test_get_login_from_committer_email():
6767
assert login == "<@example.com>" # should not be the empty string
6868
login = annotations.get_login_from_committer_email("John Smith")
6969
assert login == "John Smith"
70-
71-
72-
def test_git_supports_only_matching():
73-
# We expect tests to run on a system that has a recent version of Git.
74-
assert annotations.git_supports_only_matching()
75-
76-
77-
@mock.patch("check_oldies.annotations.git_supports_only_matching", lambda: False)
78-
def test_old_git_without_only_matching():
79-
path = base.TEST_DIR_PATH / "data/project4"
80-
futures = annotations.get_all_futures(path, base.TESTING_FUTURE_TAG, whitelist=[])
81-
assert set(futures.keys()) == {"FEWTURE-BOOM", "FEWTURE-I-AM-AN-ORPHAN"}

0 commit comments

Comments
 (0)