From d33cd6628f7cab15e9426fbba88c8b446c438212 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Fri, 19 Jul 2024 02:42:02 -0300 Subject: [PATCH] Add utils/git directory Group git-related utilities under one directory. The utils/git/run script runs git as the '_sourcezap' user, and it is how we talk to git. --- libexec/sourcezap/commands/sourcezap-checkout | 4 ++-- libexec/sourcezap/commands/sourcezap-clone | 2 +- libexec/sourcezap/commands/sourcezap-install | 11 +++++++--- libexec/sourcezap/commands/sourcezap-pull | 2 +- libexec/sourcezap/utils/git-rev | 20 ------------------- .../get-changed-files} | 8 ++++---- .../get-removed-files} | 6 +++--- libexec/sourcezap/utils/{git => git/run} | 0 libexec/sourcezap/utils/gitdiff | 11 ---------- 9 files changed, 19 insertions(+), 45 deletions(-) delete mode 100755 libexec/sourcezap/utils/git-rev rename libexec/sourcezap/utils/{git-changed-files => git/get-changed-files} (55%) rename libexec/sourcezap/utils/{git-removed-files => git/get-removed-files} (66%) rename libexec/sourcezap/utils/{git => git/run} (100%) delete mode 100755 libexec/sourcezap/utils/gitdiff diff --git a/libexec/sourcezap/commands/sourcezap-checkout b/libexec/sourcezap/commands/sourcezap-checkout index 39db0f6..dc6ca76 100755 --- a/libexec/sourcezap/commands/sourcezap-checkout +++ b/libexec/sourcezap/commands/sourcezap-checkout @@ -12,7 +12,7 @@ branch=$2 # functions git() { - "${libexec}"/utils/git "${@}" + "${libexec}"/utils/git/run "${@}" } printok() @@ -38,7 +38,7 @@ if ! "${libexec}"/utils/issourcezap-member > /dev/null 2>&1; then fi if [ ! -e "${gitdir}/.git" ]; then - printerr "try 'portzap clone' instead" + printerr "try 'sourcezap clone' instead" exit 1 fi diff --git a/libexec/sourcezap/commands/sourcezap-clone b/libexec/sourcezap/commands/sourcezap-clone index ac68c78..31dfaf8 100755 --- a/libexec/sourcezap/commands/sourcezap-clone +++ b/libexec/sourcezap/commands/sourcezap-clone @@ -13,7 +13,7 @@ branch=$3 # functions git() { - "${libexec}"/utils/git "${@}" + "${libexec}"/utils/git/run "${@}" } printok() diff --git a/libexec/sourcezap/commands/sourcezap-install b/libexec/sourcezap/commands/sourcezap-install index da916a0..735032c 100755 --- a/libexec/sourcezap/commands/sourcezap-install +++ b/libexec/sourcezap/commands/sourcezap-install @@ -15,8 +15,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}") @@ -63,6 +63,11 @@ run_install() install -o root -g _sourcezap -m "${mode}" -v "$@" } +git() +{ + "${libexec}"/utils/git/run "${@}" +} + printok() { "${libexec}"/utils/printok "${1}" @@ -91,5 +96,5 @@ if [ -e "${revfile}" ]; then else perform_install fi -"${libexec}"/utils/git-rev "${gitdir}" > "${revfile}" +"${libexec}"/utils/git/run rev-parse HEAD > "${revfile}" printok "install complete" diff --git a/libexec/sourcezap/commands/sourcezap-pull b/libexec/sourcezap/commands/sourcezap-pull index 84adb47..e40b731 100755 --- a/libexec/sourcezap/commands/sourcezap-pull +++ b/libexec/sourcezap/commands/sourcezap-pull @@ -11,7 +11,7 @@ gitdir=$1 # functions git() { - "${libexec}"/utils/git "${@}" + "${libexec}"/utils/git/run "${@}" } printok() diff --git a/libexec/sourcezap/utils/git-rev b/libexec/sourcezap/utils/git-rev deleted file mode 100755 index db476b1..0000000 --- a/libexec/sourcezap/utils/git-rev +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh -set -e - -## -# variables -localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)} -libexec="${localbase}"/libexec/sourcezap -gitdir=$1 - -## -# functions -git() -{ - "${libexec}"/utils/git "${1}" -} - -## -# main -cd "${gitdir}" -git rev-parse HEAD diff --git a/libexec/sourcezap/utils/git-changed-files b/libexec/sourcezap/utils/git/get-changed-files similarity index 55% rename from libexec/sourcezap/utils/git-changed-files rename to libexec/sourcezap/utils/git/get-changed-files index 4624d3d..ae70856 100755 --- a/libexec/sourcezap/utils/git-changed-files +++ b/libexec/sourcezap/utils/git/get-changed-files @@ -10,13 +10,13 @@ commit=$2 ## # functions -diff() +git() { - "${libexec}"/utils/gitdiff ${@} + "${libexec}"/utils/git/run "${@}" } ## # main cd "${gitdir}" -diff "--name-only" "--diff-filter=A" "${commit}" "HEAD" -diff "--name-only" "--diff-filter=M" "${commit}" "HEAD" +git diff -l0 --name-only --diff-filter=A "${commit}" "HEAD" +git diff -l0 --name-only --diff-filter=M "${commit}" "HEAD" diff --git a/libexec/sourcezap/utils/git-removed-files b/libexec/sourcezap/utils/git/get-removed-files similarity index 66% rename from libexec/sourcezap/utils/git-removed-files rename to libexec/sourcezap/utils/git/get-removed-files index 6531505..4ce4492 100755 --- a/libexec/sourcezap/utils/git-removed-files +++ b/libexec/sourcezap/utils/git/get-removed-files @@ -10,12 +10,12 @@ commit=$2 ## # functions -diff() +git() { - "${libexec}"/utils/gitdiff ${@} + "${libexec}"/utils/git/run "${@}" } ## # main cd "${gitdir}" -diff "--name-only" "--diff-filter=D" "${commit}" "HEAD" +git diff -l0 --name-only --diff-filter=D "${commit}" "HEAD" diff --git a/libexec/sourcezap/utils/git b/libexec/sourcezap/utils/git/run similarity index 100% rename from libexec/sourcezap/utils/git rename to libexec/sourcezap/utils/git/run diff --git a/libexec/sourcezap/utils/gitdiff b/libexec/sourcezap/utils/gitdiff deleted file mode 100755 index b1f0b7b..0000000 --- a/libexec/sourcezap/utils/gitdiff +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -set -e - -## -# variables -localbase=${LOCALBASE:-$(realpath "$(dirname "$0")"/../../..)} -libexec="${localbase}"/libexec/sourcezap - -## -# main -"${libexec}"/utils/git diff -l0 ${@}