git-repack.shon commit Merge branch 'master' (3acfbd7)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Linus Torvalds
   4#
   5
   6USAGE='[-a] [-d] [-l] [-n]'
   7. git-sh-setup
   8        
   9no_update_info= all_into_one= remove_redundant= local=
  10while case "$#" in 0) break ;; esac
  11do
  12        case "$1" in
  13        -n)     no_update_info=t ;;
  14        -a)     all_into_one=t ;;
  15        -d)     remove_redundant=t ;;
  16        -l)     local=t ;;
  17        *)      usage ;;
  18        esac
  19        shift
  20done
  21
  22rm -f .tmp-pack-*
  23PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
  24
  25# There will be more repacking strategies to come...
  26case ",$all_into_one," in
  27,,)
  28        rev_list='--unpacked'
  29        rev_parse='--all'
  30        pack_objects='--incremental'
  31        ;;
  32,t,)
  33        rev_list=
  34        rev_parse='--all'
  35        pack_objects=
  36
  37        # Redundancy check in all-into-one case is trivial.
  38        existing=`cd "$PACKDIR" && \
  39            find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
  40        ;;
  41esac
  42if [ "$local" ]; then
  43        pack_objects="$pack_objects --local"
  44fi
  45name=$(git-rev-list --objects $rev_list $(git-rev-parse $rev_parse) 2>&1 |
  46        git-pack-objects --non-empty $pack_objects .tmp-pack) ||
  47        exit 1
  48if [ -z "$name" ]; then
  49        echo Nothing new to pack.
  50        exit 0
  51fi
  52echo "Pack pack-$name created."
  53
  54mkdir -p "$PACKDIR" || exit
  55
  56mv .tmp-pack-$name.pack "$PACKDIR/pack-$name.pack" &&
  57mv .tmp-pack-$name.idx  "$PACKDIR/pack-$name.idx" ||
  58exit
  59
  60if test "$remove_redundant" = t
  61then
  62        # We know $existing are all redundant only when
  63        # all-into-one is used.
  64        if test "$all_into_one" != '' && test "$existing" != ''
  65        then
  66                sync
  67                ( cd "$PACKDIR" &&
  68                  for e in $existing
  69                  do
  70                        case "$e" in
  71                        ./pack-$name.pack | ./pack-$name.idx) ;;
  72                        *)      rm -f $e ;;
  73                        esac
  74                  done
  75                )
  76        fi
  77fi
  78
  79case "$no_update_info" in
  80t) : ;;
  81*) git-update-server-info ;;
  82esac