- $_ = join("\n", @message, @footer);
- open(O, ">$MSG"); print O; close O;
- ' "$MSG" "$id" "$CHANGE_ID_AFTER"
+ # Tag handling:
+ # If last line before tags was not blank, there were no tags.
+ # In that case, print everything, plus a blank line, followed by Change-Id.
+ # Otherwise there were tags. Look for the right place to inject Change-Id,
+ # by considering CHANGE_ID_AFTER. Tags listed in it (case insensitive) come first,
+ # then Change-Id, then everything else (eg. Signed-off-by:).
+ END {
+ unprinted = 1
+ if (blankLines == 0) {
+ if (lines == "") {
+ print ""
+ } else {
+ print lines "\n"
+ }
+ } else {
+ for (i = 0; i < blankLines; i++) {
+ print ""
+ }
+ changeIdAfter = "^(" tolower("'"$CHANGE_ID_AFTER"'") "):"
+ numlines = split(lines, footer, "\n")
+ for (line = 1; line <= numlines; line++) {
+ if (unprinted && match(tolower(footer[line]), changeIdAfter) != 1) {
+ unprinted = 0
+ print "Change-Id: I'"$id"'"
+ }
+ print footer[line]
+ }
+ }
+ if (unprinted) {
+ print "Change-Id: I'"$id"'"
+ }
+ }' "$MSG" > $T && mv $T "$MSG" || rm -f $T