1#!/bin/sh
2#
3# Copyright (c) 2005 Linus Torvalds
4#
5
6USAGE='[-a] [-d] [-f] [-l] [-n] [-q]'
7. git-sh-setup
8
9no_update_info= all_into_one= remove_redundant=
10local= quiet= no_reuse_delta=
11while case "$#" in 0) break ;; esac
12do
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
23done
24
25rm -f .tmp-pack-*
26PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
27
28# There will be more repacking strategies to come...
29case ",$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 ;;
42esac
43pack_objects="$pack_objects $local $quiet $no_reuse_delta"
44name=$(git-rev-list --objects --all $rev_list 2>&1 |
45 git-pack-objects --non-empty $pack_objects .tmp-pack) ||
46 exit 1
47if [ -z "$name" ]; then
48 echo Nothing new to pack.
49 exit 0
50fi
51echo "Pack pack-$name created."
52
53mkdir -p "$PACKDIR" || exit
54
55mv .tmp-pack-$name.pack "$PACKDIR/pack-$name.pack" &&
56mv .tmp-pack-$name.idx "$PACKDIR/pack-$name.idx" ||
57exit
58
59if test "$remove_redundant" = t
60then
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
77fi
78
79case "$no_update_info" in
80t) : ;;
81*) git-update-server-info ;;
82esac