git-repack.shon commit daemon: do not die on older clients. (83543a2)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Linus Torvalds
   4#
   5
   6USAGE='[-a] [-d] [-f] [-l] [-n] [-q]'
   7SUBDIRECTORY_OK='Yes'
   8. git-sh-setup
   9
  10no_update_info= all_into_one= remove_redundant=
  11local= quiet= no_reuse_delta= extra=
  12while case "$#" in 0) break ;; esac
  13do
  14        case "$1" in
  15        -n)     no_update_info=t ;;
  16        -a)     all_into_one=t ;;
  17        -d)     remove_redundant=t ;;
  18        -q)     quiet=-q ;;
  19        -f)     no_reuse_delta=--no-reuse-delta ;;
  20        -l)     local=--local ;;
  21        --window=*) extra="$extra $1" ;;
  22        --depth=*) extra="$extra $1" ;;
  23        *)      usage ;;
  24        esac
  25        shift
  26done
  27
  28PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
  29PACKTMP="$GIT_DIR/.tmp-$$-pack"
  30rm -f "$PACKTMP"-*
  31trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
  32
  33# There will be more repacking strategies to come...
  34case ",$all_into_one," in
  35,,)
  36        args='--unpacked --incremental'
  37        ;;
  38,t,)
  39        args=
  40
  41        # Redundancy check in all-into-one case is trivial.
  42        existing=`test -d "$PACKDIR" && cd "$PACKDIR" && \
  43            find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
  44        ;;
  45esac
  46
  47args="$args $local $quiet $no_reuse_delta$extra"
  48name=$(git-pack-objects --non-empty --all $args </dev/null "$PACKTMP") ||
  49        exit 1
  50if [ -z "$name" ]; then
  51        echo Nothing new to pack.
  52else
  53        if test "$quiet" != '-q'; then
  54            echo "Pack pack-$name created."
  55        fi
  56        mkdir -p "$PACKDIR" || exit
  57
  58        for sfx in pack idx
  59        do
  60                if test -f "$PACKDIR/pack-$name.$sfx"
  61                then
  62                        mv -f "$PACKDIR/pack-$name.$sfx" \
  63                                "$PACKDIR/old-pack-$name.$sfx"
  64                fi
  65        done &&
  66        mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
  67        mv -f "$PACKTMP-$name.idx"  "$PACKDIR/pack-$name.idx" &&
  68        test -f "$PACKDIR/pack-$name.pack" &&
  69        test -f "$PACKDIR/pack-$name.idx" || {
  70                echo >&2 "Couldn't replace the existing pack with updated one."
  71                echo >&2 "The original set of packs have been saved as"
  72                echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
  73                exit 1
  74        }
  75        rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
  76fi
  77
  78if test "$remove_redundant" = t
  79then
  80        # We know $existing are all redundant only when
  81        # all-into-one is used.
  82        if test "$all_into_one" != '' && test "$existing" != ''
  83        then
  84                sync
  85                ( cd "$PACKDIR" &&
  86                  for e in $existing
  87                  do
  88                        case "$e" in
  89                        ./pack-$name.pack | ./pack-$name.idx) ;;
  90                        *)      rm -f $e ;;
  91                        esac
  92                  done
  93                )
  94        fi
  95        git-prune-packed
  96fi
  97
  98case "$no_update_info" in
  99t) : ;;
 100*) git-update-server-info ;;
 101esac