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