Rename environment variables.
[alt-git.git] / git-prune-script
blobc0ffb1dcba3bc59fe5717ca8d89645ce899452b5
1 #!/bin/sh
2 dryrun=
3 while case "$#" in 0) break ;; esac
4 do
5 case "$1" in
6 -n) dryrun=echo ;;
7 --) break ;;
8 -*) echo >&2 "usage: git-prune-script [ -n ] [ heads... ]"; exit 1 ;;
9 *) break ;;
10 esac
11 shift;
12 done
14 # Defaulting to include .git/refs/*/* may be debatable from the
15 # purist POV but power users can always give explicit parameters
16 # to the script anyway.
18 case "$#" in
20 x_40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
21 x_40="$x_40$x_40$x_40$x_40$x_40$x_40$x_40$x_40"
22 set x $(sed -ne "/^$x_40\$/p" .git/HEAD .git/refs/*/* 2>/dev/null)
23 shift ;;
24 esac
26 git-fsck-cache --cache --unreachable "$@" |
27 sed -ne '/unreachable /{
28 s/unreachable [^ ][^ ]* //
29 s|\(..\)|\1/|p
30 }' | {
31 for d in "$GIT_OBJECT_DIRECTORY" "$SHA1_FILE_DIRECTORY" ''
33 test "$d" != "" && test -d "$d" && break
34 done
35 case "$d" in
36 '') cd .git/objects/ ;;
37 *) cd "$d" ;;
38 esac || exit
39 xargs -r $dryrun rm -f