Merge branch 'maint'
[git/gitweb.git] / git-repack.sh
blobf2c9071d1109e014832f0efd8a1fd67dca44c8af
1 #!/bin/sh
3 # Copyright (c) 2005 Linus Torvalds
6 USAGE='[-a] [-d] [-f] [-l] [-n] [-q]'
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 PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
29 PACKTMP="$GIT_DIR/.tmp-$$-pack"
30 rm -f "$PACKTMP"-*
31 trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
33 # There will be more repacking strategies to come...
34 case ",$all_into_one," in
35 ,,)
36 args='--unpacked --incremental'
38 ,t,)
39 args=
41 # Redundancy check in all-into-one case is trivial.
42 existing=`test -d "$PACKDIR" && cd "$PACKDIR" && \
43 find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
45 esac
47 args="$args $local $quiet $no_reuse_delta$extra"
48 name=$(git-pack-objects --non-empty --all $args </dev/null "$PACKTMP") ||
49 exit 1
50 if [ -z "$name" ]; then
51 echo Nothing new to pack.
52 else
53 if test "$quiet" != '-q'; then
54 echo "Pack pack-$name created."
56 mkdir -p "$PACKDIR" || exit
58 for sfx in pack idx
60 if test -f "$PACKDIR/pack-$name.$sfx"
61 then
62 mv -f "$PACKDIR/pack-$name.$sfx" \
63 "$PACKDIR/old-pack-$name.$sfx"
65 done &&
66 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
67 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
68 test -f "$PACKDIR/pack-$name.pack" &&
69 test -f "$PACKDIR/pack-$name.idx" || {
70 echo >&2 "Couldn't replace the existing pack with updated one."
71 echo >&2 "The original set of packs have been saved as"
72 echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
73 exit 1
75 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
78 if test "$remove_redundant" = t
79 then
80 # We know $existing are all redundant only when
81 # all-into-one is used.
82 if test "$all_into_one" != '' && test "$existing" != ''
83 then
84 sync
85 ( cd "$PACKDIR" &&
86 for e in $existing
88 case "$e" in
89 ./pack-$name.pack | ./pack-$name.idx) ;;
90 *) rm -f $e ;;
91 esac
92 done
95 git-prune-packed
98 case "$no_update_info" in
99 t) : ;;
100 *) git-update-server-info ;;
101 esac