Allow short pack names to git-pack-objects --unpacked=.
[git/git.git] / git-repack.sh
CommitLineData
b2d46199 1#!/bin/sh
ccf1ee32
JH
2#
3# Copyright (c) 2005 Linus Torvalds
4#
5
b6945f57 6USAGE='[-a] [-d] [-f] [-l] [-n] [-q] [--window=N] [--depth=N]'
d0b353b1 7SUBDIRECTORY_OK='Yes'
ae2b0f15 8. git-sh-setup
ccb36504 9
cec2be76 10no_update_info= all_into_one= remove_redundant=
ccb36504 11local= quiet= no_reuse_delta= extra=
ccf1ee32
JH
12while case "$#" in 0) break ;; esac
13do
14 case "$1" in
15 -n) no_update_info=t ;;
d5acdcf1 16 -a) all_into_one=t ;;
0adb3358 17 -d) remove_redundant=t ;;
cec2be76
JH
18 -q) quiet=-q ;;
19 -f) no_reuse_delta=--no-reuse-delta ;;
20 -l) local=--local ;;
ccb36504
LT
21 --window=*) extra="$extra $1" ;;
22 --depth=*) extra="$extra $1" ;;
9678faaa 23 *) usage ;;
ccf1ee32
JH
24 esac
25 shift
26done
27
b6945f57
JH
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
d5acdcf1 37PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
0ea2582d
ML
38PACKTMP="$GIT_DIR/.tmp-$$-pack"
39rm -f "$PACKTMP"-*
40trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
d5acdcf1
JH
41
42# There will be more repacking strategies to come...
43case ",$all_into_one," in
44,,)
cd0d74d2 45 args='--unpacked --incremental'
d5acdcf1
JH
46 ;;
47,t,)
cd0d74d2 48 args=
6ed64058
JH
49
50 # Redundancy check in all-into-one case is trivial.
9e848013 51 existing=`test -d "$PACKDIR" && cd "$PACKDIR" && \
6ed64058 52 find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
d5acdcf1
JH
53 ;;
54esac
0ea2582d 55
cd0d74d2
JH
56args="$args $local $quiet $no_reuse_delta$extra"
57name=$(git-pack-objects --non-empty --all $args </dev/null "$PACKTMP") ||
b2d46199 58 exit 1
d5acdcf1
JH
59if [ -z "$name" ]; then
60 echo Nothing new to pack.
178613c7 61else
1054dcd1
ML
62 if test "$quiet" != '-q'; then
63 echo "Pack pack-$name created."
64 fi
178613c7 65 mkdir -p "$PACKDIR" || exit
d5acdcf1 66
2ad47d61
JH
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 &&
0ea2582d
ML
75 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
76 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
2ad47d61
JH
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"
178613c7 85fi
d5acdcf1 86
0adb3358 87if test "$remove_redundant" = t
d5acdcf1 88then
6ed64058
JH
89 # We know $existing are all redundant only when
90 # all-into-one is used.
91 if test "$all_into_one" != '' && test "$existing" != ''
62af0b53 92 then
6ed64058
JH
93 sync
94 ( cd "$PACKDIR" &&
95 for e in $existing
96 do
62af0b53
LS
97 case "$e" in
98 ./pack-$name.pack | ./pack-$name.idx) ;;
6ed64058 99 *) rm -f $e ;;
62af0b53 100 esac
6ed64058
JH
101 done
102 )
d5acdcf1 103 fi
2d0048e6 104 git-prune-packed
d5acdcf1 105fi
ccf1ee32 106
ccf1ee32
JH
107case "$no_update_info" in
108t) : ;;
109*) git-update-server-info ;;
110esac