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 if test "$quiet" != '-q'; then
87 echo "Pack pack-$name created."
89 mkdir -p "$PACKDIR" || exit
93 if test -f "$PACKDIR/pack-$name.$sfx"
95 mv -f "$PACKDIR/pack-$name.$sfx" \
96 "$PACKDIR/old-pack-$name.$sfx"
99 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
100 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
101 test -f "$PACKDIR/pack-$name.pack" &&
102 test -f "$PACKDIR/pack-$name.idx" || {
103 echo >&2 "Couldn't replace the existing pack with updated one."
104 echo >&2 "The original set of packs have been saved as"
105 echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
108 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
111 if test "$remove_redundant" = t
113 # We know $existing are all redundant.
114 if [ -n "$existing" ]
120 case " $fullbases " in
122 *) rm -f "$e.pack" "$e.idx" "$e.keep" ;;
127 git prune-packed $quiet
130 case "$no_update_info" in
132 *) git-update-server-info ;;