git-repack --max-pack-size: split packs as asked by write_{object,one}()
[git/git.git] / git-repack.sh
CommitLineData
b2d46199 1#!/bin/sh
ccf1ee32
JH
2#
3# Copyright (c) 2005 Linus Torvalds
4#
5
b6945f57 6USAGE='[-a] [-d] [-f] [-l] [-n] [-q] [--window=N] [--depth=N]'
d0b353b1 7SUBDIRECTORY_OK='Yes'
ae2b0f15 8. git-sh-setup
ccb36504 9
cec2be76 10no_update_info= all_into_one= remove_redundant=
479b56ba 11local= quiet= no_reuse= extra=
ccf1ee32
JH
12while case "$#" in 0) break ;; esac
13do
14 case "$1" in
15 -n) no_update_info=t ;;
d5acdcf1 16 -a) all_into_one=t ;;
0adb3358 17 -d) remove_redundant=t ;;
cec2be76 18 -q) quiet=-q ;;
479b56ba 19 -f) no_reuse=--no-reuse-object ;;
cec2be76 20 -l) local=--local ;;
ccb36504
LT
21 --window=*) extra="$extra $1" ;;
22 --depth=*) extra="$extra $1" ;;
9678faaa 23 *) usage ;;
ccf1ee32
JH
24 esac
25 shift
26done
27
b6945f57
JH
28# Later we will default repack.UseDeltaBaseOffset to true
29default_dbo=false
30
e0d10e1c 31case "`git config --bool repack.usedeltabaseoffset ||
b6945f57
JH
32 echo $default_dbo`" in
33true)
34 extra="$extra --delta-base-offset" ;;
35esac
36
d5acdcf1 37PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
0ea2582d
ML
38PACKTMP="$GIT_DIR/.tmp-$$-pack"
39rm -f "$PACKTMP"-*
40trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
d5acdcf1
JH
41
42# There will be more repacking strategies to come...
43case ",$all_into_one," in
44,,)
cd0d74d2 45 args='--unpacked --incremental'
d5acdcf1
JH
46 ;;
47,t,)
ce859074
SP
48 if [ -d "$PACKDIR" ]; then
49 for e in `cd "$PACKDIR" && find . -type f -name '*.pack' \
50 | sed -e 's/^\.\///' -e 's/\.pack$//'`
51 do
52 if [ -e "$PACKDIR/$e.keep" ]; then
53 : keep
54 else
55 args="$args --unpacked=$e.pack"
56 existing="$existing $e"
57 fi
58 done
59 fi
60 [ -z "$args" ] && args='--unpacked --incremental'
d5acdcf1
JH
61 ;;
62esac
0ea2582d 63
479b56ba 64args="$args $local $quiet $no_reuse$extra"
63049292 65name=$(git-pack-objects --non-empty --all --reflog $args </dev/null "$PACKTMP") ||
b2d46199 66 exit 1
d5acdcf1
JH
67if [ -z "$name" ]; then
68 echo Nothing new to pack.
178613c7 69else
ad2c82c0
NP
70 chmod a-w "$PACKTMP-$name.pack"
71 chmod a-w "$PACKTMP-$name.idx"
1054dcd1
ML
72 if test "$quiet" != '-q'; then
73 echo "Pack pack-$name created."
74 fi
178613c7 75 mkdir -p "$PACKDIR" || exit
d5acdcf1 76
2ad47d61
JH
77 for sfx in pack idx
78 do
79 if test -f "$PACKDIR/pack-$name.$sfx"
80 then
81 mv -f "$PACKDIR/pack-$name.$sfx" \
82 "$PACKDIR/old-pack-$name.$sfx"
83 fi
84 done &&
0ea2582d
ML
85 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
86 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
2ad47d61
JH
87 test -f "$PACKDIR/pack-$name.pack" &&
88 test -f "$PACKDIR/pack-$name.idx" || {
89 echo >&2 "Couldn't replace the existing pack with updated one."
90 echo >&2 "The original set of packs have been saved as"
91 echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
92 exit 1
93 }
94 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
178613c7 95fi
d5acdcf1 96
0adb3358 97if test "$remove_redundant" = t
d5acdcf1 98then
ce859074
SP
99 # We know $existing are all redundant.
100 if [ -n "$existing" ]
62af0b53 101 then
6ed64058
JH
102 sync
103 ( cd "$PACKDIR" &&
104 for e in $existing
105 do
62af0b53 106 case "$e" in
ce859074
SP
107 pack-$name) ;;
108 *) rm -f "$e.pack" "$e.idx" "$e.keep" ;;
62af0b53 109 esac
6ed64058
JH
110 done
111 )
d5acdcf1 112 fi
b60daf05 113 git-prune-packed $quiet
d5acdcf1 114fi
ccf1ee32 115
ccf1ee32
JH
116case "$no_update_info" in
117t) : ;;
118*) git-update-server-info ;;
119esac