]> git.ipfire.org Git - thirdparty/git.git/blame - git-repack.sh
git-svn: support for funky branch and project names over HTTP(S)
[thirdparty/git.git] / git-repack.sh
CommitLineData
b2d46199 1#!/bin/sh
ccf1ee32
JH
2#
3# Copyright (c) 2005 Linus Torvalds
4#
5
65aa5302 6USAGE='[-a|-A] [-d] [-f] [-l] [-n] [-q] [--max-pack-size=N] [--window=N] [--window-memory=N] [--depth=N]'
d0b353b1 7SUBDIRECTORY_OK='Yes'
ae2b0f15 8. git-sh-setup
ccb36504 9
65aa5302 10no_update_info= all_into_one= remove_redundant= keep_unreachable=
479b56ba 11local= quiet= no_reuse= extra=
822f7c73 12while test $# != 0
ccf1ee32
JH
13do
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
30done
31
b6945f57
JH
32# Later we will default repack.UseDeltaBaseOffset to true
33default_dbo=false
34
e0d10e1c 35case "`git config --bool repack.usedeltabaseoffset ||
b6945f57
JH
36 echo $default_dbo`" in
37true)
38 extra="$extra --delta-base-offset" ;;
39esac
40
d5acdcf1 41PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
6b94b1a0 42PACKTMP="$GIT_OBJECT_DIRECTORY/.tmp-$$-pack"
0ea2582d
ML
43rm -f "$PACKTMP"-*
44trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
d5acdcf1
JH
45
46# There will be more repacking strategies to come...
47case ",$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 ;;
72esac
0ea2582d 73
479b56ba 74args="$args $local $quiet $no_reuse$extra"
5be60078 75names=$(git pack-objects --non-empty --all --reflog $args </dev/null "$PACKTMP") ||
b2d46199 76 exit 1
6b94b1a0 77if [ -z "$names" ]; then
d9fb395a
UKK
78 if test -z "$quiet"; then
79 echo Nothing new to pack.
80 fi
6b94b1a0
DH
81fi
82for 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"
178613c7 86 mkdir -p "$PACKDIR" || exit
d5acdcf1 87
2ad47d61
JH
88 for sfx in pack idx
89 do
90 if test -f "$PACKDIR/pack-$name.$sfx"
91 then
92 mv -f "$PACKDIR/pack-$name.$sfx" \
93 "$PACKDIR/old-pack-$name.$sfx"
94 fi
95 done &&
0ea2582d
ML
96 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
97 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
2ad47d61
JH
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."
103 exit 1
104 }
105 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
6b94b1a0 106done
d5acdcf1 107
0adb3358 108if test "$remove_redundant" = t
d5acdcf1 109then
ce859074
SP
110 # We know $existing are all redundant.
111 if [ -n "$existing" ]
62af0b53 112 then
6ed64058
JH
113 sync
114 ( cd "$PACKDIR" &&
115 for e in $existing
116 do
dca3957b
DH
117 case " $fullbases " in
118 *" $e "*) ;;
ce859074 119 *) rm -f "$e.pack" "$e.idx" "$e.keep" ;;
62af0b53 120 esac
6ed64058
JH
121 done
122 )
d5acdcf1 123 fi
5be60078 124 git prune-packed $quiet
d5acdcf1 125fi
ccf1ee32 126
ccf1ee32
JH
127case "$no_update_info" in
128t) : ;;
129*) git-update-server-info ;;
130esac