Skip to contentSkip to conversation

mbuto: add a function to find the difference of two lists

PATCH Applied Sevinj Aghayeva 2 participants 2 messages Apr 15, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mbuto: add a function to find the difference of two lists

Adds a function to find the difference of two lists and use that function to determine the list of missing modules.

---
 mbuto | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)
mbuto +18 -9
index 74c81eb..14176c3 100755
@@ -245,15 +245,8 @@ profile_kselftests() {
 
 		KMODS="$(${BASENAME} -a -s .ko ${KMODS})"
 
-		__kmods_missing=
-		for __n in ${__kmods_needed}; do
-			__found=0
-			for __f in ${KMODS}; do
-				[ ${__n} = ${__f} ] && __found=1
-			done
-			[ ${__found} -eq 0 ] && \
-				__kmods_missing="${__n} ${__kmods_missing}"
-		done
+		__kmods_missing=$(list_diff "${__kmods_needed}" "${KMODS}")
+
 		if [ ! -z "${__kmods_missing}" ]; then
 			notice "WARNING: missing modules: ${__kmods_missing}"
 		fi
@@ -426,6 +419,22 @@ workers() {
 	while ! ${RMDIR} "${__sync_dir}" 2>/dev/null; do ${SLEEP} 1; done
 }
 
+# list_diff() - Given two lists, $1 and $2, returns the tokens that exist in $1
+# but not in $2
+# $1: list
+# $2: list
+list_diff() {
+	__diff=
+	for __e1 in ${1}; do
+		__found=0
+		for __e2 in ${2}; do
+			[ ${__e1} = ${__e2} ] && __found=1
+		done
+		[ ${__found} -eq 0 ] && __diff="${__e1} ${__diff}"
+	done
+	printf '%s' "${__diff}"
+}
+
 ################################################################################
 
 
Signature · 1 line
2.25.1
#1 lore raw

Applied, with a couple of minor changes:

Quoted 1 line · On Fri, 15 Apr 2022 00:03:12 -0400 Sevinj Aghayeva <[email protected]>…

Adds a function to find the difference of two lists and use that function to

Used imperative mood ("add") for consistency (with e.g. "use").

Quoted 1 line

determine the list of missing modules.

Wrapped this to 70 columns -- somewhat arbitrary, I don't even think there's consensus on current kernel practices, somebody uses 72 or even 76 columns.

Rationale: allow email discussion at a reasonable thread depth without further wrapping in a "small" terminal.

Quoted 28 lines
---
 mbuto | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)
mbuto +2 -9
index 74c81eb..14176c3 100755
@@ -245,15 +245,8 @@ profile_kselftests() {
 
 		KMODS="$(${BASENAME} -a -s .ko ${KMODS})"
 
-		__kmods_missing=
-		for __n in ${__kmods_needed}; do
-			__found=0
-			for __f in ${KMODS}; do
-				[ ${__n} = ${__f} ] && __found=1
-			done
-			[ ${__found} -eq 0 ] && \
-				__kmods_missing="${__n} ${__kmods_missing}"
-		done
+		__kmods_missing=$(list_diff "${__kmods_needed}" "${KMODS}")
+
 		if [ ! -z "${__kmods_missing}" ]; then
 			notice "WARNING: missing modules: ${__kmods_missing}"
 		fi

mbuto workers() { · line 422

Quoted 4 lines
mbuto +1 -0
@@ -426,6 +419,22 @@ workers() {
 	while ! ${RMDIR} "${__sync_dir}" 2>/dev/null; do ${SLEEP} 1; done
 }
 
+# list_diff() - Given two lists, $1 and $2, returns the tokens that exist in $1

Imperative mode ("return" instead of "returns") for consistency, made it a bit shorter so that it fits on one line (for readability).

mbuto workers() { · line 425

Quoted 3 lines
mbuto +3 -0
+# but not in $2
+# $1: list
+# $2: list

Tabs to separate, and a slightly more informative description of the arguments.

Quoted 15 lines
mbuto +12 -0
+list_diff() {
+	__diff=
+	for __e1 in ${1}; do
+		__found=0
+		for __e2 in ${2}; do
+			[ ${__e1} = ${__e2} ] && __found=1
+		done
+		[ ${__found} -eq 0 ] && __diff="${__e1} ${__diff}"
+	done
+	printf '%s' "${__diff}"
+}
+
 ################################################################################
 
 
Signature · 1 line
Stefano