git-hash-object should honor config variables
[git/dscho.git] / git-repack.sh
blob0aae1a3ed5571a010f80438f8e8a0fc7eb0dc285
1 #!/bin/sh
3 # Copyright (c) 2005 Linus Torvalds
6 USAGE='[-a] [-d] [-f] [-l] [-n] [-q] [--max-pack-size=N] [--window=N] [--window-memory=N] [--depth=N]'
7 SUBDIRECTORY_OK='Yes'
8 . git-sh-setup
10 no_update_info= all_into_one= remove_redundant=
11 local= quiet= no_reuse= extra=
12 while test $# != 0
14 case "$1" in
15 -n) no_update_info=t ;;
16 -a) all_into_one=t ;;
17 -d) remove_redundant=t ;;
18 -q) quiet=-q ;;
19 -f) no_reuse=--no-reuse-object ;;
20 -l) local=--local ;;
21 --max-pack-size=*) extra="$extra $1" ;;
22 --window=*) extra="$extra $1" ;;
23 --window-memory=*) extra="$extra $1" ;;
24 --depth=*) extra="$extra $1" ;;
25 *) usage ;;
26 esac
27 shift
28 done
30 # Later we will default repack.UseDeltaBaseOffset to true
31 default_dbo=false
33 case "`git config --bool repack.usedeltabaseoffset ||
34 echo $default_dbo`" in
35 true)
36 extra="$extra --delta-base-offset" ;;
37 esac
39 PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
40 PACKTMP="$GIT_OBJECT_DIRECTORY/.tmp-$$-pack"
41 rm -f "$PACKTMP"-*
42 trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
44 # There will be more repacking strategies to come...
45 case ",$all_into_one," in
46 ,,)
47 args='--unpacked --incremental'
49 ,t,)
50 if [ -d "$PACKDIR" ]; then
51 for e in `cd "$PACKDIR" && find . -type f -name '*.pack' \
52 | sed -e 's/^\.\///' -e 's/\.pack$//'`
54 if [ -e "$PACKDIR/$e.keep" ]; then
55 : keep
56 else
57 args="$args --unpacked=$e.pack"
58 existing="$existing $e"
60 done
62 [ -z "$args" ] && args='--unpacked --incremental'
64 esac
66 args="$args $local $quiet $no_reuse$extra"
67 names=$(git pack-objects --non-empty --all --reflog $args </dev/null "$PACKTMP") ||
68 exit 1
69 if [ -z "$names" ]; then
70 if test -z "$quiet"; then
71 echo Nothing new to pack.
74 for name in $names ; do
75 fullbases="$fullbases pack-$name"
76 chmod a-w "$PACKTMP-$name.pack"
77 chmod a-w "$PACKTMP-$name.idx"
78 if test "$quiet" != '-q'; then
79 echo "Pack pack-$name created."
81 mkdir -p "$PACKDIR" || exit
83 for sfx in pack idx
85 if test -f "$PACKDIR/pack-$name.$sfx"
86 then
87 mv -f "$PACKDIR/pack-$name.$sfx" \
88 "$PACKDIR/old-pack-$name.$sfx"
90 done &&
91 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
92 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
93 test -f "$PACKDIR/pack-$name.pack" &&
94 test -f "$PACKDIR/pack-$name.idx" || {
95 echo >&2 "Couldn't replace the existing pack with updated one."
96 echo >&2 "The original set of packs have been saved as"
97 echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
98 exit 1
100 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
101 done
103 if test "$remove_redundant" = t
104 then
105 # We know $existing are all redundant.
106 if [ -n "$existing" ]
107 then
108 sync
109 ( cd "$PACKDIR" &&
110 for e in $existing
112 case " $fullbases " in
113 *" $e "*) ;;
114 *) rm -f "$e.pack" "$e.idx" "$e.keep" ;;
115 esac
116 done
119 git prune-packed $quiet
122 case "$no_update_info" in
123 t) : ;;
124 *) git-update-server-info ;;
125 esac