git-prune-scripton commit Merge of http://members.cox.net/junkio/git-jc.git (74c7cfa)
   1#!/bin/sh
   2dryrun=
   3while case "$#" in 0) break ;; esac
   4do
   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;
  12done
  13
  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.
  17
  18case "$#" in
  190)
  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 ;;
  24esac
  25
  26git-fsck-cache --cache --unreachable "$@" |
  27sed -ne '/unreachable /{
  28    s/unreachable [^ ][^ ]* //
  29    s|\(..\)|\1/|p
  30}' | {
  31        case "$SHA1_FILE_DIRECTORY" in
  32        '') cd .git/objects/ ;;
  33        *) cd "$SHA1_FILE_DIRECTORY" ;;
  34        esac || exit
  35        xargs -r $dryrun rm -f
  36}