1#!/bin/sh
2#
3# Copyright (c) 2005 Linus Torvalds
4#
5
6USAGE='[-a] [-d] [-f] [-l] [-n] [-q] [--window=N] [--depth=N]'
7SUBDIRECTORY_OK='Yes'
8. git-sh-setup
9
10no_update_info= all_into_one= remove_redundant=
11local= quiet= no_reuse_delta= extra=
12while case "$#" in 0) break ;; esac
13do
14 case "$1" in
15 -n) no_update_info=t ;;
16 -a) all_into_one=t ;;
17 -d) remove_redundant=t ;;
18 -q) quiet=-q ;;
19 -f) no_reuse_delta=--no-reuse-delta ;;
20 -l) local=--local ;;
21 --window=*) extra="$extra $1" ;;
22 --depth=*) extra="$extra $1" ;;
23 *) usage ;;
24 esac
25 shift
26done
27
28# Later we will default repack.UseDeltaBaseOffset to true
29default_dbo=false
30
31case "`git repo-config --bool repack.usedeltabaseoffset ||
32 echo $default_dbo`" in
33true)
34 extra="$extra --delta-base-offset" ;;
35esac
36
37PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
38PACKTMP="$GIT_DIR/.tmp-$$-pack"
39rm -f "$PACKTMP"-*
40trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
41
42# There will be more repacking strategies to come...
43case ",$all_into_one," in
44,,)
45 args='--unpacked --incremental'
46 ;;
47,t,)
48 args=
49
50 # Redundancy check in all-into-one case is trivial.
51 existing=`test -d "$PACKDIR" && cd "$PACKDIR" && \
52 find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
53 ;;
54esac
55
56args="$args $local $quiet $no_reuse_delta$extra"
57name=$(git-pack-objects --non-empty --all $args </dev/null "$PACKTMP") ||
58 exit 1
59if [ -z "$name" ]; then
60 echo Nothing new to pack.
61else
62 if test "$quiet" != '-q'; then
63 echo "Pack pack-$name created."
64 fi
65 mkdir -p "$PACKDIR" || exit
66
67 for sfx in pack idx
68 do
69 if test -f "$PACKDIR/pack-$name.$sfx"
70 then
71 mv -f "$PACKDIR/pack-$name.$sfx" \
72 "$PACKDIR/old-pack-$name.$sfx"
73 fi
74 done &&
75 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
76 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
77 test -f "$PACKDIR/pack-$name.pack" &&
78 test -f "$PACKDIR/pack-$name.idx" || {
79 echo >&2 "Couldn't replace the existing pack with updated one."
80 echo >&2 "The original set of packs have been saved as"
81 echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
82 exit 1
83 }
84 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
85fi
86
87if test "$remove_redundant" = t
88then
89 # We know $existing are all redundant only when
90 # all-into-one is used.
91 if test "$all_into_one" != '' && test "$existing" != ''
92 then
93 sync
94 ( cd "$PACKDIR" &&
95 for e in $existing
96 do
97 case "$e" in
98 ./pack-$name.pack | ./pack-$name.idx) ;;
99 *) rm -f $e ;;
100 esac
101 done
102 )
103 fi
104 git-prune-packed
105fi
106
107case "$no_update_info" in
108t) : ;;
109*) git-update-server-info ;;
110esac