mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-14 18:25:22 +00:00
ci: pre-commit: Fix the gst-indent hook not implementing filtering criteria
There's a different way to list the files between the former pre-commit hook (which ran gst-indent directly on the output of git diff-index) and the former CI check job (which ran gst-indent-all wholesale). It can be easily addressed by detecting CI_PROJECT_NAME at listing time. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8409>
This commit is contained in:
parent
915b917ba6
commit
2b5ab13f29
2 changed files with 47 additions and 2 deletions
|
@ -16,8 +16,9 @@ repos:
|
||||||
- id: gst-indent
|
- id: gst-indent
|
||||||
name: gst-indent
|
name: gst-indent
|
||||||
language: python
|
language: python
|
||||||
entry: ./scripts/gst-indent.py
|
entry: ./scripts/gst-indent-all.py
|
||||||
types_or: ["c"]
|
pass_filenames: false
|
||||||
|
types_or: ["c", "c++"]
|
||||||
# The rust hook uses cargo fmt, which requires a Cargo.toml
|
# The rust hook uses cargo fmt, which requires a Cargo.toml
|
||||||
# We use a local hook to run rustfmt directly
|
# We use a local hook to run rustfmt directly
|
||||||
- id: rustfmt
|
- id: rustfmt
|
||||||
|
|
44
scripts/gst-indent-all.py
Executable file
44
scripts/gst-indent-all.py
Executable file
|
@ -0,0 +1,44 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from itertools import filterfalse
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
from gst_indent_common import indent
|
||||||
|
|
||||||
|
def readfile(f):
|
||||||
|
if os.path.exists(f):
|
||||||
|
expressions = open(f, 'r', encoding='utf-8').read().splitlines()
|
||||||
|
expressions = [re.compile(i) for i in expressions]
|
||||||
|
return lambda x: any(i.match(x) for i in expressions)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def listfiles(single_glob):
|
||||||
|
if os.environ.get("CI_PROJECT_NAME"):
|
||||||
|
return subprocess.check_output(['git', 'ls-files', single_glob],
|
||||||
|
universal_newlines=True).splitlines()
|
||||||
|
else:
|
||||||
|
return subprocess.check_output(['git', 'diff-index', '--cached', '--name-only', 'HEAD', '--diff-filter=ACMR', single_glob],
|
||||||
|
universal_newlines=True).splitlines()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
basedir = os.path.dirname(__file__)
|
||||||
|
|
||||||
|
filter_in_c = readfile('.indentignore')
|
||||||
|
listing = listfiles('*.c')
|
||||||
|
if filter_in_c:
|
||||||
|
listing = filterfalse(filter_in_c, listing)
|
||||||
|
|
||||||
|
for entry in listing:
|
||||||
|
indent(entry)
|
||||||
|
|
||||||
|
filter_in_cpp = readfile('.indent_cpp_list')
|
||||||
|
listing = listfiles('*.cpp')
|
||||||
|
if filter_in_cpp:
|
||||||
|
listing = filter(filter_in_cpp, listing)
|
||||||
|
|
||||||
|
for entry in listing:
|
||||||
|
indent(entry)
|
Loading…
Reference in a new issue