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

xlocate: allow chroot-git #237

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 16 additions & 7 deletions xlocate
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ fi
: ${XLOCATE_GIT:=$XDG_CACHE_HOME/xlocate.git}
: ${XLOCATE_REPO:=https://alpha.de.repo.voidlinux.org/xlocate/xlocate.git}

if command -v git >/dev/null 2>&1; then
GIT_CMD=$(command -v git)
elif command -v chroot-git >/dev/null 2>&1; then
GIT_CMD=$(command -v chroot-git)
else
echo "xlocate: git command not found." 1>&2
exit 1
fi

if command -v pv >/dev/null; then
PROGRESS="pv -l"
else
Expand All @@ -22,7 +31,7 @@ xupdategit() {
set -e
DIR=$(mktemp -dt xlocate.XXXXXX)
DIR=$(/usr/bin/realpath -e "$DIR")
git init -q $DIR
$GIT_CMD init -q $DIR
cd $DIR
xbps-query -M -Ro '*' | $PROGRESS | awk '
$0 ~ ": " {
Expand All @@ -35,9 +44,9 @@ xupdategit() {
printf '%s\n' ./* |
LC_ALL= xargs -d'\n' -I'{}' -n1 -P "$(nproc)" -r -- \
sort -o {} {}
git add ./*
git -c user.name=xupdategit -c user.email=xupdategit@none commit -q -m 'xupdategit'
git repack -ad
$GIT_CMD add ./*
$GIT_CMD -c user.name=xupdategit -c user.email=xupdategit@none commit -q -m 'xupdategit'
$GIT_CMD repack -ad
rm -rf "$XLOCATE_GIT" .git/COMMIT_EDITMSG .git/description \
.git/index .git/hooks .git/logs
[ -n "${XLOCATE_GIT%/*}" ] && mkdir -p "${XLOCATE_GIT%/*}"
Expand All @@ -48,9 +57,9 @@ xupdategit() {
xsyncgit() {
if ! [ -d "$XLOCATE_GIT" ]; then
[ -n "${XLOCATE_GIT%/*}" ] && mkdir -p "${XLOCATE_GIT%/*}"
git clone --bare "$XLOCATE_REPO" "$XLOCATE_GIT"
$GIT_CMD clone --bare "$XLOCATE_REPO" "$XLOCATE_GIT"
fi
git -C "$XLOCATE_GIT" fetch -u -f "$XLOCATE_REPO" master:master
$GIT_CMD -C "$XLOCATE_GIT" fetch -u -f "$XLOCATE_REPO" master:master
}

case "$1" in
Expand Down Expand Up @@ -78,7 +87,7 @@ if [ -d "$XLOCATE_GIT" ]; then
echo "xlocate: database outdated, please run xlocate -g." 1>&2
fi
fi
git -c grep.lineNumber=false --git-dir="$XLOCATE_GIT" grep -- "$@" @ |
$GIT_CMD -c grep.lineNumber=false --git-dir="$XLOCATE_GIT" grep -- "$@" @ |
sed 's/^@://; s/:/\t/' | grep .
else
echo "xlocate: database not found, please use xlocate -S." 1>&2
Expand Down