3 # Copyright (c) 2005 Linus Torvalds
6 USAGE='[-a] [-d] [-f] [-l] [-n] [-q] [--window=N] [--depth=N]'
10 no_update_info= all_into_one= remove_redundant=
11 local= quiet= no_reuse_delta= extra=
12 while case "$#" in 0) break ;; esac
15 -n) no_update_info=t ;;
17 -d) remove_redundant=t ;;
19 -f) no_reuse_delta=--no-reuse-delta ;;
21 --window=*) extra="$extra $1" ;;
22 --depth=*) extra="$extra $1" ;;
28 # Later we will default repack.UseDeltaBaseOffset to true
31 case "`git repo-config --bool repack.usedeltabaseoffset ||
32 echo $default_dbo`" in
34 extra="$extra --delta-base-offset" ;;
37 PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
38 PACKTMP="$GIT_DIR/.tmp-$$-pack"
40 trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
42 # There will be more repacking strategies to come...
43 case ",$all_into_one," in
45 args='--unpacked --incremental'
48 if [ -d "$PACKDIR" ]; then
49 for e in `cd "$PACKDIR" && find . -type f -name '*.pack' \
50 | sed -e 's/^\.\///' -e 's/\.pack$//'`
52 if [ -e "$PACKDIR/$e.keep" ]; then
55 args="$args --unpacked=$e.pack"
56 existing="$existing $e"
60 [ -z "$args" ] && args='--unpacked --incremental'
64 args="$args $local $quiet $no_reuse_delta$extra"
65 name=$(git-pack-objects --non-empty --all $args </dev/null "$PACKTMP") ||
67 if [ -z "$name" ]; then
68 echo Nothing new to pack.
70 chmod a-w "$PACKTMP-$name.pack"
71 chmod a-w "$PACKTMP-$name.idx"
72 if test "$quiet" != '-q'; then
73 echo "Pack pack-$name created."
75 mkdir -p "$PACKDIR" || exit
79 if test -f "$PACKDIR/pack-$name.$sfx"
81 mv -f "$PACKDIR/pack-$name.$sfx" \
82 "$PACKDIR/old-pack-$name.$sfx"
85 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
86 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
87 test -f "$PACKDIR/pack-$name.pack" &&
88 test -f "$PACKDIR/pack-$name.idx" || {
89 echo >&2 "Couldn't replace the existing pack with updated one."
90 echo >&2 "The original set of packs have been saved as"
91 echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
94 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
97 if test "$remove_redundant" = t
99 # We know $existing are all redundant.
100 if [ -n "$existing" ]
108 *) rm -f "$e.pack" "$e.idx" "$e.keep" ;;
116 case "$no_update_info" in
118 *) git-update-server-info ;;