Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of interference-bump #96

Closed
wants to merge 15 commits into from
107 changes: 79 additions & 28 deletions src/lib/interfere.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -145,45 +145,96 @@ function interference-makepkg() {
function interference-bump() {
set -euo pipefail

local _PACKAGES _PKGTAG _VERSION _BUMPSFILE _BUMPS _BUMP
local _PACKAGES _PKGTAG _BUMPSFILE _BUMPS
local _BUMPS_TMP _BUMPS_UPD _BUMPS_RVW _BUMP _LINE

_BUMPSFILE="${CAUR_INTERFERE}/PKGREL_BUMPS"

if [ -f "${_BUMPSFILE}" ]; then
_BUMPS=$(<"${_BUMPSFILE}")
if [[ -f "${_BUMPSFILE}" ]]; then
_BUMPS=$(sort -u "${_BUMPSFILE}")
else
_BUMPS=""
fi

_PACKAGES="$(repoctl list -v)"

# Clear old bumps
while IFS= read -r _BUMP; do
_PKGTAG=${_BUMP%% *}
_VERSION="$(awk -v pkgtag="${_PKGTAG}" '$1==pkgtag { print $NF; exit }' <<<"${_PACKAGES}")"
local _INTERNALVERSION _INTERNALBUMPCOUNT
IFS=";" read -r _INTERNALVERSION _INTERNALBUMPCOUNT <<<"$(awk -v pkgtag="${_PKGTAG}" '$1==pkgtag { print $2 ";" $3; exit }' <<<"${_BUMPS}")"
if [[ -z "${_INTERNALVERSION}" ]] || [[ -z "${_INTERNALBUMPCOUNT}" ]]; then
continue
fi
if [[ "$(vercmp "${_VERSION}" "${_INTERNALVERSION}.${_INTERNALBUMPCOUNT}")" -gt 0 ]]; then
_BUMPS="$(awk -v pkgtag="$_PKGTAG" '/^$/ {next} $1==pkgtag { next } 1' <<<"${_BUMPS}")"
fi
done <<<"$_BUMPS"

# Add/increase existing bumps
# format: [name] [version]-[pkgrel] [bump]
_PACKAGES="$(
repoctl list -v \
| sed -E \
-e 's@-([0-9]+\S*)$@-\1 0@' \
-e 's@-([0-9]+)(\.([0-9]+)) 0$@-\1 \3@' \
| sort -u
)"

# collect packages with mismatched pkgver, pkgrel, or bump
_BUMPS_TMP=$(
comm -13 \
<(sort -u <<<"${_PACKAGES}" || true) \
<(sort -u <<<"${_BUMPS}" || true)
)

# combine mismatched package with current listing
_BUMPS_TMP+=$(
echo
while read -r _LINE; do
[[ -z "${_LINE}" ]] && continue
grep -Esm1 '^'"${_LINE%% *}"'\b .*$' <<<"${_PACKAGES}"
done <<<"${_BUMPS_TMP}"
)

# _BUMPS_RVW will contain packages that need review.
# These are usually packages that have yet to be rebuilt.
# The pkgver and pkgrel match, but bump is still mismatched.
_BUMPS_RVW=$(
echo
sort -u <<<"${_BUMPS_TMP}"
)

# _BUMPS_UPD will contain packages with new releases.
# The pkgver and pkgrel no longer match the bump list.
_BUMPS_UPD=$(
sed -Ez \
-e 's&\n(\S+ \S+) \S+\n\1 \S+\n&\n\n&g' \
-e 's&\n(\S+ \S+) \S+\n\1 \S+\n&\n\n&g' \
<<<"${_BUMPS_RVW}" | sort -u || true
)

_BUMPS_RVW=$(
comm -23 \
<(sort -u <<<"${_BUMPS_RVW}" || true) \
<(sort -u <<<"${_BUMPS_UPD}" || true)
)

# remove updated packages from bump list
_BUMPS_TMP=$(sed -E 's& .*$&&' <<<"${_BUMPS_UPD}")

while read -r _LINE; do
[[ -z "${_LINE}" ]] && continue
_BUMPS=$(
sed -E "/^${_LINE} .*+\$/d" <<<"${_BUMPS}"
)
done <<<"${_BUMPS_TMP}"

# add new bump or increase existing one
for _PKGTAG in "$@"; do
_VERSION="$(awk -v pkgtag="${_PKGTAG}" '$1==pkgtag { print $NF; exit }' <<<"${_PACKAGES}")"
if [ -z "${_VERSION}" ]; then
echo "Package ${_PKGTAG} not found in repo" >&2
return 1
[[ -z "$_PKGTAG" ]] && continue
# increase existing bump
_LINE=$(grep -Esm1 "^$_PKGTAG " <<<"$_BUMPS" || true)
if [[ -z "$_LINE" ]]; then
# add new bump
_LINE=$(grep -Esm1 "^$_PKGTAG " <<<"$_PACKAGES" || true)
[[ -n "$_LINE" ]] && _BUMPS+=$'\n'"$_LINE"
fi
if [[ -n "$_LINE" ]]; then
_BUMP=$(sed -E 's&^.* ([0-9]+)&\1&' <<<"$_LINE")
_BUMPS=$(sed -E 's&^('"${_LINE% *}"') '"$_BUMP"'$&\1 '"$((_BUMP + 1))"'&' <<<"$_BUMPS")
fi
_VERSION="${_VERSION##* }"
_BUMPS="$(awk -v pkgtag="$_PKGTAG" -v version="$_VERSION" '/^$/ {next} $1==pkgtag { if (!set) { print $1 " " $2 " " $3+1; set=1 }; next } ENDFILE { if (!set) { print pkgtag " " version " " "1" }; exit } 1' <<<"${_BUMPS}")"
done

echo "${_BUMPS}"
echo "${_BUMPS}" >"${_BUMPSFILE}"
# display packages for review
echo "${_BUMPS_RVW}" | sed -E 's& .*$&&' | sort -u

# update bump file
sort -u <<<"${_BUMPS}" >"${_BUMPSFILE}"

interfere-push-bumps || interfere-sync
return 0
Expand Down