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