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
27PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
28PACKTMP="$GIT_DIR/.tmp-$$-pack"
29rm -f "$PACKTMP"-*
30trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
31
32# There will be more repacking strategies to come...
33case ",$all_into_one," in
34,,)
35 rev_list='--unpacked'
36 pack_objects='--incremental'
37 ;;
38,t,)
39 rev_list=
40 pack_objects=
41
42 # Redundancy check in all-into-one case is trivial.
43 existing=`test -d "$PACKDIR" && cd "$PACKDIR" && \
44 find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
45 ;;
46esac
47
48pack_objects="$pack_objects $local $quiet $no_reuse_delta$extra"
49name=$( { git-rev-list --objects --all $rev_list ||
50 echo "git-rev-list died with exit code $?"
51 } |
52 git-pack-objects --non-empty $pack_objects "$PACKTMP") ||
53 exit 1
54if [ -z "$name" ]; then
55 echo Nothing new to pack.
56else
57 if test "$quiet" != '-q'; then
58 echo "Pack pack-$name created."
59 fi
60 mkdir -p "$PACKDIR" || exit
61
62 for sfx in pack idx
63 do
64 if test -f "$PACKDIR/pack-$name.$sfx"
65 then
66 mv -f "$PACKDIR/pack-$name.$sfx" \
67 "$PACKDIR/old-pack-$name.$sfx"
68 fi
69 done &&
70 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
71 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
72 test -f "$PACKDIR/pack-$name.pack" &&
73 test -f "$PACKDIR/pack-$name.idx" || {
74 echo >&2 "Couldn't replace the existing pack with updated one."
75 echo >&2 "The original set of packs have been saved as"
76 echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
77 exit 1
78 }
79 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
80fi
81
82if test "$remove_redundant" = t
83then
84 # We know $existing are all redundant only when
85 # all-into-one is used.
86 if test "$all_into_one" != '' && test "$existing" != ''
87 then
88 sync
89 ( cd "$PACKDIR" &&
90 for e in $existing
91 do
92 case "$e" in
93 ./pack-$name.pack | ./pack-$name.idx) ;;
94 *) rm -f $e ;;
95 esac
96 done
97 )
98 fi
99 git-prune-packed
100fi
101
102case "$no_update_info" in
103t) : ;;
104*) git-update-server-info ;;
105esac