3 # Copyright (c) 2005 Linus Torvalds
6 USAGE
='[-a|-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
= keep_unreachable
=
11 local= quiet
= no_reuse
= extra
=
15 -n) no_update_info
=t
;;
18 keep_unreachable
=--keep-unreachable ;;
19 -d) remove_redundant
=t
;;
21 -f) no_reuse
=--no-reuse-object ;;
23 --max-pack-size=*) extra
="$extra $1" ;;
24 --window=*) extra
="$extra $1" ;;
25 --window-memory=*) extra
="$extra $1" ;;
26 --depth=*) extra
="$extra $1" ;;
32 # Later we will default repack.UseDeltaBaseOffset to true
35 case "`git config --bool repack.usedeltabaseoffset ||
36 echo $default_dbo`" in
38 extra
="$extra --delta-base-offset" ;;
41 PACKDIR
="$GIT_OBJECT_DIRECTORY/pack"
42 PACKTMP
="$GIT_OBJECT_DIRECTORY/.tmp-$$-pack"
44 trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
46 # There will be more repacking strategies to come...
47 case ",$all_into_one," in
49 args
='--unpacked --incremental'
52 if [ -d "$PACKDIR" ]; then
53 for e
in `cd "$PACKDIR" && find . -type f -name '*.pack' \
54 | sed -e 's/^\.\///' -e 's/\.pack$//'`
56 if [ -e "$PACKDIR/$e.keep" ]; then
59 args
="$args --unpacked=$e.pack"
60 existing
="$existing $e"
66 args
='--unpacked --incremental'
67 elif test -n "$keep_unreachable"
69 args
="$args $keep_unreachable"
74 args
="$args $local $quiet $no_reuse$extra"
75 names
=$
(git pack-objects
--non-empty --all --reflog $args </dev
/null
"$PACKTMP") ||
77 if [ -z "$names" ]; then
78 if test -z "$quiet"; then
79 echo Nothing new to pack.
82 for name
in $names ; do
83 fullbases
="$fullbases pack-$name"
84 chmod a-w
"$PACKTMP-$name.pack"
85 chmod a-w
"$PACKTMP-$name.idx"
86 mkdir
-p "$PACKDIR" ||
exit
90 if test -f "$PACKDIR/pack-$name.$sfx"
92 mv -f "$PACKDIR/pack-$name.$sfx" \
93 "$PACKDIR/old-pack-$name.$sfx"
96 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
97 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
98 test -f "$PACKDIR/pack-$name.pack" &&
99 test -f "$PACKDIR/pack-$name.idx" ||
{
100 echo >&2 "Couldn't replace the existing pack with updated one."
101 echo >&2 "The original set of packs have been saved as"
102 echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
105 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
108 if test "$remove_redundant" = t
110 # We know $existing are all redundant.
111 if [ -n "$existing" ]
117 case " $fullbases " in
119 *) rm -f "$e.pack" "$e.idx" "$e.keep" ;;
124 git prune-packed
$quiet
127 case "$no_update_info" in
129 *) git-update-server-info
;;