Compare commits

..

1 Commits

Author SHA1 Message Date
phoebos
a0f6e89299
kiss: speedup pkg_find when finding one package
pkg_find is used for 2 purposes:
 - finding all packages in KISS_PATH that meet some criteria
 - finding the first package in KISS_PATH that meets criteria

The first is the case for `kiss search` but the second is more common.
It is used everywhere to find the first package, that is, the package to
be used for builds, downloads, upgrades etc.
However, in both cases, every repo in KISS_PATH is scanned for the
package, which is unnecessary in the second case which only needs the
first match. Therefore, break after the first match in this case.

On my system, this results in a 2x speedup of `kiss U` (just the logic
to detect upgrades, exiting before prompting).
2023-06-14 01:57:40 +01:00
4 changed files with 5 additions and 50 deletions

View File

@ -1,9 +0,0 @@
steps:
build:
image: alpine
when:
branch: [ master ]
commands: |
apk add --no-cache shellcheck
shellcheck kiss contrib/*

View File

@ -1,16 +0,0 @@
#!/bin/sh -ef
# Display a package's dependencies in repositories
pkg=${1:-"${PWD##*/}"}
kiss search "$pkg" >/dev/null || {
printf 'usage: kiss-depends [pkg]\n' >&2
exit 1
}
kiss search "$pkg" | while read -r pkgpath; do
printf '=> %s\n' "$pkgpath"
while read -r dep mak || [ "$dep" ]; do
printf '%s%s\n' "$dep" "${mak:+ "$mak"}"
done 2>/dev/null < "$pkgpath/depends"
done

View File

@ -1,19 +0,0 @@
#!/bin/sh
# Display packages in all repositories which depend on a package
[ "$1" ] || set -- "${PWD##*/}"
suffix () {
case "$1" in *"$2") return 0; esac; return 1
}
IFS=:
for repo in $KISS_PATH; do
# remove trailing slashes
while suffix "$repo" /; do repo="${repo%/}"; done
gitdir="$(git -C "$repo" rev-parse --show-toplevel 2>/dev/null || echo "$repo")"
case "$gitdir" in "$repo") unset prefix ;; *) prefix="${repo##*/}/" ;; esac
cd "$gitdir/.." || continue
grep -E "^$1([[:space:]]|$)" -- "${gitdir##*/}/$prefix"*/depends 2>/dev/null ||:
done

11
kiss
View File

@ -330,7 +330,10 @@ _pkg_find() {
for _find_path in $4 "${3:-$sys_db}"; do set +f for _find_path in $4 "${3:-$sys_db}"; do set +f
ok "$_find_path" || continue ok "$_find_path" || continue
for _find_pkg in "$_find_path/"$1; do for _find_pkg in "$_find_path/"$1; do
test "${3:--d}" "$_find_pkg" && set -f -- "$@" "$_find_pkg" test "${3:--d}" "$_find_pkg" && {
set -f -- "$@" "$_find_pkg"
case $2- in -) break 2 ;; esac
}
done done
done done
@ -2007,7 +2010,6 @@ args() {
KISS_PID="$KISS_PID" \ KISS_PID="$KISS_PID" \
KISS_ROOT="$KISS_ROOT" \ KISS_ROOT="$KISS_ROOT" \
KISS_TMPDIR="$KISS_TMPDIR" \ KISS_TMPDIR="$KISS_TMPDIR" \
_KISS_DATE="$time" \
_KISS_LVL="$_KISS_LVL" \ _KISS_LVL="$_KISS_LVL" \
"$0" "$action" "$@" "$0" "$action" "$@"
@ -2161,10 +2163,7 @@ main() {
# Store the date and time of script invocation to be used as the name of # Store the date and time of script invocation to be used as the name of
# the log files the package manager creates during builds. # the log files the package manager creates during builds.
# Accept _KISS_DATE in case this process has been called by a kiss process time=$(date +%Y-%m-%d-%H:%M)
# started on a different day, which could cause permission issues if we
# create log_dir as root.
time=${_KISS_DATE:-"$(date +%Y-%m-%d-%H:%M)"}
create_tmp_dirs create_tmp_dirs
trap_on trap_on