commit:     079586e7a0d89ba1050567549e954bcf2b5d0976
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Fri Jul 18 20:20:51 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Jul 22 22:29:36 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=079586e7

isolated-functions.sh: don't define find0() as a self-redeclaring function

Presently, find0() is implemented as a self-redeclaring function. Upon
first being called, if chooses one of two implementations, one of which
serves to cover situations where the -files0-from option is unavailable,
thereby retaining compatibility with the outdated GitHub CI environment.
However, the "isolated-functions.sh" unit calls find0() at the time of
being sourced, for reasons that are explained by commit 3fa9f4d6aa.

Instead, hoist the test for the -files0-from option so that an
implementation is chosen without having to explicitly call the function.
This serves both as a micro-optimisation and as a minor code cleanup.

See-also: 3fa9f4d6aa646553a45cd0118fe46adb64bafd13
See-also: b381d3533901b03ca50329d020c51c82757cdb5e
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 bin/isolated-functions.sh | 51 ++++++++++++++++++++---------------------------
 1 file changed, 22 insertions(+), 29 deletions(-)

diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh
index 109c1cd9c6..6db0340926 100644
--- a/bin/isolated-functions.sh
+++ b/bin/isolated-functions.sh
@@ -691,34 +691,27 @@ contains_word() {
 # parameters shall be conveyed verbatim and are guaranteed to be treated as
 # options and/or primaries, provided that the version of GNU findutils is 4.9.0
 # or greater. For older versions, no such guarantee is made.
-find0() {
-       if printf '/\0' | find -files0-from - -maxdepth 0 &>/dev/null; then
-               find0() {
-                       find -files0-from - "$@"
-               }
-       else
-               # This is a temporary workaround for the GitHub CI runner, which
-               # suffers from an outdated version of findutils, per bug 957550.
-               find0() {
-                       local -a opts paths
-
-                       # All of -H, -L and -P are options. If specified, they
-                       # must precede pathnames and primaries alike.
-                       while [[ $1 == -[HLP] ]]; do
-                               opts+=("$1")
-                               shift
-                       done
-                       mapfile -td '' paths
-                       if (( ${#paths[@]} )); then
-                               find "${opts[@]}" "${paths[@]}" "$@"
-                       fi
-               }
-       fi
-
-       find0 "$@"
-}
-
-# Initialise the function now because find0() is normally called after forking.
-find0 < /dev/null
+if printf '/\0' | find -files0-from - -maxdepth 0 &>/dev/null; then
+       find0() {
+               find -files0-from - "$@"
+       }
+else
+       # This is a temporary workaround for the GitHub CI runner, which
+       # suffers from an outdated version of findutils, per bug 957550.
+       find0() {
+               local -a opts paths
+
+               # All of -H, -L and -P are options. If specified, they must
+               # precede pathnames and primaries alike.
+               while [[ $1 == -[HLP] ]]; do
+                       opts+=("$1")
+                       shift
+               done
+               mapfile -td '' paths
+               if (( ${#paths[@]} )); then
+                       find "${opts[@]}" "${paths[@]}" "$@"
+               fi
+       }
+fi
 
 true

Reply via email to