2024-01-20 13:36:30 +03:00
|
|
|
#!/bin/zsh
|
|
|
|
|
|
|
|
git-dir-usage() {
|
2024-02-12 12:07:41 +03:00
|
|
|
local gitdir x topdir
|
|
|
|
gitdir=$(__z_git rev-parse --git-dir) || return $?
|
|
|
|
x=$(__z_git rev-parse --path-format=absolute 2>/dev/null) || return $?
|
2024-01-20 13:36:30 +03:00
|
|
|
if [ -n "$x" ] ; then
|
|
|
|
## older git version which does not support "--path-format=absolute"
|
2024-02-12 12:07:41 +03:00
|
|
|
: TODO
|
2024-01-20 13:36:30 +03:00
|
|
|
else
|
2024-02-12 12:07:41 +03:00
|
|
|
gitdir=$(__z_git rev-parse --path-format=absolute --git-dir) || return $?
|
2024-01-20 13:36:30 +03:00
|
|
|
fi
|
2024-01-27 00:10:58 +03:00
|
|
|
|
2024-02-12 12:07:41 +03:00
|
|
|
case "${gitdir}" in
|
|
|
|
*/* ) topdir=${gitdir:h} ; gitdir=${gitdir:t} ;;
|
2024-01-20 13:36:30 +03:00
|
|
|
esac
|
2024-01-27 00:10:58 +03:00
|
|
|
|
2024-02-12 12:07:41 +03:00
|
|
|
local -a subdirs
|
|
|
|
subdirs+="${gitdir}/logs/refs"
|
|
|
|
subdirs+="${gitdir}/objects/info"
|
|
|
|
subdirs+="${gitdir}/objects/pack"
|
|
|
|
|
|
|
|
if [ -n "${topdir}" ] ; then
|
|
|
|
env -C "${topdir}" du -d1 "${gitdir}"
|
|
|
|
env -C "${topdir}" du -d1 "${subdirs[@]}"
|
2024-01-20 13:36:30 +03:00
|
|
|
else
|
2024-02-12 12:07:41 +03:00
|
|
|
du -d1 "${gitdir}"
|
|
|
|
du -d1 "${subdirs[@]}"
|
2024-01-20 13:36:30 +03:00
|
|
|
fi | grep -Ev '^[0-9]\s' | sort -Vk2
|
|
|
|
}
|
|
|
|
|
|
|
|
git-gc() {
|
|
|
|
git-dir-usage || return $?
|
|
|
|
echo
|
|
|
|
idle git gc "$@"
|
|
|
|
echo
|
|
|
|
git-dir-usage
|
|
|
|
}
|
|
|
|
|
|
|
|
git-gc-force() {
|
|
|
|
git-gc --aggressive --force
|
2024-02-12 12:07:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
git-archive-ref() {
|
|
|
|
local name ver gitref topdir c_hash c_time out
|
|
|
|
name="${1:?}" ver="${2:?}" gitref="${3:?}"
|
|
|
|
topdir=$(__z_git rev-parse --show-toplevel) || return $?
|
|
|
|
c_hash=$(__z_git log -n 1 --format='%h' --abbrev=8 "${gitref}") || return $?
|
|
|
|
c_time=$(__z_git log -n 1 --format='%cd' --date='format:%Y%m%d.%H%M%S' "${gitref}") || return $?
|
|
|
|
out="${name}_${ver}+git.${c_time}.${c_hash}.tar"
|
|
|
|
topdir=${topdir:h}
|
|
|
|
git archive --format=tar -o "${topdir}/${out}" --prefix="${name}-${ver}-git.${c_hash}/" "${gitref}" || return $?
|
|
|
|
echo "archived to ${out} in ${topdir}/" >&2
|
2024-01-20 13:36:30 +03:00
|
|
|
}
|