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