common: simplify logic to find git

From chroot-git 2.33.1, we always have an executable named git
for other build infrastructure and lints.

Let's remove the shenanegan to find which git to be used, prepend the
path to chroot-git's git into $PATH, and let's the shell call the
correct git for us instead.
This commit is contained in:
Đoàn Trần Công Danh 2022-09-16 08:50:39 +07:00 committed by Đoàn Trần Công Danh
parent 77db514078
commit 7510b96218
5 changed files with 20 additions and 34 deletions

View file

@ -33,13 +33,9 @@ jobs:
common/travis/prepare.sh common/travis/prepare.sh
- name: Find cycles and open issues - name: Find cycles and open issues
run: | run: |
if command -v chroot-git >/dev/null 2>&1; then PATH="/usr/libexec/chroot-git:$PATH"
GIT_CMD=$(command -v chroot-git)
elif command -v git >/dev/null 2>&1; then
GIT_CMD=$(command -v git)
fi
# required by git 2.35.2+ # required by git 2.35.2+
$GIT_CMD config --global --add safe.directory "$PWD" git config --global --add safe.directory "$PWD"
common/scripts/xbps-cycles.py | tee cycles common/scripts/xbps-cycles.py | tee cycles
grep 'Cycle:' cycles | while read -r line; do grep 'Cycle:' cycles | while read -r line; do
if gh issue list -R "$GITHUB_REPOSITORY" -S "$line" | grep .; then if gh issue list -R "$GITHUB_REPOSITORY" -S "$line" | grep .; then

View file

@ -5,18 +5,18 @@ die() {
exit 1 exit 1
} }
GIT_CMD=$(command -v chroot-git 2>/dev/null) || PATH="/usr/libexec/chroot-git:$PATH"
GIT_CMD=$(command -v git 2>/dev/null) || command -v git >/dev/null 2>&1 ||
die "neither chroot-git nor git could be found!" die "neither chroot-git nor git could be found!"
rev_parse() { rev_parse() {
if [ -n "$1" ]; then if [ -n "$1" ]; then
"$GIT_CMD" rev-parse --verify "$1" git rev-parse --verify "$1"
else else
shift shift
while test "$#" != 0 while test "$#" != 0
do do
"$GIT_CMD" rev-parse --verify "$1" 2>/dev/null && return git rev-parse --verify "$1" 2>/dev/null && return
shift shift
done done
return 1 return 1
@ -27,9 +27,9 @@ base=$(rev_parse "$1" FETCH_HEAD ORIG_HEAD) || die "base commit not found"
tip=$(rev_parse "$2" HEAD) || die "tip commit not found" tip=$(rev_parse "$2" HEAD) || die "tip commit not found"
status=0 status=0
for cmt in $("$GIT_CMD" rev-list --abbrev-commit $base..$tip) for cmt in $(git rev-list --abbrev-commit $base..$tip)
do do
"$GIT_CMD" cat-file commit "$cmt" | git cat-file commit "$cmt" |
awk -vC="$cmt" ' awk -vC="$cmt" '
# skip header # skip header
/^$/ && !msg { msg = 1; next } /^$/ && !msg { msg = 1; next }

View file

@ -13,20 +13,18 @@ if ! [ "$base_rev" ]; then
die "usage: $0 TEMPLATE BASE-REVISION [TIP-REVISION]" die "usage: $0 TEMPLATE BASE-REVISION [TIP-REVISION]"
fi fi
if command -v chroot-git >/dev/null 2>&1; then PATH="/usr/libexec/chroot-git:$PATH"
GIT_CMD=$(command -v chroot-git) if ! command -v git >/dev/null 2>&1; then
elif command -v git >/dev/null 2>&1; then
GIT_CMD=$(command -v git)
else
die "neither chroot-git nor git could be found" die "neither chroot-git nor git could be found"
fi fi
scan() { scan() {
rx="$1" msg="$2" rx="$1" msg="$2"
template_path=$template template_path=$template
maybe_git=
if [ "$tip_rev" ]; then if [ "$tip_rev" ]; then
template_path="${tip_rev}:${template}" template_path="${tip_rev}:${template}"
maybe_git="$GIT_CMD" maybe_git="git"
revspec="[^:]*:" revspec="[^:]*:"
fi fi
$maybe_git grep -P -Hn -e "$rx" "$template_path" | $maybe_git grep -P -Hn -e "$rx" "$template_path" |
@ -37,7 +35,7 @@ scan() {
show_template() { show_template() {
rev="$1" rev="$1"
if [ "$rev" ]; then if [ "$rev" ]; then
$GIT_CMD cat-file blob "${rev}:${template}" 2>/dev/null git cat-file blob "${rev}:${template}" 2>/dev/null
else else
cat "${template}" 2>/dev/null cat "${template}" 2>/dev/null
fi fi

View file

@ -2,19 +2,15 @@
# #
# changed_templates.sh # changed_templates.sh
if command -v chroot-git >/dev/null 2>&1; then PATH="/usr/libexec/chroot-git:$PATH"
GIT_CMD=$(command -v chroot-git)
elif command -v git >/dev/null 2>&1; then
GIT_CMD=$(command -v git)
fi
tip="$($GIT_CMD rev-list -1 --parents HEAD)" tip="$(git rev-list -1 --parents HEAD)"
case "$tip" in case "$tip" in
*" "*" "*) tip="${tip##* }" ;; *" "*" "*) tip="${tip##* }" ;;
*) tip="${tip%% *}" ;; *) tip="${tip%% *}" ;;
esac esac
base="$($GIT_CMD merge-base FETCH_HEAD "$tip")" || { base="$(git merge-base FETCH_HEAD "$tip")" || {
echo "Your branches is based on too old copy." echo "Your branches is based on too old copy."
echo "Please rebase to newest copy." echo "Please rebase to newest copy."
exit 1 exit 1
@ -23,7 +19,7 @@ base="$($GIT_CMD merge-base FETCH_HEAD "$tip")" || {
echo "$base $tip" >/tmp/revisions echo "$base $tip" >/tmp/revisions
/bin/echo -e '\x1b[32mChanged packages:\x1b[0m' /bin/echo -e '\x1b[32mChanged packages:\x1b[0m'
$GIT_CMD diff-tree -r --no-renames --name-only --diff-filter=AM \ git diff-tree -r --no-renames --name-only --diff-filter=AM \
"$base" "$tip" \ "$base" "$tip" \
-- 'srcpkgs/*/template' | -- 'srcpkgs/*/template' |
cut -d/ -f 2 | cut -d/ -f 2 |

View file

@ -2,14 +2,10 @@
# #
# changed_templates.sh # changed_templates.sh
if command -v chroot-git >/dev/null 2>&1; then PATH="/usr/libexec/chroot-git:$PATH"
GIT_CMD=$(command -v chroot-git)
elif command -v git >/dev/null 2>&1; then
GIT_CMD=$(command -v git)
fi
# required by git 2.35.2+ # required by git 2.35.2+
$GIT_CMD config --global --add safe.directory "$PWD" git config --global --add safe.directory "$PWD"
/bin/echo -e '\x1b[32mFetching upstream...\x1b[0m' /bin/echo -e '\x1b[32mFetching upstream...\x1b[0m'
$GIT_CMD fetch --depth 200 https://github.com/void-linux/void-packages.git master git fetch --depth 200 https://github.com/void-linux/void-packages.git master