]> git.proxmox.com Git - ceph.git/blob - ceph/src/dpdk/scripts/check-maintainers.sh
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / dpdk / scripts / check-maintainers.sh
1 #! /bin/sh
2
3 # BSD LICENSE
4 #
5 # Copyright 2015 6WIND S.A.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 #
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in
15 # the documentation and/or other materials provided with the
16 # distribution.
17 # * Neither the name of 6WIND S.A. nor the names of its
18 # contributors may be used to endorse or promote products derived
19 # from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 # Do some basic checks in MAINTAINERS file
34
35 cd $(dirname $0)/..
36
37 # Get files matching paths with wildcards and / meaning recursing
38 files () # <path> [<path> ...]
39 {
40 if [ -z "$1" ] ; then
41 return
42 fi
43 if [ -d .git ] ; then
44 git ls-files "$1"
45 else
46 find "$1" -type f |
47 sed 's,^\./,,'
48 fi |
49 # if not ended by /
50 if ! echo "$1" | grep -q '/[[:space:]]*$' ; then
51 # filter out deeper directories
52 sed "/\(\/[^/]*\)\{$(($(echo "$1" | grep -o / | wc -l) + 1))\}/d"
53 else
54 cat
55 fi
56 # next path
57 shift
58 files "$@"
59 }
60
61 # Get all files matching F: and X: fields
62 parse_fx () # <index file>
63 {
64 IFS='
65 '
66 # parse each line excepted underlining
67 for line in $( (sed '/^-\+$/d' $1 ; echo) | sed 's,^$,§,') ; do
68 if echo "$line" | grep -q '^§$' ; then
69 # empty line delimit end of section
70 whitelist=$(files $flines)
71 blacklist=$(files $xlines)
72 match=$(aminusb "$whitelist" "$blacklist")
73 if [ -n "$whitelist" ] ; then
74 printf "# $title "
75 maintainers=$(echo "$maintainers" | sed -r 's,.*<(.*)>.*,\1,')
76 maintainers=$(printf "$maintainers" | sed -e 's,^,<,' -e 's,$,>,')
77 echo $maintainers
78 fi
79 if [ -n "$match" ] ; then
80 echo "$match"
81 fi
82 # flush section
83 unset maintainers
84 unset flines
85 unset xlines
86 elif echo "$line" | grep -q '^[A-Z]: ' ; then
87 # maintainer
88 maintainers=$(add_line_to_if "$line" "$maintainers" 'M: ')
89 # file matching pattern
90 flines=$(add_line_to_if "$line" "$flines" 'F: ')
91 # file exclusion pattern
92 xlines=$(add_line_to_if "$line" "$xlines" 'X: ')
93 else # assume it is a title
94 title="$line"
95 fi
96 done
97 }
98
99 # Check patterns in F: and X:
100 check_fx () # <index file>
101 {
102 IFS='
103 '
104 for line in $(sed -n 's,^[FX]: ,,p' $1 | tr '*' '#') ; do
105 line=$(printf "$line" | tr '#' '*')
106 match=$(files "$line")
107 if [ -z "$match" ] ; then
108 echo "$line"
109 fi
110 done
111 }
112
113 # Add a line to a set of lines if it begins with right pattern
114 add_line_to_if () # <new line> <lines> <head pattern>
115 {
116 (
117 echo "$2"
118 echo "$1" | sed -rn "s,^$3(.*),\1,p"
119 ) |
120 sed '/^$/d'
121 }
122
123 # Subtract two sets of lines
124 aminusb () # <lines a> <lines b>
125 {
126 printf "$1\n$2\n$2" | sort | uniq -u | sed '/^$/d'
127 }
128
129 printf 'sections: '
130 parsed=$(parse_fx MAINTAINERS)
131 echo "$parsed" | grep -c '^#'
132 printf 'with maintainer: '
133 echo "$parsed" | grep -c '^#.*@'
134 printf 'maintainers: '
135 grep '^M:.*<' MAINTAINERS | sort -u | wc -l
136
137 echo
138 echo '##########'
139 echo '# orphan areas'
140 echo '##########'
141 echo "$parsed" | sed -rn 's,^#([^@]*)$,\1,p' | uniq
142
143 echo
144 echo '##########'
145 echo '# files not listed'
146 echo '##########'
147 all=$(files ./)
148 listed=$(echo "$parsed" | sed '/^#/d' | sort -u)
149 aminusb "$all" "$listed"
150
151 echo
152 echo '##########'
153 echo '# wrong patterns'
154 echo '##########'
155 check_fx MAINTAINERS
156
157 # TODO: check overlaps