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]'
10 no_update_info
= all_into_one
= remove_redundant
=
11 local= quiet
= no_reuse
= extra
=
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" ;;
30 # Later we will default repack.UseDeltaBaseOffset to true
33 case "`git config --bool repack.usedeltabaseoffset ||
34 echo $default_dbo`" in
36 extra
="$extra --delta-base-offset" ;;
39 PACKDIR
="$GIT_OBJECT_DIRECTORY/pack"
40 PACKTMP
="$GIT_OBJECT_DIRECTORY/.tmp-$$-pack"
42 trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
44 # There will be more repacking strategies to come...
45 case ",$all_into_one," in
47 args
='--unpacked --incremental'
50 if [ -d "$PACKDIR" ]; then
51 for e
in `cd "$PACKDIR" && find . -type f -name '*.pack' \
52 | sed -e 's/^\.\///' -e 's/\.pack$//'`
54 if [ -e "$PACKDIR/$e.keep" ]; then
57 args
="$args --unpacked=$e.pack"
58 existing
="$existing $e"
62 [ -z "$args" ] && args
='--unpacked --incremental'
66 args
="$args $local $quiet $no_reuse$extra"
67 names
=$
(git pack-objects
--non-empty --all --reflog $args </dev
/null
"$PACKTMP") ||
69 if [ -z "$names" ]; then
70 if test -z "$quiet"; then
71 echo Nothing new to pack.
74 for name
in $names ; do
75 fullbases
="$fullbases pack-$name"
76 chmod a-w
"$PACKTMP-$name.pack"
77 chmod a-w
"$PACKTMP-$name.idx"
78 if test "$quiet" != '-q'; then
79 echo "Pack pack-$name created."
81 mkdir
-p "$PACKDIR" ||
exit
85 if test -f "$PACKDIR/pack-$name.$sfx"
87 mv -f "$PACKDIR/pack-$name.$sfx" \
88 "$PACKDIR/old-pack-$name.$sfx"
91 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
92 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
93 test -f "$PACKDIR/pack-$name.pack" &&
94 test -f "$PACKDIR/pack-$name.idx" ||
{
95 echo >&2 "Couldn't replace the existing pack with updated one."
96 echo >&2 "The original set of packs have been saved as"
97 echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
100 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
103 if test "$remove_redundant" = t
105 # We know $existing are all redundant.
106 if [ -n "$existing" ]
112 case " $fullbases " in
114 *) rm -f "$e.pack" "$e.idx" "$e.keep" ;;
119 git prune-packed
$quiet
122 case "$no_update_info" in
124 *) git-update-server-info
;;