@@ -154,29 +154,31 @@ build_commit_trailer_regex() {
154154 # Read custom trailer keys from git config and add them either to specials or trailers.
155155 # This loop reads lines matching 'trailer.*.key'.
156156 while read -r _ key; do
157- # Skip if key already exists in trailers or specials.
157+ if [[ " $key " =~ -b y$ ]]; then
158+ trailers_by+=(" $key " )
159+ continue
160+ fi
161+
158162 for each in " ${trailers[@]} " " ${specials[@]} " ; do
159- if [ " $key " = " $each " ]; then
160- continue 2
161- fi
163+ [[ " $key " == " $each " ]] && continue 2
162164 done
163- # If key ends with a separator character, add to specials; otherwise, to trailers.
165+
164166 if [[ $key =~ [${separators} ]$ ]]; then
165167 specials+=(" $key " )
166168 else
167169 trailers+=(" $key " )
168170 fi
169171 done < <( git config --get-regexp ' trailer.*.key' )
170172
171- # Read custom trailer keys again into the 'keys' array (if needed).
172- while IFS=. read -r _ key _ ; do
173- for each in " ${keys[@]} " ; do
174- if [ " $key " = " $each " ] ; then
175- continue 2
176- fi
177- done
178- keys+=( " $key " )
179- done < <( git config --get-regexp ' trailer.*.key ' )
173+ # Possible trailers :
174+ # - Acked-by
175+ # - Co-authored-by
176+ # - Reported-by
177+ # - Reviewed-by
178+ # - Signed-off-by
179+ # - Suggested-by
180+ # - Tested-by
181+ TRAILERS_BY_REGEX= " ^( $( IFS= ' | ' ; echo " ${trailers_by[*]} " ) ): "
180182
181183 # Begin constructing the regex.
182184 TRAILER_REGEX=' ^('
@@ -209,16 +211,6 @@ build_commit_trailer_regex() {
209211 TRAILER_REGEX=" ${TRAILER_REGEX% |} )"
210212 fi
211213
212- # Append additional keys.
213- if (( ${# keys[@]} > 0 )) ; then
214- TRAILER_REGEX+=' |(('
215- for each in " ${keys[@]} " ; do
216- TRAILER_REGEX+=" $each |"
217- done
218- # Use the second character of separators (if available) as a separator for keys.
219- TRAILER_REGEX=" ${TRAILER_REGEX% |} )[${separators: 1: 1} [:blank:]])"
220- fi
221-
222214 # End the regex.
223215 TRAILER_REGEX+=" )"
224216}
@@ -618,7 +610,7 @@ add_change_id() {
618610 other_footer = ""
619611
620612 for (line = 1; line <= numlines; line++) {
621- if (match(tolower(footer[line]), /^(signed-off-by|acked-by|co-authored-by|reviewed-by|tested-by|suggested-by|reported-by):/ )) {
613+ if (match(tolower(footer[line]), TRAILERS_BY_REGEX )) {
622614 trailers = trailers footer[line] "\n"
623615 } else {
624616 other_footer = other_footer footer[line] "\n"
0 commit comments