From c2a3578a55b84cb685f3a394580b776ddfa963dd Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Sun, 21 Jul 2024 21:28:46 -0300 Subject: [PATCH] Replace utils/gitexec with utils/git/run --- libexec/portzap/commands/portzap-clone | 12 ++++------- libexec/portzap/commands/portzap-install | 9 +++++---- libexec/portzap/commands/portzap-pull | 10 +++------- libexec/portzap/utils/git-changed-files | 22 --------------------- libexec/portzap/utils/git-removed-files | 21 -------------------- libexec/portzap/utils/git-rev | 20 ------------------- libexec/portzap/utils/git/get-changed-files | 16 +++++++++++++++ libexec/portzap/utils/git/get-removed-files | 15 ++++++++++++++ libexec/portzap/utils/{git => git/run} | 2 +- libexec/portzap/utils/gitdiff | 11 ----------- share/portzap/RELNOTES | 6 ++++++ 11 files changed, 50 insertions(+), 94 deletions(-) delete mode 100644 libexec/portzap/utils/git-changed-files delete mode 100644 libexec/portzap/utils/git-removed-files delete mode 100644 libexec/portzap/utils/git-rev create mode 100644 libexec/portzap/utils/git/get-changed-files create mode 100644 libexec/portzap/utils/git/get-removed-files rename libexec/portzap/utils/{git => git/run} (70%) delete mode 100644 libexec/portzap/utils/gitdiff diff --git a/libexec/portzap/commands/portzap-clone b/libexec/portzap/commands/portzap-clone index 5ec255e..79776f5 100755 --- a/libexec/portzap/commands/portzap-clone +++ b/libexec/portzap/commands/portzap-clone @@ -5,17 +5,13 @@ set -e # variables localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)} libexec="${localbase}"/libexec/portzap +git="${libexec}"/utils/git/run giturl=$1 gitdir=$2 branch=$3 ## # functions -git() -{ - "${libexec}"/utils/gitexec "${1}" -} - printok() { "${libexec}"/utils/printok "${1}" } @@ -41,8 +37,8 @@ if [ -e "${gitdir}/.git" ]; then exit 1 fi -git clone "${giturl}" "${gitdir}" +"${git}" clone "${giturl}" "${gitdir}" cd "${gitdir}" -git config core.filemode off -git checkout -t origin/"${branch}" +"${git}" config core.filemode off +"${git}" checkout -t origin/"${branch}" printok "clone complete" diff --git a/libexec/portzap/commands/portzap-install b/libexec/portzap/commands/portzap-install index 2160c79..4963858 100755 --- a/libexec/portzap/commands/portzap-install +++ b/libexec/portzap/commands/portzap-install @@ -6,6 +6,7 @@ set -e localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)} libexec="${localbase}"/libexec/portzap mode=u=rwX,g=rX,o= +git="${libexec}"/utils/git/run gitdir=$1 installdir=$2 revfile=$3 @@ -15,8 +16,8 @@ revfile=$3 perform_update() { rev=$(cat "${revfile}") - add=$("${libexec}"/utils/git-changed-files "${gitdir}" "${rev}") - del=$("${libexec}"/utils/git-removed-files "${gitdir}" "${rev}") + add=$("${libexec}"/utils/git/get-changed-files "${gitdir}" "${rev}") + del=$("${libexec}"/utils/git/get-removed-files "${gitdir}" "${rev}") for file in ${del}; do target="${installdir}/${file}" parent=$(dirname "${target}") @@ -72,7 +73,7 @@ if [ "$(id -u)" != "0" ]; then exit 1 fi -umask ${mode} +umask "${mode}" cd "${gitdir}" run_install "-d" "${installdir}" chmod ${mode} "${installdir}" @@ -81,5 +82,5 @@ if [ -e "${revfile}" ]; then else perform_install fi -"${libexec}"/utils/git-rev "${gitdir}" > "${revfile}" +"${git}" rev-parse HEAD > "${revfile}" printok "install complete" diff --git a/libexec/portzap/commands/portzap-pull b/libexec/portzap/commands/portzap-pull index 9bd7786..27b4c1a 100755 --- a/libexec/portzap/commands/portzap-pull +++ b/libexec/portzap/commands/portzap-pull @@ -5,15 +5,11 @@ set -e # variables localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)} libexec="${localbase}"/libexec/portzap +git="${libexec}"/utils/git/run gitdir=$1 ## # functions -git() -{ - "${libexec}"/utils/git "${@}" -} - printok() { "${libexec}"/utils/printok "${1}" } @@ -40,6 +36,6 @@ if [ ! -e "${gitdir}/.git" ]; then fi cd "${gitdir}" -branch=$(gitexec "branch --show-current") -gitexec "pull --rebase origin ${branch}" +branch=$("${git}" branch --show-current) +"${git}" pull --rebase origin "${branch}" printok "pull complete" diff --git a/libexec/portzap/utils/git-changed-files b/libexec/portzap/utils/git-changed-files deleted file mode 100644 index 8d1fcf7..0000000 --- a/libexec/portzap/utils/git-changed-files +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh -set -e - -## -# variables -localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)} -libexec="${localbase}"/libexec/portzap -gitdir=$1 -commit=$2 - -## -# functions -diff() -{ - "${libexec}"/utils/gitdiff ${@} -} - -## -# main -cd "${gitdir}" -diff "--name-only" "--diff-filter=A" "${commit}" "HEAD" -diff "--name-only" "--diff-filter=M" "${commit}" "HEAD" diff --git a/libexec/portzap/utils/git-removed-files b/libexec/portzap/utils/git-removed-files deleted file mode 100644 index 158f73b..0000000 --- a/libexec/portzap/utils/git-removed-files +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh -set -e - -## -# variables -localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)} -libexec="${localbase}"/libexec/portzap -gitdir=$1 -commit=$2 - -## -# functions -diff() -{ - "${libexec}"/utils/gitdiff ${@} -} - -## -# main -cd "${gitdir}" -diff "--name-only" "--diff-filter=D" "${commit}" "HEAD" diff --git a/libexec/portzap/utils/git-rev b/libexec/portzap/utils/git-rev deleted file mode 100644 index 045e4bd..0000000 --- a/libexec/portzap/utils/git-rev +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh -set -e - -## -# variables -localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)} -libexec="${localbase}"/libexec/portzap -gitdir=$1 - -## -# functions -gitexec() -{ - "${libexec}"/utils/gitexec "${1}" -} - -## -# main -cd "${gitdir}" -gitexec "rev-parse HEAD" diff --git a/libexec/portzap/utils/git/get-changed-files b/libexec/portzap/utils/git/get-changed-files new file mode 100644 index 0000000..7c64d41 --- /dev/null +++ b/libexec/portzap/utils/git/get-changed-files @@ -0,0 +1,16 @@ +#!/bin/sh +set -e + +## +# variables +localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../../..)} +libexec="${localbase}"/libexec/portzap +git="${libexec}"/utils/git/run +gitdir=$1 +commit=$2 + +## +# main +cd "${gitdir}" +"${git}" diff -l0 --name-only --diff-filter=A "${commit}" "HEAD" +"${git}" diff -l0 --name-only --diff-filter=M "${commit}" "HEAD" diff --git a/libexec/portzap/utils/git/get-removed-files b/libexec/portzap/utils/git/get-removed-files new file mode 100644 index 0000000..4ad32dc --- /dev/null +++ b/libexec/portzap/utils/git/get-removed-files @@ -0,0 +1,15 @@ +#!/bin/sh +set -e + +## +# variables +localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../../..)} +libexec="${localbase}"/libexec/portzap +git="${libexec}"/utils/git/run +gitdir=$1 +commit=$2 + +## +# main +cd "${gitdir}" +"${git}" diff -l0 --name-only --diff-filter=D "${commit}" "HEAD" diff --git a/libexec/portzap/utils/git b/libexec/portzap/utils/git/run similarity index 70% rename from libexec/portzap/utils/git rename to libexec/portzap/utils/git/run index decaea3..92da168 100644 --- a/libexec/portzap/utils/git +++ b/libexec/portzap/utils/git/run @@ -10,4 +10,4 @@ mode=u=rwX,g=rX,o= # main doas -n \ -u _portzap \ - /bin/sh -c "umask ${mode}; ${git} ${1}" + /bin/sh -c "umask ${mode}; ${git} ${*}" diff --git a/libexec/portzap/utils/gitdiff b/libexec/portzap/utils/gitdiff deleted file mode 100644 index afb2a29..0000000 --- a/libexec/portzap/utils/gitdiff +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -set -e - -## -# variables -localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)} -libexec="${localbase}"/libexec/portzap - -## -# main -"${libexec}"/utils/gitexec diff -l0 ${@} diff --git a/share/portzap/RELNOTES b/share/portzap/RELNOTES index e4b1a0e..e1acade 100644 --- a/share/portzap/RELNOTES +++ b/share/portzap/RELNOTES @@ -1,4 +1,10 @@ v?.?.? +| Replace utils/gitexec with utils/git/run + After this change, we talk to git via utils/git/run + +| Add utils/git + A dedicated directory for git-related scripts + | Remove "set -x" After this change, portzap emits less output