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= extra=
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 --window=*) extra="$extra $1" ;;
21 --depth=*) extra="$extra $1" ;;
22 *) usage ;;
23 esac
24 shift
25done
26
27rm -f .tmp-pack-*
28PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
29
30# There will be more repacking strategies to come...
31case ",$all_into_one," in
32,,)
33 rev_list='--unpacked'
34 pack_objects='--incremental'
35 ;;
36,t,)
37 rev_list=
38 pack_objects=
39
40 # Redundancy check in all-into-one case is trivial.
41 existing=`cd "$PACKDIR" && \
42 find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
43 ;;
44esac
45pack_objects="$pack_objects $local $quiet $no_reuse_delta$extra"
46name=$(git-rev-list --objects --all $rev_list 2>&1 |
47 git-pack-objects --non-empty $pack_objects .tmp-pack) ||
48 exit 1
49if [ -z "$name" ]; then
50 echo Nothing new to pack.
51else
52 if test "$quiet" != '-q'; then
53 echo "Pack pack-$name created."
54 fi
55 mkdir -p "$PACKDIR" || exit
56
57 mv .tmp-pack-$name.pack "$PACKDIR/pack-$name.pack" &&
58 mv .tmp-pack-$name.idx "$PACKDIR/pack-$name.idx" ||
59 exit
60fi
61
62if test "$remove_redundant" = t
63then
64 # We know $existing are all redundant only when
65 # all-into-one is used.
66 if test "$all_into_one" != '' && test "$existing" != ''
67 then
68 sync
69 ( cd "$PACKDIR" &&
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 )
78 fi
79 git-prune-packed
80fi
81
82case "$no_update_info" in
83t) : ;;
84*) git-update-server-info ;;
85esac