2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright 2015 6WIND S.A.
5 # Do some basic checks in MAINTAINERS file
9 # speed up by ignoring Unicode details
12 # Get files matching paths with wildcards and / meaning recursing
13 files () # <path> [<path> ...]
25 if ! echo "$1" | grep -q '/[[:space:]]*$' ; then
26 # filter out deeper directories
27 sed "/\(\/[^/]*\)\{$(($(echo "$1" | grep -o / | wc -l) + 1))\}/d"
36 # Get all files matching F: and X: fields
37 parse_fx () # <index file>
41 # parse each line excepted underlining
42 for line in $( (sed '/^-\+$/d' $1 ; echo) | sed 's,^$,§,') ; do
43 if echo "$line" | grep -q '^§$' ; then
44 # empty line delimit end of section
45 include_files=$(files $flines)
46 exclude_files=$(files $xlines)
47 match=$(aminusb "$include_files" "$exclude_files")
48 if [ -n "$include_files" ] ; then
50 maintainers=$(echo "$maintainers" | sed -r 's,.*<(.*)>.*,\1,')
51 maintainers=$(printf "$maintainers" | sed -e 's,^,<,' -e 's,$,>,')
54 if [ -n "$match" ] ; then
61 elif echo "$line" | grep -q '^[A-Z]: ' ; then
63 maintainers=$(add_line_to_if "$line" "$maintainers" 'M: ')
64 # file matching pattern
65 flines=$(add_line_to_if "$line" "$flines" 'F: ')
66 # file exclusion pattern
67 xlines=$(add_line_to_if "$line" "$xlines" 'X: ')
68 else # assume it is a title
74 # Check patterns in F: and X:
75 check_fx () # <index file>
79 for line in $(sed -n 's,^[FX]: ,,p' $1 | tr '*' '#') ; do
80 line=$(printf "$line" | tr '#' '*')
81 match=$(files "$line")
82 if [ -z "$match" ] ; then
88 # Add a line to a set of lines if it begins with right pattern
89 add_line_to_if () # <new line> <lines> <head pattern>
93 echo "$1" | sed -rn "s,^$3(.*),\1,p"
98 # Subtract two sets of lines
99 aminusb () # <lines a> <lines b>
101 printf "$1\n$2\n$2" | sort | uniq -u | sed '/^$/d'
105 parsed=$(parse_fx MAINTAINERS)
106 echo "$parsed" | grep -c '^#'
107 printf 'with maintainer: '
108 echo "$parsed" | grep -c '^#.*@'
109 printf 'maintainers: '
110 grep '^M:.*<' MAINTAINERS | sort -u | wc -l
114 echo '# orphan areas'
116 echo "$parsed" | sed -rn 's,^#([^@]*)$,\1,p' | uniq
120 echo '# files not listed'
123 listed=$(echo "$parsed" | sed '/^#/d' | sort -u)
124 aminusb "$all" "$listed"
128 echo '# wrong patterns'
132 # TODO: check overlaps