Skip to content

Commit 4ad8e16

Browse files
Refactor commit trailer regex
Refactor commit trailer regex by renaming default_trailers_by to DEFAULT_TRAILERS_BY to follow the naming convention for global variables.Then refine build_commit_trailer_regex by reusing the array. Co-authored-by: EricccTaiwan <[email protected]> Change-Id: I7c7e9367f59a6da0ff84605904d08343ad558f42
1 parent 86e4254 commit 4ad8e16

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

scripts/commit-msg.hook

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ get_all_match_positions() {
130130
done <<< "$targets"
131131
}
132132

133+
DEFAULT_TRAILERS_BY=(
134+
'Signed-off-by'
135+
'Reviewed-by'
136+
'Co-authored-by'
137+
'Acked-by'
138+
'Suggested-by'
139+
'Tested-by'
140+
'Reported-by'
141+
)
142+
133143
# Build regex for detecting commit trailers.
134144
build_commit_trailer_regex() {
135145
local -a keys specials standalones trailers
@@ -145,21 +155,16 @@ build_commit_trailer_regex() {
145155
'Signed-off-by' 'Suggested-by' 'Tested-by'
146156
)
147157

158+
trailers_test=(
159+
'CC' 'Change-Id' 'Closes'
160+
"${DEFAULT_TRAILERS_BY[@]}"
161+
)
148162
# Standalone keys (those that do not require a value).
149163
standalones=(
150164
'(Doc|Upgrade|Security)Impact'
151165
"Git-Dch[$separators] (Ignore|Short|Full)"
152166
)
153167

154-
default_trailers_by=(
155-
'Signed-off-by'
156-
'Reviewed-by'
157-
'Co-authored-by'
158-
'Acked-by'
159-
'Suggested-by'
160-
'Tested-by'
161-
'Reported-by'
162-
)
163168

164169
# Read custom trailer keys from git config and add them either to specials or trailers.
165170
# This loop reads lines matching 'trailer.*.key'.
@@ -181,7 +186,7 @@ build_commit_trailer_regex() {
181186
done < <(git config --get-regexp 'trailer.*.key')
182187

183188
if [[ ${#trailers_by[@]} -eq 0 ]]; then
184-
trailers_by=("${default_trailers_by[@]}")
189+
trailers_by=("${DEFAULT_TRAILERS_BY[@]}")
185190
fi
186191

187192
# Possible trailers :

0 commit comments

Comments
 (0)