Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2019-06-18 13:22:26 +0200
committerErich Eckner <git@eckner.net>2019-06-18 13:22:26 +0200
commit58fa076f7312c5cc6b879f462b785c11cec55cb5 (patch)
treedb07f82237941c3c6e0f2ac7423d188aa14a186f /lib
parentf286f76871841745021ede6a4dba8ef2bbffdafe (diff)
lib/common-functions: update_blocked_packages_count() new to fill that column
Diffstat (limited to 'lib')
-rwxr-xr-xlib/common-functions92
1 files changed, 92 insertions, 0 deletions
diff --git a/lib/common-functions b/lib/common-functions
index 873521d..5dd1c0d 100755
--- a/lib/common-functions
+++ b/lib/common-functions
@@ -947,3 +947,95 @@ apply_trunk_patch() {
-type f \
-exec cp '{}' "${source_dir}" \;
}
+
+# update_blocked_packages_count
+# update the count how many packages are blocked by a build assignment
+update_blocked_packages_count() {
+ ( # new shell is intentional
+ temp_dir=$(mktemp -d 'tmp.sanity-check.XXXXXXXXXX' --tmpdir)
+ trap 'rm -rf --one-file-system "${temp_dir}"' EXIT
+ # shellcheck disable=SC2016
+ {
+ printf 'SELECT '
+ printf '`a_bp`.`build_assignment`,'
+ printf '`b_bp`.`build_assignment`'
+ printf ' FROM `binary_packages` AS `a_bp`'
+ mysql_join_binary_packages_binary_packages_in_repositories 'a_bp' 'a_bpir'
+ printf ' AND `a_bpir`.`repository`=%s' \
+ "${repository_ids__any_build_list}"
+ mysql_join_binary_packages_dependencies 'a_bp'
+ mysql_join_dependencies_dependency_types
+ printf ' AND `dependency_types`.`relevant_for_binary_packages`'
+ mysql_join_dependencies_install_target_providers_with_versions
+ mysql_join_install_target_providers_binary_packages '' 'b_bp'
+ mysql_join_binary_packages_binary_packages_in_repositories 'b_bp' 'b_bpir'
+ printf ' AND `a_bpir`.`repository`=%s' \
+ "${repository_ids__any_build_list}"
+ printf ' WHERE `a_bp`.`architecture`=`b_bp`.`architecture`'
+ printf ' OR `a_bp`.`architecture`=%s' \
+ "${architecture_ids__any}"
+ printf ' OR `b_bp`.`architecture`=%s' \
+ "${architecture_ids__any}"
+ } | \
+ mysql_run_query | \
+ tr '\t' ' ' | \
+ sort -u | \
+ sort -k1,1 > \
+ "${temp_dir}/links.new"
+ touch "${temp_dir}/links.1" "${temp_dir}/links.2"
+ # new links (sorted by 1st column); old links (sorted by 1st / 2nd column)
+ while [ -s "${temp_dir}/links.new" ]; do
+ cat "${temp_dir}/links.1" "${temp_dir}/links.new" | \
+ sort -k2,2 > \
+ "${temp_dir}/links.2"
+ sort -k1,1 "${temp_dir}/links.2" > \
+ "${temp_dir}/links.1"
+ duplicates=$(
+ uniq -d "${temp_dir}/links.1"
+ )
+ if [ -n "${duplicates}" ]; then
+ >&2 echo 'internal error: there are %s duplicate links' \
+ "$(
+ printf '%s\n' "${duplicates}" | \
+ wc -l
+ )"
+ exit 42
+ fi
+ {
+ {
+ join -1 2 -2 1 -o 1.1,2.2 "${temp_dir}/links.2" "${temp_dir}/links.new"
+ sort -k2,2 "${temp_dir}/links.new" | \
+ join -1 2 -2 1 -o 1.1,2.2 - "${temp_dir}/links.1"
+ sort -k2,2 "${temp_dir}/links.new" | \
+ join -1 2 -2 1 -o 1.1,2.2 - "${temp_dir}/links.new"
+ } | \
+ sort -u
+ sed 'p' "${temp_dir}/links.1"
+ } | \
+ sort | \
+ uniq -u | \
+ sort -k1,1 | \
+ sponge "${temp_dir}/links.new"
+ done
+ cut -d' ' -f1 "${temp_dir}/links.1" | \
+ uniq -c | \
+ sed 's/^\s\+//' | \
+ tr ' ' '\t' > \
+ "${temp_dir}/link-counts"
+ # shellcheck disable=SC2016
+ {
+ printf 'CREATE TEMPORARY TABLE `lc` ('
+ printf '`count` MEDIUMINT,'
+ printf '`ba_id` BIGINT,'
+ printf 'PRIMARY KEY (`ba_id`)'
+ printf ');\n'
+ printf 'LOAD DATA LOCAL INFILE "%s" INTO TABLE `lc`(`count`,`ba_id`);\n' \
+ "${temp_dir}/link-counts"
+ printf 'UPDATE `build_assignments`'
+ printf ' LEFT JOIN `lc`'
+ printf ' ON `build_assignments`.`id`=`lc`.`ba_id`'
+ printf ' SET `build_assignments`.`currently_blocking`=`lc`.`count`;\n'
+ } | \
+ mysql_run_query
+ )
+}