From 5deea8c9f40f348eebd250a6fb96fcef3426b671 Mon Sep 17 00:00:00 2001 From: "George L. Yermulnik" Date: Mon, 19 Feb 2024 14:46:55 +0200 Subject: [PATCH 1/7] [`hooks/_common.sh`] Replace `mapfile` to support older Bash --- hooks/_common.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hooks/_common.sh b/hooks/_common.sh index 730848997..576013e07 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -348,7 +348,9 @@ function common::per_dir_hook { local pids=() - mapfile -t dir_paths_unique < <(echo "${dir_paths[@]}" | tr ' ' '\n' | sort -u) + while IFS= read -r _line; do + dir_paths_unique+=("$_line") + done < <(printf '%s\n' "${dir_paths[@]}" | sort -u) local length=${#dir_paths_unique[@]} local last_index=$((${#dir_paths_unique[@]} - 1)) From bf354a2b11870d84ab147928c483eb4e967fe5d1 Mon Sep 17 00:00:00 2001 From: "George L. Yermulnik" Date: Mon, 19 Feb 2024 15:05:18 +0200 Subject: [PATCH 2/7] Declare `dir_paths_unique` as local and as array --- hooks/_common.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/hooks/_common.sh b/hooks/_common.sh index 576013e07..c9e1390f8 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -347,6 +347,7 @@ function common::per_dir_hook { fi local pids=() + local dir_paths_unique=() while IFS= read -r _line; do dir_paths_unique+=("$_line") From a272c3373e388da02ce7a9e7bf8def9f025b99f3 Mon Sep 17 00:00:00 2001 From: "George L. Yermulnik" Date: Mon, 19 Feb 2024 15:20:44 +0200 Subject: [PATCH 3/7] Address PR discussion by creating array in a one-liner --- hooks/_common.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/hooks/_common.sh b/hooks/_common.sh index c9e1390f8..3b4bd79d0 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -347,11 +347,10 @@ function common::per_dir_hook { fi local pids=() - local dir_paths_unique=() - while IFS= read -r _line; do - dir_paths_unique+=("$_line") - done < <(printf '%s\n' "${dir_paths[@]}" | sort -u) + # shellcheck disable=SC2207 + local -a dir_paths_unique=("$(printf '%s\n' "${dir_paths[@]}" | sort -u)") + local length=${#dir_paths_unique[@]} local last_index=$((${#dir_paths_unique[@]} - 1)) From 310cf281de64ddd33fae339d41853ebdb7373dcb Mon Sep 17 00:00:00 2001 From: Maksym Vlasov Date: Mon, 19 Feb 2024 15:31:06 +0200 Subject: [PATCH 4/7] Apply suggestions from code review --- hooks/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/_common.sh b/hooks/_common.sh index 3b4bd79d0..20555bca9 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -349,7 +349,7 @@ function common::per_dir_hook { local pids=() # shellcheck disable=SC2207 - local -a dir_paths_unique=("$(printf '%s\n' "${dir_paths[@]}" | sort -u)") + local -a dir_paths_unique=( $(printf '%s\n' "${dir_paths[@]}" | sort -u) ) local length=${#dir_paths_unique[@]} local last_index=$((${#dir_paths_unique[@]} - 1)) From 2f9dfe984078451b814be8a98ced2727fc128634 Mon Sep 17 00:00:00 2001 From: Maksym Vlasov Date: Mon, 19 Feb 2024 15:31:36 +0200 Subject: [PATCH 5/7] Apply suggestions from code review --- hooks/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/_common.sh b/hooks/_common.sh index 20555bca9..5f5a345be 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -348,7 +348,7 @@ function common::per_dir_hook { local pids=() - # shellcheck disable=SC2207 + # shellcheck disable=SC2207 # More readable way local -a dir_paths_unique=( $(printf '%s\n' "${dir_paths[@]}" | sort -u) ) local length=${#dir_paths_unique[@]} From ebd70793b15d81271081d59169606581a5d3c525 Mon Sep 17 00:00:00 2001 From: pre-commit Date: Mon, 19 Feb 2024 13:32:21 +0000 Subject: [PATCH 6/7] pre-commit fixes --- hooks/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/_common.sh b/hooks/_common.sh index 5f5a345be..d6dbbb272 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -349,7 +349,7 @@ function common::per_dir_hook { local pids=() # shellcheck disable=SC2207 # More readable way - local -a dir_paths_unique=( $(printf '%s\n' "${dir_paths[@]}" | sort -u) ) + local -a dir_paths_unique=($(printf '%s\n' "${dir_paths[@]}" | sort -u)) local length=${#dir_paths_unique[@]} local last_index=$((${#dir_paths_unique[@]} - 1)) From 24ac3cf8b89a47b5d0cc38d50b73cfcd0f0426e1 Mon Sep 17 00:00:00 2001 From: "George L. Yermulnik" Date: Mon, 19 Feb 2024 15:38:20 +0200 Subject: [PATCH 7/7] Address remark about array elements splitting --- hooks/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/_common.sh b/hooks/_common.sh index 3b4bd79d0..8f75a1b43 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -349,7 +349,7 @@ function common::per_dir_hook { local pids=() # shellcheck disable=SC2207 - local -a dir_paths_unique=("$(printf '%s\n' "${dir_paths[@]}" | sort -u)") + local -a dir_paths_unique=($(printf '%s\n' "${dir_paths[@]}" | sort -u)) local length=${#dir_paths_unique[@]} local last_index=$((${#dir_paths_unique[@]} - 1))