3 # Copyright (c) 2005 Linus Torvalds
6 USAGE
='[-a] [-d] [-f] [-l] [-n] [-q] [--max-pack-size=N] [--window=N] [--depth=N]'
10 no_update_info
= all_into_one
= remove_redundant
=
11 local= quiet
= no_reuse
= extra
=
12 while case "$#" in 0) break ;; esac
15 -n) no_update_info
=t
;;
17 -d) remove_redundant
=t
;;
19 -f) no_reuse
=--no-reuse-object ;;
21 --max-pack-size=*) extra
="$extra $1" ;;
22 --window=*) extra
="$extra $1" ;;
23 --depth=*) extra
="$extra $1" ;;
29 # Later we will default repack.UseDeltaBaseOffset to true
32 case "`git config --bool repack.usedeltabaseoffset ||
33 echo $default_dbo`" in
35 extra
="$extra --delta-base-offset" ;;
38 PACKDIR
="$GIT_OBJECT_DIRECTORY/pack"
39 PACKTMP
="$GIT_OBJECT_DIRECTORY/.tmp-$$-pack"
41 trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
43 # There will be more repacking strategies to come...
44 case ",$all_into_one," in
46 args
='--unpacked --incremental'
49 if [ -d "$PACKDIR" ]; then
50 for e
in `cd "$PACKDIR" && find . -type f -name '*.pack' \
51 | sed -e 's/^\.\///' -e 's/\.pack$//'`
53 if [ -e "$PACKDIR/$e.keep" ]; then
56 args
="$args --unpacked=$e.pack"
57 existing
="$existing $e"
61 [ -z "$args" ] && args
='--unpacked --incremental'
65 args
="$args $local $quiet $no_reuse$extra"
66 names
=$
(git pack-objects
--non-empty --all --reflog $args </dev
/null
"$PACKTMP") ||
68 if [ -z "$names" ]; then
69 if test -z "$quiet"; then
70 echo Nothing new to pack.
73 for name
in $names ; do
74 fullbases
="$fullbases pack-$name"
75 chmod a-w
"$PACKTMP-$name.pack"
76 chmod a-w
"$PACKTMP-$name.idx"
77 if test "$quiet" != '-q'; then
78 echo "Pack pack-$name created."
80 mkdir
-p "$PACKDIR" ||
exit
84 if test -f "$PACKDIR/pack-$name.$sfx"
86 mv -f "$PACKDIR/pack-$name.$sfx" \
87 "$PACKDIR/old-pack-$name.$sfx"
90 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
91 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
92 test -f "$PACKDIR/pack-$name.pack" &&
93 test -f "$PACKDIR/pack-$name.idx" ||
{
94 echo >&2 "Couldn't replace the existing pack with updated one."
95 echo >&2 "The original set of packs have been saved as"
96 echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
99 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
102 if test "$remove_redundant" = t
104 # We know $existing are all redundant.
105 if [ -n "$existing" ]
111 case " $fullbases " in
113 *) rm -f "$e.pack" "$e.idx" "$e.keep" ;;
118 git prune-packed
$quiet
121 case "$no_update_info" in
123 *) git-update-server-info
;;