git-prune-scripton commit [PATCH 2/4] split core-git.txt and update (204ee6a)
   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: ${GIT_DIR=.git}
  15: ${GIT_OBJECT_DIRECTORY="${SHA1_FILE_DIRECTORY-"$GIT_DIR/objects"}"}
  16
  17# Defaulting to include .git/refs/*/* may be debatable from the
  18# purist POV but power users can always give explicit parameters
  19# to the script anyway.
  20
  21case "$#" in
  220)
  23    x_40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
  24    x_40="$x_40$x_40$x_40$x_40$x_40$x_40$x_40$x_40"
  25    set x $(sed -ne "/^$x_40\$/p" \
  26        "$GIT_DIR"/HEAD "$GIT_DIR"/refs/*/* /dev/null 2>/dev/null)
  27    shift ;;
  28esac
  29
  30git-fsck-cache --cache --unreachable "$@" |
  31sed -ne '/unreachable /{
  32    s/unreachable [^ ][^ ]* //
  33    s|\(..\)|\1/|p
  34}' | {
  35        cd "$GIT_OBJECT_DIRECTORY" || exit
  36        xargs -r $dryrun rm -f
  37}
  38