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'
50 # Redundancy check in all-into-one case is trivial.
51 existing=`test -d "$PACKDIR" && cd "$PACKDIR" && \
52 find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
56 args="$args $local $quiet $no_reuse_delta$extra"
57 name=$(git-pack-objects --non-empty --all $args </dev/null "$PACKTMP") ||
59 if [ -z "$name" ]; then
60 echo Nothing new to pack.
62 if test "$quiet" != '-q'; then
63 echo "Pack pack-$name created."
65 mkdir -p "$PACKDIR" || exit
69 if test -f "$PACKDIR/pack-$name.$sfx"
71 mv -f "$PACKDIR/pack-$name.$sfx" \
72 "$PACKDIR/old-pack-$name.$sfx"
75 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
76 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
77 test -f "$PACKDIR/pack-$name.pack" &&
78 test -f "$PACKDIR/pack-$name.idx" || {
79 echo >&2 "Couldn't replace the existing pack with updated one."
80 echo >&2 "The original set of packs have been saved as"
81 echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
84 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
87 if test "$remove_redundant" = t
89 # We know $existing are all redundant only when
90 # all-into-one is used.
91 if test "$all_into_one" != '' && test "$existing" != ''
98 ./pack-$name.pack | ./pack-$name.idx) ;;
107 case "$no_update_info" in
109 *) git-update-server-info ;;