Signed-off-by: Eli Schwartz <eschwartz@archlinux.org> --- db-functions-svn | 46 ++++++++++++++++++++++++++++++++++++++++++++++ db-move | 23 ++++------------------- db-remove | 5 ++--- 3 files changed, 52 insertions(+), 22 deletions(-) diff --git a/db-functions-svn b/db-functions-svn index 9903f55e..f971cd2e 100644 --- a/db-functions-svn +++ b/db-functions-svn @@ -58,3 +58,49 @@ find_repo_for_package() { printf '%s\n' "${repos[@]%/}" } + +# Commit changes staged by (successive?) vcs_(re)?move_package runs. +vcs_commit() { + arch_svn commit -q "${WORKDIR}/svn/${pkgbase}" -m "${1}" +} + +# Write to the VCS in order to track a package moving between different pacman +# repositories. +vcs_move_package() { + local pkgbase=${1} + local vcsrepo_from=${WORKDIR}/svn/${pkgbase}/repos/${2} + local vcsrepo_to=${WORKDIR}/svn/${pkgbase}/repos/${3} + + if [[ ! -d ${WORKDIR}/svn ]]; then + arch_svn checkout -q -N "${SVNREPO}" "${WORKDIR}/svn" >/dev/null + fi + arch_svn up -q "${WORKDIR}/svn/${pkgbase}" >/dev/null + + if [[ -d ${vcsrepo_to} ]]; then + while read -r file; do + arch_svn rm -q "${vcsrepo_to}/${file}@" + done < <(arch_svn ls "${vcsrepo_to}") + else + mkdir "${vcsrepo_to}" + arch_svn add -q "${vcsrepo_to}" + fi + + while read -r file; do + arch_svn mv -q -r HEAD "${vcsrepo_from}/${file}@" "${vcsrepo_to}/" + done < <(arch_svn ls "${vcsrepo_from}") + arch_svn rm --force -q "${vcsrepo_from}" +} + +# Write to the VCS in order to track a package being deleted from a pacman +# repository. +vcs_remove_package() { + local pkgbase=${1} + local vcsrepo=${WORKDIR}/svn/${pkgbase}/repos/${2} + + if [[ ! -d ${WORKDIR}/svn ]]; then + arch_svn checkout -q -N "${SVNREPO}" "${WORKDIR}/svn" >/dev/null + fi + + arch_svn up -q "${WORKDIR}/svn/${pkgbase}" > /dev/null + arch_svn rm --force -q "${vcsrepo}" +} diff --git a/db-move b/db-move index 4867b41f..72aa0b35 100755 --- a/db-move +++ b/db-move @@ -58,15 +58,12 @@ for arch in "${ARCHES[@]}"; do declare -a add_pkgs_$arch declare -a remove_pkgs_$arch done -arch_svn checkout -q -N "${SVNREPO}" "${WORKDIR}/svn" >/dev/null for pkgbase in "${args[@]:2}"; do - arch_svn up -q "${WORKDIR}/svn/${pkgbase}" >/dev/null tag_list="" for pkgarch in "${ARCHES[@]}" 'any'; do - svnrepo_from="${WORKDIR}/svn/${pkgbase}/repos/${repo_from}-${pkgarch}" - svnrepo_to="${WORKDIR}/svn/${pkgbase}/repos/${repo_to}-${pkgarch}" + vcsrepo_from=$(find_repo_for_package "${pkgbase}" "${pkgarch}" "${repo_from}") - if [[ -f ${svnrepo_from}/PKGBUILD ]]; then + if [[ ${vcsrepo_from} = ${repo_from}-${pkgarch} ]]; then if [[ ${pkgarch} = any ]]; then tarches=("${ARCHES[@]}") else @@ -77,19 +74,7 @@ for pkgbase in "${args[@]:2}"; do get_full_version; echo "${pkgname[@]}") read -ra pkgnames <<<"$pkgnames" - if [[ -d ${svnrepo_to} ]]; then - for file in $(arch_svn ls "${svnrepo_to}"); do - arch_svn rm -q "${svnrepo_to}/$file@" - done - else - mkdir "${svnrepo_to}" - arch_svn add -q "${svnrepo_to}" - fi - - for file in $(arch_svn ls "${svnrepo_from}"); do - arch_svn mv -q -r HEAD "${svnrepo_from}/$file@" "${svnrepo_to}/" - done - arch_svn rm --force -q "${svnrepo_from}" + vcs_move_package "${pkgbase}" "${repo_from}-${pkgarch}" "${repo_to}-${pkgarch}" tag_list+=", $pkgarch" for tarch in "${tarches[@]}"; do @@ -110,7 +95,7 @@ for pkgbase in "${args[@]:2}"; do fi done tag_list="${tag_list#, }" - arch_svn commit -q "${WORKDIR}/svn/${pkgbase}" -m "${0##*/}: moved ${pkgbase} from [${repo_from}] to [${repo_to}] (${tag_list})" + vcs_commit "${0##*/}: moved ${pkgbase} from [${repo_from}] to [${repo_to}] (${tag_list})" done for tarch in "${ARCHES[@]}"; do diff --git a/db-remove b/db-remove index b0a49cf8..a27a9f29 100755 --- a/db-remove +++ b/db-remove @@ -34,9 +34,8 @@ for pkgbase in "${pkgbases[@]}"; do msg "Removing %s from [%s]..." "$pkgbase" "$repo" if remove_pkgs+=($(source_pkgbuild "${pkgbase}" "repos/${vcsrepo}" && echo ${pkgname[@]})); then - arch_svn checkout -q "${SVNREPO}/${pkgbase}" "${WORKDIR}/svn/${pkgbase}" >/dev/null - arch_svn rm --force -q "${WORKDIR}/svn/$pkgbase/repos/$vcsrepo" - arch_svn commit -q "${WORKDIR}/svn/$pkgbase" -m "${0##*/}: $pkgbase removed by $(id -un)" + vcs_remove_package "${pkgbase}" "${vcsrepo}" + vcs_commit "${0##*/}: $pkgbase removed by $(id -un)" else warning "%s not found in %s" "$pkgbase" "$vcsrepo" warning "Removing only %s from the repo" "$pkgbase" -- 2.19.1