git-repack.shon commit transport.c: squelch a gcc 4.0.1 complaint about an uninitialized variable (47ec794)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Linus Torvalds
   4#
   5
   6USAGE='[-a|-A] [-d] [-f] [-l] [-n] [-q] [--max-pack-size=N] [--window=N] [--window-memory=N] [--depth=N]'
   7SUBDIRECTORY_OK='Yes'
   8. git-sh-setup
   9
  10no_update_info= all_into_one= remove_redundant= keep_unreachable=
  11local= quiet= no_reuse= extra=
  12while test $# != 0
  13do
  14        case "$1" in
  15        -n)     no_update_info=t ;;
  16        -a)     all_into_one=t ;;
  17        -A)     all_into_one=t
  18                keep_unreachable=--keep-unreachable ;;
  19        -d)     remove_redundant=t ;;
  20        -q)     quiet=-q ;;
  21        -f)     no_reuse=--no-reuse-object ;;
  22        -l)     local=--local ;;
  23        --max-pack-size=*) extra="$extra $1" ;;
  24        --window=*) extra="$extra $1" ;;
  25        --window-memory=*) extra="$extra $1" ;;
  26        --depth=*) extra="$extra $1" ;;
  27        *)      usage ;;
  28        esac
  29        shift
  30done
  31
  32# Later we will default repack.UseDeltaBaseOffset to true
  33default_dbo=false
  34
  35case "`git config --bool repack.usedeltabaseoffset ||
  36       echo $default_dbo`" in
  37true)
  38        extra="$extra --delta-base-offset" ;;
  39esac
  40
  41PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
  42PACKTMP="$GIT_OBJECT_DIRECTORY/.tmp-$$-pack"
  43rm -f "$PACKTMP"-*
  44trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
  45
  46# There will be more repacking strategies to come...
  47case ",$all_into_one," in
  48,,)
  49        args='--unpacked --incremental'
  50        ;;
  51,t,)
  52        if [ -d "$PACKDIR" ]; then
  53                for e in `cd "$PACKDIR" && find . -type f -name '*.pack' \
  54                        | sed -e 's/^\.\///' -e 's/\.pack$//'`
  55                do
  56                        if [ -e "$PACKDIR/$e.keep" ]; then
  57                                : keep
  58                        else
  59                                args="$args --unpacked=$e.pack"
  60                                existing="$existing $e"
  61                        fi
  62                done
  63        fi
  64        if test -z "$args"
  65        then
  66                args='--unpacked --incremental'
  67        elif test -n "$keep_unreachable"
  68        then
  69                args="$args $keep_unreachable"
  70        fi
  71        ;;
  72esac
  73
  74args="$args $local $quiet $no_reuse$extra"
  75names=$(git pack-objects --non-empty --all --reflog $args </dev/null "$PACKTMP") ||
  76        exit 1
  77if [ -z "$names" ]; then
  78        if test -z "$quiet"; then
  79                echo Nothing new to pack.
  80        fi
  81fi
  82for name in $names ; do
  83        fullbases="$fullbases pack-$name"
  84        chmod a-w "$PACKTMP-$name.pack"
  85        chmod a-w "$PACKTMP-$name.idx"
  86        if test "$quiet" != '-q'; then
  87            echo "Pack pack-$name created."
  88        fi
  89        mkdir -p "$PACKDIR" || exit
  90
  91        for sfx in pack idx
  92        do
  93                if test -f "$PACKDIR/pack-$name.$sfx"
  94                then
  95                        mv -f "$PACKDIR/pack-$name.$sfx" \
  96                                "$PACKDIR/old-pack-$name.$sfx"
  97                fi
  98        done &&
  99        mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
 100        mv -f "$PACKTMP-$name.idx"  "$PACKDIR/pack-$name.idx" &&
 101        test -f "$PACKDIR/pack-$name.pack" &&
 102        test -f "$PACKDIR/pack-$name.idx" || {
 103                echo >&2 "Couldn't replace the existing pack with updated one."
 104                echo >&2 "The original set of packs have been saved as"
 105                echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
 106                exit 1
 107        }
 108        rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
 109done
 110
 111if test "$remove_redundant" = t
 112then
 113        # We know $existing are all redundant.
 114        if [ -n "$existing" ]
 115        then
 116                sync
 117                ( cd "$PACKDIR" &&
 118                  for e in $existing
 119                  do
 120                        case " $fullbases " in
 121                        *" $e "*) ;;
 122                        *)      rm -f "$e.pack" "$e.idx" "$e.keep" ;;
 123                        esac
 124                  done
 125                )
 126        fi
 127        git prune-packed $quiet
 128fi
 129
 130case "$no_update_info" in
 131t) : ;;
 132*) git-update-server-info ;;
 133esac