Fix cvsimport warning when called without --no-cvs-direct
[git.git] / git-repack.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Linus Torvalds
4 #
5
6 . git-sh-setup || die "Not a git archive"
7         
8 no_update_info= all_into_one= remove_redundant= local=
9 while case "$#" in 0) break ;; esac
10 do
11         case "$1" in
12         -n)     no_update_info=t ;;
13         -a)     all_into_one=t ;;
14         -d)     remove_redandant=t ;;
15         -l)     local=t ;;
16         *)      break ;;
17         esac
18         shift
19 done
20
21 rm -f .tmp-pack-*
22 PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
23
24 # There will be more repacking strategies to come...
25 case ",$all_into_one," in
26 ,,)
27         rev_list='--unpacked'
28         rev_parse='--all'
29         pack_objects='--incremental'
30         ;;
31 ,t,)
32         rev_list=
33         rev_parse='--all'
34         pack_objects=
35         # This part is a stop-gap until we have proper pack redundancy
36         # checker.
37         existing=`cd "$PACKDIR" && \
38             find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
39         ;;
40 esac
41 if [ "$local" ]; then
42         pack_objects="$pack_objects --local"
43 fi
44 name=$(git-rev-list --objects $rev_list $(git-rev-parse $rev_parse) |
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_redandant" = t
60 then
61         # We know $existing are all redandant only when
62         # all-into-one is used.
63         if test "$all_into_one" != '' && test "$existing" != ''
64         then
65                 ( cd "$PACKDIR" &&
66                   for e in $existing
67                   do
68                         case "$e" in
69                         ./pack-$name.pack | ./pack-$name.idx) ;;
70                         *)      rm -f $e ;;
71                         esac
72                   done
73                 )
74         fi
75 fi
76
77 case "$no_update_info" in
78 t) : ;;
79 *) git-update-server-info ;;
80 esac