git-repack.shon commit Get rid of the dependency on RCS' merge program (e2b7008)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Linus Torvalds
   4#
   5
   6USAGE='[-a] [-d] [-f] [-l] [-n] [-q] [--window=N] [--depth=N]'
   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
  28# Later we will default repack.UseDeltaBaseOffset to true
  29default_dbo=false
  30
  31case "`git repo-config --bool repack.usedeltabaseoffset ||
  32       echo $default_dbo`" in
  33true)
  34        extra="$extra --delta-base-offset" ;;
  35esac
  36
  37PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
  38PACKTMP="$GIT_DIR/.tmp-$$-pack"
  39rm -f "$PACKTMP"-*
  40trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
  41
  42# There will be more repacking strategies to come...
  43case ",$all_into_one," in
  44,,)
  45        args='--unpacked --incremental'
  46        ;;
  47,t,)
  48        if [ -d "$PACKDIR" ]; then
  49                for e in `cd "$PACKDIR" && find . -type f -name '*.pack' \
  50                        | sed -e 's/^\.\///' -e 's/\.pack$//'`
  51                do
  52                        if [ -e "$PACKDIR/$e.keep" ]; then
  53                                : keep
  54                        else
  55                                args="$args --unpacked=$e.pack"
  56                                existing="$existing $e"
  57                        fi
  58                done
  59        fi
  60        [ -z "$args" ] && args='--unpacked --incremental'
  61        ;;
  62esac
  63
  64args="$args $local $quiet $no_reuse_delta$extra"
  65name=$(git-pack-objects --non-empty --all $args </dev/null "$PACKTMP") ||
  66        exit 1
  67if [ -z "$name" ]; then
  68        echo Nothing new to pack.
  69else
  70        if test "$quiet" != '-q'; then
  71            echo "Pack pack-$name created."
  72        fi
  73        mkdir -p "$PACKDIR" || exit
  74
  75        for sfx in pack idx
  76        do
  77                if test -f "$PACKDIR/pack-$name.$sfx"
  78                then
  79                        mv -f "$PACKDIR/pack-$name.$sfx" \
  80                                "$PACKDIR/old-pack-$name.$sfx"
  81                fi
  82        done &&
  83        mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
  84        mv -f "$PACKTMP-$name.idx"  "$PACKDIR/pack-$name.idx" &&
  85        test -f "$PACKDIR/pack-$name.pack" &&
  86        test -f "$PACKDIR/pack-$name.idx" || {
  87                echo >&2 "Couldn't replace the existing pack with updated one."
  88                echo >&2 "The original set of packs have been saved as"
  89                echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
  90                exit 1
  91        }
  92        rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
  93fi
  94
  95if test "$remove_redundant" = t
  96then
  97        # We know $existing are all redundant.
  98        if [ -n "$existing" ]
  99        then
 100                sync
 101                ( cd "$PACKDIR" &&
 102                  for e in $existing
 103                  do
 104                        case "$e" in
 105                        pack-$name) ;;
 106                        *)      rm -f "$e.pack" "$e.idx" "$e.keep" ;;
 107                        esac
 108                  done
 109                )
 110        fi
 111        git-prune-packed
 112fi
 113
 114case "$no_update_info" in
 115t) : ;;
 116*) git-update-server-info ;;
 117esac