From 313d1ee619363eca0b8b0742a2d58c9ce18877fd Mon Sep 17 00:00:00 2001 From: Isaac David Date: Sat, 14 Oct 2017 00:54:20 -0500 Subject: blacklist get-rep: re-implement to query repos instead of blacklist.txt Rationale: https://lists.parabola.nu/pipermail/dev/2017-October/005936.html This makes get-rep a general-purpose tool for finding replacements and providers of any package, not just blacklisted-ones. It works equally well reading from full blacklist.txt lines, just pkgname lines, and unwittingly; a single line with many pkgnames. Some caveats for further discussion: - This changes behavior from showing just one replacement/provider to _all_ replacements and providers (including pkgname itself) in the repos. - By "repos" I mean the repos the executing machine is configured to access. This could be changed in the future with `expac --config` if more package databases are desired (e.g. different architecture). - Results are shown using the "repo/pkgname ..." format rather than just "pkgname ...". I think this makes the program more useful. - Results aren't reordered to ensure that the first provider of pkgname is pkgname itself. Order will be as expected otherwise, by virtue of expac parsing repos in order. --- src/lib/blacklist.sh | 19 ++++++++++++++++++- test/lib-blacklist-test.sh | 10 +++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/lib/blacklist.sh b/src/lib/blacklist.sh index e3d976b..c092ed3 100755 --- a/src/lib/blacklist.sh +++ b/src/lib/blacklist.sh @@ -93,7 +93,24 @@ blacklist-get-pkg() { # Usage: blacklist-cat | blacklist-get-rep # Prints only the replacement package field of the blacklist line(s) on stdin. blacklist-get-rep() { - blacklist-normalize | cut -d: -f2 + local -a targets=($(blacklist-get-pkg)) + expac -Ss '%r/%n %n %P %R' | awk -v arr="${targets[*]}" ' + { + gsub("[=<>]+[^[:blank:]]*", "", $0) # discard versioning + # build pkg -> providers table from pkg -> provides + for (provided = 2; provided <= NF; ++provided) { + if (! seen[$1 " " $provided]++) { + providers[$provided] = providers[$provided] $1 " " + } + } + } + END { + split(arr, targets, " ") + for (pkg in targets) { + sub("[ \t]+$", "", providers[targets[pkg]]) + print providers[targets[pkg]] + } + }' } # Usage: blacklist-cat | blacklist-get-url diff --git a/test/lib-blacklist-test.sh b/test/lib-blacklist-test.sh index 1f8c518..7b88b72 100755 --- a/test/lib-blacklist-test.sh +++ b/test/lib-blacklist-test.sh @@ -8,16 +8,16 @@ _blacklist_url=https://projects.parabola.nu/blacklist.git/plain/blacklist.txt it_works_with_just_pkgname() { v="$(libreblacklist normalize <<