From 686435fc9fced939a525b7437ec3e7af6c01aee0 Mon Sep 17 00:00:00 2001 From: merakor Date: Thu, 22 Jul 2021 09:06:45 +0000 Subject: cpt-revdepends: fix grep usage, and $tmp_dir FossilOrigin-Name: f51f87ee1550beaf2b698922c8887806d39c9aa85c9325037f5a46061716624d --- contrib/cpt-revdepends | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'contrib') diff --git a/contrib/cpt-revdepends b/contrib/cpt-revdepends index 833dea2..e8e8143 100755 --- a/contrib/cpt-revdepends +++ b/contrib/cpt-revdepends @@ -41,11 +41,11 @@ parser_definition() { cd "$sys_db" get_revdep() { - query="^$1\$" + pkg=$1; set -- "^$pkg\$" # Defined by parser. # shellcheck disable=2154 - [ "$make" ] && query="$query\\|^$1 *make\$" - grep "$query" -- */depends | while read -r pkg _; do + [ "$make" ] && set -- -e "$1" -e "^$pkg " + grep "$@" -- */depends | while read -r pkg _; do printf '%s\n' "${pkg%%/*}" done } @@ -53,7 +53,7 @@ get_revdep() { # Defined by parser. # shellcheck disable=2154 if [ "$tree" ]; then - create_cache nobuild + mkdir -p "$tmp_dir" :> "$tmp_dir/processed" get_revdep "$1" > "$tmp_dir/dep" while ! diff -q "$tmp_dir/dep" "$tmp_dir/processed" >/dev/null 2>&1; do -- cgit v1.2.3 From 31ec224db55bb90c451b121fcc03b36f4fff5d5e Mon Sep 17 00:00:00 2001 From: merakor Date: Thu, 22 Jul 2021 09:09:29 +0000 Subject: cpt-revdepends: fix usage string FossilOrigin-Name: 4e34c38625436d6f4a9d0abc3adfc9042862792e8471b50c3ef573e157b56ecf --- contrib/cpt-revdepends | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'contrib') diff --git a/contrib/cpt-revdepends b/contrib/cpt-revdepends index e8e8143..3529a53 100755 --- a/contrib/cpt-revdepends +++ b/contrib/cpt-revdepends @@ -22,7 +22,7 @@ ## .El parser_definition() { - setup REST help:usage -- "usage: ${0##*/} [options...] [pkg...]" + 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 -- cgit v1.2.3 From 9fee0d52ae7327c3b781bf24cb595342cd8a6193 Mon Sep 17 00:00:00 2001 From: merakor Date: Thu, 22 Jul 2021 10:07:40 +0000 Subject: cpt-maintainer: add tool to display the maintainer of the given package FossilOrigin-Name: aa2c95809a8569425002c8e5a6993df7830ccfbf3ade159d5b9da829992a7a7f --- contrib/cpt-maintainer | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 contrib/cpt-maintainer (limited to 'contrib') diff --git a/contrib/cpt-maintainer b/contrib/cpt-maintainer new file mode 100755 index 0000000..34f212f --- /dev/null +++ b/contrib/cpt-maintainer @@ -0,0 +1,49 @@ +#!/bin/sh -e +# Find the maintainer of a package + +## SYNOPSIS: +## .Nm +## .Op Ar pkg... + +## DESCRIPTION: +## .Nm +## finds the maintainer of the given pacage. If no package name is given, +## .Nm +## will use the name of the current directory as the package. + +# shellcheck disable=1091 +. cpt-lib + +usage() { + out "usage: ${0##*/} [pkg...]" + exit +} + +case $1 in + --help|-h) usage ;; + '') set -- "${PWD##*/}" +esac + +for pkgname; do + cpt-search -d "$pkgname" | while read -r pkg; do + # Default to the 'meta' file of the package instead of jumping through + # VCS hoops to find out. + log "$pkg" " " + pkg_query_meta "$pkg" maintainer && continue + + cd "$pkg" + # Use pkg_vcs_info to find out the repository type, but don't save + # repository information to the repository cache file. + repo_type=$(CPT_REPO_CACHE=0 pkg_vcs_info) + repo_type=${repo_type##*:} + + # We use the latest author who made a change to the version file to + # identify the maintainer of a package. + case $repo_type in + git) git log -1 --format='%an <%ae>' version ;; + fossil) fossil time par cur -n 1 -p version -F "%a" | sed \$d ;; + hg) hg log -l1 -T '{user}\n' -- version ;; + *) out "Maintainer information not available" + esac + done +done -- cgit v1.2.3 From b18adcfd202ea80581e57df08a3fe559f9a78ae4 Mon Sep 17 00:00:00 2001 From: merakor Date: Mon, 26 Jul 2021 22:39:53 +0000 Subject: cpt-size: rewrite tool to address POSIX compliance, faster calculation, and argument count limitations on huge packages FossilOrigin-Name: 01179eddc1e9cfa4183377c1f09da1de09f5ed0a801d81a94ae2aa8021ed1ff5 --- contrib/cpt-size | 65 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 32 deletions(-) (limited to 'contrib') diff --git a/contrib/cpt-size b/contrib/cpt-size index 2812d56..0ece039 100755 --- a/contrib/cpt-size +++ b/contrib/cpt-size @@ -11,40 +11,41 @@ ## .Ar packages ## using the files from the package manifest and outputs a total size of the ## packages along with all the files associated with them. +parser_definition() { + setup REST help:usage -- "usage: ${0##*/} [pkg...]" + disp :usage -h --help hidden:1 +} -## CAVEATS: -## .Nm -## uses the non-POSIX -## .Fl h -## and -## .Fl c -## flags for -## .Xr du 1 , -## which will not work with -## .Em sbase , -## but it is a major performance improvement compared to calculating -## total and human-readable sizes by hand. +# shellcheck source=/bin/cpt-lib +# shellcheck disable=1091 +. cpt-lib -case "$1" in - --help|-h) - printf '%s\n' "usage: ${0##*/} [pkg...]" - exit 0 - ;; - '') set -- "${PWD##*/}" -esac +# Ensure that all the packages given as arguments are installed. +pkg_list "$@" >/dev/null -for pkg; do cpt-list "$pkg" >/dev/null; done +mkdir -p "$tmp_dir" -files= -for pkg; do - while read -r file; do - # Filter directories from manifest and leave only files. - # Directories in the manifest end in a trailing '/'. - case $file in */) continue; esac - files="$files '$file'" - done < "$CPT_ROOT/var/db/cpt/installed/$pkg/manifest" -done -eval "set -- $files" +# We don't immediately pipe into awk as we want to exit in an error. +for pkg; do sed '/\/$/d;s/./\\&/g' "$sys_db/$pkg/manifest"; done | + xargs du -k > "$tmp_dir/size" -# Send the file list to 'du'. -du -shc -- "$@" 2>/dev/null +# This awk function formats the `du` output similar to the '-hc' flags. We +# could have used a shell `while read` loop to do the exact same thing, but that +# would be much much slower. +awk 'function fmtsize(s) { + if (s==0) f="" + else if (s<1024) f="K" + else if (s<(1048576)){f="M";s=s/1024;} + else if (s<(1073741824)){f="G";s=s/1048576;} + else f="" + return int(s) f + } + { + sc = $1 + size += $1 + sub(sprintf("^%s\s*", $1), "") + printf("%-6s %s\n", fmtsize(sc), $0) + } + END { + printf("%-6s total\n", fmtsize(size)) + }' "$tmp_dir/size" -- cgit v1.2.3