3 # Copyright (c) 2005 Linus Torvalds
6 USAGE
='[-a] [-d] [-f] [-l] [-n] [-q] [--max-pack-size=N] [--window=N] [--window-memory=N] [--depth=N] [--pack-version=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 --window-memory=*) extra
="$extra $1" ;;
24 --depth=*) extra
="$extra $1" ;;
25 --pack-version=*) extra
="$extra $1" ;;
31 # Later we will default repack.UseDeltaBaseOffset to true
34 case "`git config --bool repack.usedeltabaseoffset ||
35 echo $default_dbo`" in
37 extra
="$extra --delta-base-offset" ;;
40 PACKDIR
="$GIT_OBJECT_DIRECTORY/pack"
41 PACKTMP
="$GIT_OBJECT_DIRECTORY/.tmp-$$-pack"
43 trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
45 # There will be more repacking strategies to come...
46 case ",$all_into_one," in
48 args
='--unpacked --incremental'
51 if [ -d "$PACKDIR" ]; then
52 for e
in `cd "$PACKDIR" && find . -type f -name '*.pack' \
53 | sed -e 's/^\.\///' -e 's/\.pack$//'`
55 if [ -e "$PACKDIR/$e.keep" ]; then
58 args
="$args --unpacked=$e.pack"
59 existing
="$existing $e"
63 [ -z "$args" ] && args
='--unpacked --incremental'
67 args
="$args $local $quiet $no_reuse$extra"
68 names
=$
(git pack-objects
--non-empty --all --reflog $args </dev
/null
"$PACKTMP") ||
70 if [ -z "$names" ]; then
71 if test -z "$quiet"; then
72 echo Nothing new to pack.
75 for name
in $names ; do
76 fullbases
="$fullbases pack-$name"
77 chmod a-w
"$PACKTMP-$name.pack"
78 chmod a-w
"$PACKTMP-$name.idx"
79 if test "$quiet" != '-q'; then
80 echo "Pack pack-$name created."
82 mkdir
-p "$PACKDIR" ||
exit
86 if test -f "$PACKDIR/pack-$name.$sfx"
88 mv -f "$PACKDIR/pack-$name.$sfx" \
89 "$PACKDIR/old-pack-$name.$sfx"
92 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
93 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
94 test -f "$PACKDIR/pack-$name.pack" &&
95 test -f "$PACKDIR/pack-$name.idx" ||
{
96 echo >&2 "Couldn't replace the existing pack with updated one."
97 echo >&2 "The original set of packs have been saved as"
98 echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
101 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
104 if test "$remove_redundant" = t
106 # We know $existing are all redundant.
107 if [ -n "$existing" ]
113 case " $fullbases " in
115 *) rm -f "$e.pack" "$e.idx" "$e.keep" ;;
120 git prune-packed
$quiet
123 case "$no_update_info" in
125 *) git-update-server-info
;;