1#!/bin/sh
2#
3# Copyright (c) 2005 Linus Torvalds
4#
5
6. git-sh-setup || die "Not a git archive"
7
8no_update_info= all_into_one= remove_redundant= local=
9while case "$#" in 0) break ;; esac
10do
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
19done
20
21rm -f .tmp-pack-*
22PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
23
24# There will be more repacking strategies to come...
25case ",$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 ;;
36esac
37if [ "$local" ]; then
38 pack_objects="$pack_objects --local"
39fi
40name=$(git-rev-list --objects $rev_list $(git-rev-parse $rev_parse) |
41 git-pack-objects --non-empty $pack_objects .tmp-pack) ||
42 exit 1
43if [ -z "$name" ]; then
44 echo Nothing new to pack.
45 if test "$remove_redandant" = 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
54fi
55echo "Pack pack-$name created."
56
57mkdir -p "$PACKDIR" || exit
58
59mv .tmp-pack-$name.pack "$PACKDIR/pack-$name.pack" &&
60mv .tmp-pack-$name.idx "$PACKDIR/pack-$name.idx" ||
61exit
62
63if test "$remove_redandant" = t
64then
65 sync
66 redundant=$(git-pack-redundant --all)
67 if test "$redundant" != "" ; then
68 echo $redundant | xargs rm
69 fi
70fi
71
72case "$no_update_info" in
73t) : ;;
74*) git-update-server-info ;;
75esac