1
0
dotfiles/.config/zsh/alias/git.zsh

65 lines
1.8 KiB
Bash
Raw Permalink Normal View History

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
2024-07-23 23:08:35 +03:00
for x ( logs/refs objects/info objects/pack ) ; do
[ -d "${gitdir}/$x" ] || continue
subdirs+="${gitdir}/$x"
done
(
[ -n "${topdir}" ] && cd "${topdir}/"
if [ ${#subdirs} -gt 0 ] ; then
du -d1 "${subdirs[@]}"
fi
2024-02-12 12:07:41 +03:00
du -d1 "${gitdir}"
2024-07-23 23:08:35 +03:00
) | grep -Ev '^[0-9]K?\s' | sort -Vk2
2024-01-20 13:36:30 +03:00
}
git-gc() {
git-dir-usage || return $?
echo
2024-07-23 23:08:35 +03:00
echo "# git gc $*" >&2
z-time idle git gc "$@"
2024-01-20 13:36:30 +03:00
echo
git-dir-usage
}
git-gc-force() {
2024-07-23 23:08:35 +03:00
git-dir-usage || return $?
echo
echo "# git gc --aggressive --force $*" >&2
z-time idle git gc --aggressive --force "$@"
echo
echo "# git repack -Ad" >&2
z-time idle git repack -Ad
echo
git-dir-usage
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-07-05 13:18:16 +03:00
}