Code

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