Merge branch 'master' into next
[git.git] / git-repack.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Linus Torvalds
4 #
5
6 USAGE='[-a] [-d] [-f] [-l] [-n] [-q]'
7 . git-sh-setup
8         
9 no_update_info= all_into_one= remove_redundant=
10 local= quiet= no_reuse_delta=
11 while case "$#" in 0) break ;; esac
12 do
13         case "$1" in
14         -n)     no_update_info=t ;;
15         -a)     all_into_one=t ;;
16         -d)     remove_redundant=t ;;
17         -q)     quiet=-q ;;
18         -f)     no_reuse_delta=--no-reuse-delta ;;
19         -l)     local=--local ;;
20         *)      usage ;;
21         esac
22         shift
23 done
24
25 rm -f .tmp-pack-*
26 PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
27
28 # There will be more repacking strategies to come...
29 case ",$all_into_one," in
30 ,,)
31         rev_list='--unpacked'
32         pack_objects='--incremental'
33         ;;
34 ,t,)
35         rev_list=
36         pack_objects=
37
38         # Redundancy check in all-into-one case is trivial.
39         existing=`cd "$PACKDIR" && \
40             find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
41         ;;
42 esac
43 pack_objects="$pack_objects $local $quiet $no_reuse_delta"
44 name=$(git-rev-list --objects --all $rev_list 2>&1 |
45         git-pack-objects --non-empty $pack_objects .tmp-pack) ||
46         exit 1
47 if [ -z "$name" ]; then
48         echo Nothing new to pack.
49         exit 0
50 fi
51 echo "Pack pack-$name created."
52
53 mkdir -p "$PACKDIR" || exit
54
55 mv .tmp-pack-$name.pack "$PACKDIR/pack-$name.pack" &&
56 mv .tmp-pack-$name.idx  "$PACKDIR/pack-$name.idx" ||
57 exit
58
59 if test "$remove_redundant" = t
60 then
61         # We know $existing are all redundant only when
62         # all-into-one is used.
63         if test "$all_into_one" != '' && test "$existing" != ''
64         then
65                 sync
66                 ( cd "$PACKDIR" &&
67                   for e in $existing
68                   do
69                         case "$e" in
70                         ./pack-$name.pack | ./pack-$name.idx) ;;
71                         *)      rm -f $e ;;
72                         esac
73                   done
74                 )
75         fi
76         git-prune-packed
77 fi
78
79 case "$no_update_info" in
80 t) : ;;
81 *) git-update-server-info ;;
82 esac