From f437f2efab461bc527dd7341dae2452e95455966 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Mon, 24 Sep 2018 10:00:47 +0200 Subject: bin/harvest-commit-times new --- bin/harvest-commit-times | 113 +++++++++++++++++++++++++++++++++++++++++++++++ conf/master.conf.example | 1 + lib/load-configuration | 4 ++ 3 files changed, 118 insertions(+) create mode 100755 bin/harvest-commit-times diff --git a/bin/harvest-commit-times b/bin/harvest-commit-times new file mode 100755 index 0000000..91c96ba --- /dev/null +++ b/bin/harvest-commit-times @@ -0,0 +1,113 @@ +#!/bin/sh + +# shellcheck disable=SC2119,SC2120 + +# shellcheck source=../lib/load-configuration +. "${0%/*}/../lib/load-configuration" + +# shellcheck disable=SC2016 +usage() { + >&2 echo '' + >&2 echo 'harvest-commit-times: harvest the commit times of package' + >&2 echo ' sources from git and put them into the database' + >&2 echo '' + >&2 echo 'possible options:' + >&2 echo ' -h|--help: Show this help and exit.' + >&2 echo ' -w|--wait: If necessary, wait for lock blocking.' + [ -z "$1" ] && exit 1 || exit "$1" +} + +eval set -- "$( + getopt -o hw \ + --long help \ + --long wait \ + -n "$(basename "$0")" -- "$@" || \ + echo usage +)" + +block_flag='-n' + +while true; do + case "$1" in + -h|--help) + usage 0 + ;; + -w|--wait) + block_flag='' + ;; + --) + shift + break + ;; + *) + >&2 echo 'Whoops, forgot to implement option "'"$1"'" internally.' + exit 42 + ;; + esac + shift +done + +if [ $# -ne 0 ]; then + >&2 echo 'Too many arguments.' + usage +fi + +exec 9> "${harvest_commit_times_lock_file}" +if ! verbose_flock ${block_flag} 9; then + >&2 echo 'come back (shortly) later - Another harvest-commit-times is already running.' + exit +fi + +tmp_file=$(mktemp "tmp.harvest-commit-times.XXXXXXXXXX") +trap 'rm "${tmp_file}"' EXIT + +# shellcheck disable=SC2016 +{ + printf 'SELECT' + printf ' `package_sources`.`id`,' + printf '`package_sources`.`pkgbase`,' + printf '`package_sources`.`git_revision`,' + printf '`package_sources`.`mod_git_revision`,' + printf '`upstream_repositories`.`name`,' + printf '`git_repositories`.`name`' + printf ' FROM `package_sources`' + mysql_join_package_sources_upstream_repositories + mysql_join_upstream_repositories_git_repositories + printf ' WHERE `package_sources`.`commit_time`="0000-00-00 00:00:00"' + printf ' AND `package_sources`.`uses_upstream`' +} | \ + mysql_run_query 'unimportant' | \ + sponge | \ + while read -r id pkgbase git_revision mod_git_revision repository git_repository; do + eval 'git_directory="${repo_paths__'"${git_repository}"'}"' + find_pkgbuilds "${pkgbase}" "${repository}" "${git_repository}" "${git_revision}" "${mod_git_revision}" + commit_time=$( + # shellcheck disable=SC2154 + git -C "${git_directory}" log -n 1 --pretty=format:%ct "${git_revision}" -- "${PKGBUILD}" + ) + if [ -n "${commit_time}" ]; then + printf '%s\t%s\n' \ + "${id}" \ + "${commit_time}" + else + >&2 printf 'Package source %s is not available in git.\n' \ + "${id}" + exit 2 + fi + done > \ + "${tmp_file}" + +if [ -s "${tmp_file}" ]; then + # shellcheck disable=SC2016 + { + printf 'CREATE TEMPORARY TABLE `cts` (`id` BIGINT, `ct` BIGINT);\n' + printf 'LOAD DATA LOCAL INFILE "%s" INTO TABLE `cts`(`id`,`ct`);\n' \ + "${tmp_file}" + printf 'UPDATE `cts`' + printf ' JOIN `package_sources`' + printf ' ON `package_sources`.`id`=`cts`.`id`' + printf ' AND `package_sources`.`commit_time`="0000-00-00 00:00:00"' + printf ' SET `package_sources`.`commit_time`=from_unixtime(`cts`.`ct`);\n' + } | \ + mysql_run_query 'unimportant' +fi diff --git a/conf/master.conf.example b/conf/master.conf.example index 1623307..9624fe3 100755 --- a/conf/master.conf.example +++ b/conf/master.conf.example @@ -35,6 +35,7 @@ #mysql_command='mysql buildmaster' #build_list_lock_file="${work_dir}/build-list.lock" +#harvest_commit_times_lock_file="${work_dir}/harvest-commit-times.lock" #package_database_lock_file="${work_dir}/package-database.lock" #sanity_check_lock_file="${work_dir}/sanity-check.lock" #status_lock_file="${work_dir}/status.lock" diff --git a/lib/load-configuration b/lib/load-configuration index 4f6b26a..af3527d 100755 --- a/lib/load-configuration +++ b/lib/load-configuration @@ -136,6 +136,10 @@ if [ -z "${build_list_lock_file}" ]; then build_list_lock_file="${work_dir}/build-list.lock" fi +if [ -z "${harvest_commit_times_lock_file}" ]; then + harvest_commit_times_lock_file="${work_dir}/harvest-commit-times.lock" +fi + if [ -z "${package_database_lock_file}" ]; then package_database_lock_file="${work_dir}/package-database.lock" fi -- cgit v1.2.3-54-g00ecf