packv4: nth_packed_object_sha1() packv4 support
[git/packv4.git] / git-repack.sh
blobf24924f4adff0e340809808f61e925e78f838458
1 #!/bin/sh
3 # Copyright (c) 2005 Linus Torvalds
6 USAGE='[-a] [-d] [-f] [-l] [-n] [-q] [--max-pack-size=N] [--window=N] [--window-memory=N] [--depth=N] [--pack-version=N]'
7 SUBDIRECTORY_OK='Yes'
8 . git-sh-setup
10 no_update_info= all_into_one= remove_redundant=
11 local= quiet= no_reuse= extra=
12 while case "$#" in 0) break ;; esac
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=--no-reuse-object ;;
20 -l) local=--local ;;
21 --max-pack-size=*) extra="$extra $1" ;;
22 --window=*) extra="$extra $1" ;;
23 --window-memory=*) extra="$extra $1" ;;
24 --depth=*) extra="$extra $1" ;;
25 --pack-version=*) extra="$extra $1" ;;
26 *) usage ;;
27 esac
28 shift
29 done
31 # Later we will default repack.UseDeltaBaseOffset to true
32 default_dbo=false
34 case "`git config --bool repack.usedeltabaseoffset ||
35 echo $default_dbo`" in
36 true)
37 extra="$extra --delta-base-offset" ;;
38 esac
40 PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
41 PACKTMP="$GIT_OBJECT_DIRECTORY/.tmp-$$-pack"
42 rm -f "$PACKTMP"-*
43 trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
45 # There will be more repacking strategies to come...
46 case ",$all_into_one," in
47 ,,)
48 args='--unpacked --incremental'
50 ,t,)
51 if [ -d "$PACKDIR" ]; then
52 for e in `cd "$PACKDIR" && find . -type f -name '*.pack' \
53 | sed -e 's/^\.\///' -e 's/\.pack$//'`
55 if [ -e "$PACKDIR/$e.keep" ]; then
56 : keep
57 else
58 args="$args --unpacked=$e.pack"
59 existing="$existing $e"
61 done
63 [ -z "$args" ] && args='--unpacked --incremental'
65 esac
67 args="$args $local $quiet $no_reuse$extra"
68 names=$(git pack-objects --non-empty --all --reflog $args </dev/null "$PACKTMP") ||
69 exit 1
70 if [ -z "$names" ]; then
71 if test -z "$quiet"; then
72 echo Nothing new to pack.
75 for name in $names ; do
76 fullbases="$fullbases pack-$name"
77 chmod a-w "$PACKTMP-$name.pack"
78 chmod a-w "$PACKTMP-$name.idx"
79 if test "$quiet" != '-q'; then
80 echo "Pack pack-$name created."
82 mkdir -p "$PACKDIR" || exit
84 for sfx in pack idx
86 if test -f "$PACKDIR/pack-$name.$sfx"
87 then
88 mv -f "$PACKDIR/pack-$name.$sfx" \
89 "$PACKDIR/old-pack-$name.$sfx"
91 done &&
92 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
93 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
94 test -f "$PACKDIR/pack-$name.pack" &&
95 test -f "$PACKDIR/pack-$name.idx" || {
96 echo >&2 "Couldn't replace the existing pack with updated one."
97 echo >&2 "The original set of packs have been saved as"
98 echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
99 exit 1
101 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
102 done
104 if test "$remove_redundant" = t
105 then
106 # We know $existing are all redundant.
107 if [ -n "$existing" ]
108 then
109 sync
110 ( cd "$PACKDIR" &&
111 for e in $existing
113 case " $fullbases " in
114 *" $e "*) ;;
115 *) rm -f "$e.pack" "$e.idx" "$e.keep" ;;
116 esac
117 done
120 git prune-packed $quiet
123 case "$no_update_info" in
124 t) : ;;
125 *) git-update-server-info ;;
126 esac