aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2021-03-12 13:04:32 +0000
committermerakor <cem@ckyln.com>2021-03-12 13:04:32 +0000
commitf7d3e9f6771a75bff790c569a149f0fee1d28f41 (patch)
tree857ce39bcda2a276a4416ab5d591d333a7c85470 /contrib
parentb89f063fcd25ea9d08c1374ea180eefe8c841614 (diff)
downloadcpt-f7d3e9f6771a75bff790c569a149f0fee1d28f41.tar.gz
cpt-revdepends: use library, new options
FossilOrigin-Name: 0dbdfc54c41442587443f818d8ac9af41293905747181ef7e861596934047f99
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/cpt-revdepends47
1 files changed, 37 insertions, 10 deletions
diff --git a/contrib/cpt-revdepends b/contrib/cpt-revdepends
index 5857da1..36fe4fa 100755
--- a/contrib/cpt-revdepends
+++ b/contrib/cpt-revdepends
@@ -1,17 +1,44 @@
#!/bin/sh -e
# Display packages which depend on package
-case "$1" in
- --help|-h)
- printf '%s\n' "usage: ${0##*/} [pkg]"
- exit 0
- ;;
- '') set -- "${PWD##*/}"
-esac
+parser_definition() {
+ setup REST help:usage -- "usage: ${0##*/} [options...] [pkg...]"
+ flag tree -t --tree -- "Also print indirect reverse dependencies"
+ flag make -m --make -- "Include make dependencies"
+ global_options
+}
+
+. cpt-lib; set +f
+
+[ "$1" ] || set -- "${PWD##*/}"
# 'cd' to the database directory as a simple way of
# stripping the path and performing a 'basename'.
-cd "$CPT_ROOT/var/db/cpt/installed"
+cd "$sys_db"
+
+get_revdep() {
+ query="^$1\$"
+ [ "$make" ] && query="$query\\|^$1 *make\$"
+ grep "$query" -- */depends | while read -r pkg _; do
+ printf '%s\n' "${pkg%%/*}"
+ done
+}
-# Use a simple 'grep' to display packages depending on '$1'.
-grep "^$1\$" -- */depends
+if [ "$tree" ]; then
+ create_cache nobuild
+ :> "$tmp_dir/processed"
+ get_revdep "$1" > "$tmp_dir/dep"
+ while ! diff -q "$tmp_dir/dep" "$tmp_dir/processed" >/dev/null 2>&1; do
+ cp "$tmp_dir/dep" "$tmp_dir/dep.new"
+ while read -r line; do
+ grep -q "^$line\$" "$tmp_dir/processed" && continue
+ get_revdep "$line" >> "$tmp_dir/dep.new"
+ printf '%s\n' "$line" >> "$tmp_dir/processed"
+ done < "$tmp_dir/dep"
+ sort -u -o "$tmp_dir/dep" "$tmp_dir/dep.new"
+ sort -u -o "$tmp_dir/processed" "$tmp_dir/processed"
+ done
+ cat "$tmp_dir/dep"
+else
+ get_revdep "$1"
+fi