1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Linus Torvalds
4 #
6 . git-sh-setup || die "Not a git archive"
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_redundant=t ;;
15 -l) local=t ;;
16 *) break ;;
17 esac
18 shift
19 done
21 rm -f .tmp-pack-*
22 PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
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 ;;
36 esac
37 if [ "$local" ]; then
38 pack_objects="$pack_objects --local"
39 fi
40 name=$(git-rev-list --objects $rev_list $(git-rev-parse $rev_parse) |
41 git-pack-objects --non-empty $pack_objects .tmp-pack) ||
42 exit 1
43 if [ -z "$name" ]; then
44 echo Nothing new to pack.
45 if test "$remove_redundant" = t ; then
46 echo "Removing redundant packs."
47 sync
48 redundant=$(git-pack-redundant --all)
49 if test "$redundant" != "" ; then
50 echo $redundant | xargs rm
51 fi
52 fi
53 exit 0
54 fi
55 echo "Pack pack-$name created."
57 mkdir -p "$PACKDIR" || exit
59 mv .tmp-pack-$name.pack "$PACKDIR/pack-$name.pack" &&
60 mv .tmp-pack-$name.idx "$PACKDIR/pack-$name.idx" ||
61 exit
63 if test "$remove_redundant" = t
64 then
65 sync
66 if test "$all_into_one" = t
67 then
68 cd "$PACKDIR"
69 existing=`find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
70 for e in $existing
71 do
72 case "$e" in
73 ./pack-$name.pack | ./pack-$name.idx) ;;
74 *) rm -f $e ;;
75 esac
76 done
77 else
78 redundant=$(git-pack-redundant --all)
79 if test "$redundant" != "" ; then
80 echo $redundant | xargs rm
81 fi
82 fi
83 fi
85 case "$no_update_info" in
86 t) : ;;
87 *) git-update-server-info ;;
88 esac