The + character is not part of the 'basic regular expressions' in BSD
grep. We now use -E to use extended (modern) regular expressions. Also
remove escaping. This makes the commit msg hook work on macOS 14.2.
Signed-off-by: Maarten Aertsen <maarten@nlnetlabs.nl>
---
contrib/commit-msg | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/contrib/commit-msg b/contrib/commit-msg
index add67177..503b5a11 100755
--- a/contrib/commit-msg+++ b/contrib/commit-msg
@@ -41,7 +41,7 @@ while read -r key value; do
key="$first_letter$other_letters"
# Find sort order of this key.
- order=$(echo "$trailer_order" | grep -Fxn "$key" | sed -n 's/^\([0-9]\+\):.*/\1/p')+ order=$(echo "$trailer_order" | grep -Fxn "$key" | sed -nE 's/^([0-9]+):.*/\1/p') if [ -z "$order" ]; then
echo "warning: unknown trailer '$key'" >&2
# Unknown trailers are always first.
@@ -51,7 +51,7 @@ while read -r key value; do
echo "$order $key $value"
done |
# Sort trailers according to their numeric order, trim the numeric order.
-LC_ALL=C sort -n | sed 's/^[0-9]\+ //' > "$tmp"+LC_ALL=C sort -n | sed -E 's/^[0-9]+ //' > "$tmp"debug echo ==== sanitized trailers ====
debug cat "$tmp"
--
2.39.3 (Apple Git-145)
Maarten Aertsen, Feb 26, 2024 at 21:58:
> The + character is not part of the 'basic regular expressions' in BSD> grep. We now use -E to use extended (modern) regular expressions. Also> remove escaping. This makes the commit msg hook work on macOS 14.2.>> Signed-off-by: Maarten Aertsen <maarten@nlnetlabs.nl>
Hi Maarten,
thanks and congrats on your first patch. To make the linter happy, can
you change the title of the commit to:
contrib: use sed -E for commit-msg hook
The patch itself is fine :)
Thanks!
On Mon Feb 26, 2024 at 9:56 PM CET, Maarten Aertsen wrote:
> # Find sort order of this key.> - order=$(echo "$trailer_order" | grep -Fxn "$key" | sed -n 's/^\([0-9]\+\):.*/\1/p')> + order=$(echo "$trailer_order" | grep -Fxn "$key" | sed -nE 's/^([0-9]+):.*/\1/p')
A nit … the change is in sed(1) not in grep(1). Also, whenever I
see a combination of grep and sed, my first question is “Wouldn’t
awk(1) work here better?”
Best,
Matěj
--
http://matej.ceplovi.cz/blog/, @mcepl@floss.social
GPG Finger: 3C76 A027 CA45 AD70 98B5 BC1D 7920 5802 880B C9D8
Afraid to die alone?
Become a bus driver.
-- alleged easter egg in notepad++