gitweb: Support for 'forks'
[alt-git.git] / git-repack.sh
blob17e24526c279467891389295a55f8f257ca0d01b
1 #!/bin/sh
3 # Copyright (c) 2005 Linus Torvalds
6 USAGE='[-a] [-d] [-f] [-l] [-n] [-q] [--window=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_delta= extra=
12 while case "$#" in 0) break ;; esac
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_delta=--no-reuse-delta ;;
20 -l) local=--local ;;
21 --window=*) extra="$extra $1" ;;
22 --depth=*) extra="$extra $1" ;;
23 *) usage ;;
24 esac
25 shift
26 done
28 # Later we will default repack.UseDeltaBaseOffset to true
29 default_dbo=false
31 case "`git repo-config --bool repack.usedeltabaseoffset ||
32 echo $default_dbo`" in
33 true)
34 extra="$extra --delta-base-offset" ;;
35 esac
37 PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
38 PACKTMP="$GIT_DIR/.tmp-$$-pack"
39 rm -f "$PACKTMP"-*
40 trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
42 # There will be more repacking strategies to come...
43 case ",$all_into_one," in
44 ,,)
45 args='--unpacked --incremental'
47 ,t,)
48 args=
50 # Redundancy check in all-into-one case is trivial.
51 existing=`test -d "$PACKDIR" && cd "$PACKDIR" && \
52 find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
54 esac
56 args="$args $local $quiet $no_reuse_delta$extra"
57 name=$(git-pack-objects --non-empty --all $args </dev/null "$PACKTMP") ||
58 exit 1
59 if [ -z "$name" ]; then
60 echo Nothing new to pack.
61 else
62 if test "$quiet" != '-q'; then
63 echo "Pack pack-$name created."
65 mkdir -p "$PACKDIR" || exit
67 for sfx in pack idx
69 if test -f "$PACKDIR/pack-$name.$sfx"
70 then
71 mv -f "$PACKDIR/pack-$name.$sfx" \
72 "$PACKDIR/old-pack-$name.$sfx"
74 done &&
75 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
76 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
77 test -f "$PACKDIR/pack-$name.pack" &&
78 test -f "$PACKDIR/pack-$name.idx" || {
79 echo >&2 "Couldn't replace the existing pack with updated one."
80 echo >&2 "The original set of packs have been saved as"
81 echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
82 exit 1
84 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
87 if test "$remove_redundant" = t
88 then
89 # We know $existing are all redundant only when
90 # all-into-one is used.
91 if test "$all_into_one" != '' && test "$existing" != ''
92 then
93 sync
94 ( cd "$PACKDIR" &&
95 for e in $existing
97 case "$e" in
98 ./pack-$name.pack | ./pack-$name.idx) ;;
99 *) rm -f $e ;;
100 esac
101 done
104 git-prune-packed
107 case "$no_update_info" in
108 t) : ;;
109 *) git-update-server-info ;;
110 esac