@@ -154,29 +154,31 @@ build_commit_trailer_regex() {
154
154
# Read custom trailer keys from git config and add them either to specials or trailers.
155
155
# This loop reads lines matching 'trailer.*.key'.
156
156
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
+
158
162
for each in " ${trailers[@]} " " ${specials[@]} " ; do
159
- if [ " $key " = " $each " ]; then
160
- continue 2
161
- fi
163
+ [[ " $key " == " $each " ]] && continue 2
162
164
done
163
- # If key ends with a separator character, add to specials; otherwise, to trailers.
165
+
164
166
if [[ $key =~ [${separators} ]$ ]]; then
165
167
specials+=(" $key " )
166
168
else
167
169
trailers+=(" $key " )
168
170
fi
169
171
done < <( git config --get-regexp ' trailer.*.key' )
170
172
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[*]} " ) ): "
180
182
181
183
# Begin constructing the regex.
182
184
TRAILER_REGEX=' ^('
@@ -209,16 +211,6 @@ build_commit_trailer_regex() {
209
211
TRAILER_REGEX=" ${TRAILER_REGEX% |} )"
210
212
fi
211
213
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
-
222
214
# End the regex.
223
215
TRAILER_REGEX+=" )"
224
216
}
@@ -611,35 +603,30 @@ add_change_id() {
611
603
print lines "\n"
612
604
lines = ""
613
605
}
614
- changeIdAfter = "^(" tolower(" ' " $CHANGE_ID_AFTER " ' ") "):"
606
+
615
607
numlines = split(lines, footer, "\n")
616
608
617
- # Find the last line that starts with a comment character.
618
- coauthorIndex = 0
619
- for (line = 1; line <= numlines; line++) {
620
- if (match(tolower(footer[line]), /^co-authored-by:/)) {
621
- coauthorIndex = line
622
- }
623
- }
609
+ trailers = ""
610
+ other_footer = ""
624
611
625
612
for (line = 1; line <= numlines; line++) {
626
- if (unprinted && match(tolower(footer[line]), changeIdAfter) != 1) {
627
- # If the Change-Id is the first line in the footer, print it first.
628
- if (coauthorIndex == 0 || line > coauthorIndex) {
629
- print "Change-Id: I' " $id " ' "
630
- unprinted = 0
631
- }
613
+ if (match(tolower(footer[line]), TRAILERS_BY_REGEX)) {
614
+ trailers = trailers footer[line] "\n"
615
+ } else {
616
+ other_footer = other_footer footer[line] "\n"
632
617
}
633
- print footer[line]
618
+ }
634
619
635
- if(line == coauthorIndex && unprinted) {
636
- print "Change-Id: I' " $id " ' "
637
- unprinted = 0
638
- }
620
+ if (other_footer != "") {
621
+ printf "%s", other_footer
639
622
}
640
- if (unprinted) {
641
- print "Change-Id: I' " $id " ' "
623
+
624
+ if (trailers != "") {
625
+ printf "%s", trailers
642
626
}
627
+
628
+ printf "Change-Id: I' " $id " ' \n"
629
+
643
630
}' " $MSG " > " $T " && mv " $T " " $MSG " || rm -f " $T "
644
631
}
645
632
0 commit comments