pkg_rolling-replace-0.12:

Replace the nested shell loops in depgraph_installed() with some awk
that only needs to invoke pkg_info once. This gives a ~20x speedup.

Previously, if many packages were installed, depgraph generation took a
considerable amount of time; in the order of 30 seconds even on moderately
fast hardware.
This commit is contained in:
tnn 2007-12-02 02:11:05 +00:00
parent 2ab9e539e7
commit 2e9b188782
2 changed files with 22 additions and 14 deletions

View file

@ -1,6 +1,6 @@
# $NetBSD: Makefile,v 1.14 2007/08/17 01:19:45 gdt Exp $ # $NetBSD: Makefile,v 1.15 2007/12/02 02:11:05 tnn Exp $
DISTNAME= pkg_rolling-replace-0.11 DISTNAME= pkg_rolling-replace-0.12
CATEGORIES= pkgtools CATEGORIES= pkgtools
MASTER_SITES= # empty MASTER_SITES= # empty
DISTFILES= # empty DISTFILES= # empty
@ -28,7 +28,7 @@ SUBST_CLASSES+= tools
SUBST_STAGE.tools= pre-configure SUBST_STAGE.tools= pre-configure
SUBST_MESSAGE.tools= Substituting tool locations. SUBST_MESSAGE.tools= Substituting tool locations.
SUBST_FILES.tools= pkg_rolling-replace.sh SUBST_FILES.tools= pkg_rolling-replace.sh
SUBST_VARS.tools= PKG_INFO_CMD MAKE PKG_CHK SUBST_VARS.tools= PKG_INFO_CMD MAKE PKG_CHK AWK
SUBST_CLASSES+= makeconf SUBST_CLASSES+= makeconf
SUBST_STAGE.makeconf= pre-configure SUBST_STAGE.makeconf= pre-configure

View file

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# $NetBSD: pkg_rolling-replace.sh,v 1.14 2007/08/17 01:19:45 gdt Exp $ # $NetBSD: pkg_rolling-replace.sh,v 1.15 2007/12/02 02:11:05 tnn Exp $
#<license> #<license>
# Copyright (c) 2006 BBN Technologies Corp. All rights reserved. # Copyright (c) 2006 BBN Technologies Corp. All rights reserved.
# #
@ -63,6 +63,7 @@
# Substituted by pkgsrc at pre-configure time. # Substituted by pkgsrc at pre-configure time.
MAKE="@MAKE@" MAKE="@MAKE@"
AWK="@AWK@"
test -z "$MAKECONF" && MAKECONF="@MAKECONF@" test -z "$MAKECONF" && MAKECONF="@MAKECONF@"
test -f "$MAKECONF" && test -z "$PKGSRCDIR" && PKGSRCDIR="` \ test -f "$MAKECONF" && test -z "$PKGSRCDIR" && PKGSRCDIR="` \
@ -151,15 +152,22 @@ check_packages_w_flag()
# echo dep->pkg edges for all installed packages # echo dep->pkg edges for all installed packages
depgraph_installed() depgraph_installed()
{ {
for pkgver in $(${PKG_INFO} -e '*'); do ${PKG_INFO} -N '*' | ${AWK} ' \
pkg=$(echo $pkgver | sed 's/-[0-9][^-]*$//') /^Information for/ { \
# Include $pkg as a node without dependencies in case it has none. pkg=$3; sub("-[0-9][^-]*:$", "", pkg); \
echo $pkg $pkg print pkg" "pkg; \
for depver in $(${PKG_INFO} -Nq $pkg); do state=1; \
dep=$(echo $depver | sed 's/-[0-9][^-]*$//') } \
echo $dep $pkg /^./ { \
done if (state == 2) { \
done dep=$1; sub("-[0-9][^-]*$", "", dep); \
print dep" "pkg; \
} \
} \
/^Built using/ { \
state=2 \
} \
'
} }
# usage: who_requires pkg --in-graph DEPGRAPH # usage: who_requires pkg --in-graph DEPGRAPH
@ -320,7 +328,7 @@ while [ -n "$REPLACE_TODO" ]; do
break; break;
fi fi
done done
pkgdir=$(${PKG_INFO} -Bq $pkg | awk -F= '/PKGPATH=/{print $2}' | sed -e 's/^ //') pkgdir=$(${PKG_INFO} -Bq $pkg | ${AWK} -F= '/PKGPATH=/{print $2}' | sed -e 's/^ //')
echo "${OPI} Selecting $pkg ($pkgdir) as next package to replace" echo "${OPI} Selecting $pkg ($pkgdir) as next package to replace"
sleep 1 sleep 1