]> git.ipfire.org Git - thirdparty/git.git/blame - git-repack.sh
git.el: Avoid a lisp error when there's no current branch (detached HEAD).
[thirdparty/git.git] / git-repack.sh
CommitLineData
b2d46199 1#!/bin/sh
ccf1ee32
JH
2#
3# Copyright (c) 2005 Linus Torvalds
4#
5
121b42a5 6USAGE='[-a] [-d] [-f] [-l] [-n] [-q] [--max-pack-size=N] [--window=N] [--window-memory=N] [--depth=N]'
d0b353b1 7SUBDIRECTORY_OK='Yes'
ae2b0f15 8. git-sh-setup
ccb36504 9
cec2be76 10no_update_info= all_into_one= remove_redundant=
479b56ba 11local= quiet= no_reuse= 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 18 -q) quiet=-q ;;
479b56ba 19 -f) no_reuse=--no-reuse-object ;;
cec2be76 20 -l) local=--local ;;
6b94b1a0 21 --max-pack-size=*) extra="$extra $1" ;;
ccb36504 22 --window=*) extra="$extra $1" ;;
121b42a5 23 --window-memory=*) extra="$extra $1" ;;
ccb36504 24 --depth=*) extra="$extra $1" ;;
9678faaa 25 *) usage ;;
ccf1ee32
JH
26 esac
27 shift
28done
29
b6945f57
JH
30# Later we will default repack.UseDeltaBaseOffset to true
31default_dbo=false
32
e0d10e1c 33case "`git config --bool repack.usedeltabaseoffset ||
b6945f57
JH
34 echo $default_dbo`" in
35true)
36 extra="$extra --delta-base-offset" ;;
37esac
38
d5acdcf1 39PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
6b94b1a0 40PACKTMP="$GIT_OBJECT_DIRECTORY/.tmp-$$-pack"
0ea2582d
ML
41rm -f "$PACKTMP"-*
42trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
d5acdcf1
JH
43
44# There will be more repacking strategies to come...
45case ",$all_into_one," in
46,,)
cd0d74d2 47 args='--unpacked --incremental'
d5acdcf1
JH
48 ;;
49,t,)
ce859074
SP
50 if [ -d "$PACKDIR" ]; then
51 for e in `cd "$PACKDIR" && find . -type f -name '*.pack' \
52 | sed -e 's/^\.\///' -e 's/\.pack$//'`
53 do
54 if [ -e "$PACKDIR/$e.keep" ]; then
55 : keep
56 else
57 args="$args --unpacked=$e.pack"
58 existing="$existing $e"
59 fi
60 done
61 fi
62 [ -z "$args" ] && args='--unpacked --incremental'
d5acdcf1
JH
63 ;;
64esac
0ea2582d 65
479b56ba 66args="$args $local $quiet $no_reuse$extra"
5be60078 67names=$(git pack-objects --non-empty --all --reflog $args </dev/null "$PACKTMP") ||
b2d46199 68 exit 1
6b94b1a0 69if [ -z "$names" ]; then
d9fb395a
UKK
70 if test -z "$quiet"; then
71 echo Nothing new to pack.
72 fi
6b94b1a0
DH
73fi
74for name in $names ; do
dca3957b 75 fullbases="$fullbases pack-$name"
ad2c82c0
NP
76 chmod a-w "$PACKTMP-$name.pack"
77 chmod a-w "$PACKTMP-$name.idx"
1054dcd1
ML
78 if test "$quiet" != '-q'; then
79 echo "Pack pack-$name created."
80 fi
178613c7 81 mkdir -p "$PACKDIR" || exit
d5acdcf1 82
2ad47d61
JH
83 for sfx in pack idx
84 do
85 if test -f "$PACKDIR/pack-$name.$sfx"
86 then
87 mv -f "$PACKDIR/pack-$name.$sfx" \
88 "$PACKDIR/old-pack-$name.$sfx"
89 fi
90 done &&
0ea2582d
ML
91 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
92 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
2ad47d61
JH
93 test -f "$PACKDIR/pack-$name.pack" &&
94 test -f "$PACKDIR/pack-$name.idx" || {
95 echo >&2 "Couldn't replace the existing pack with updated one."
96 echo >&2 "The original set of packs have been saved as"
97 echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
98 exit 1
99 }
100 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
6b94b1a0 101done
d5acdcf1 102
0adb3358 103if test "$remove_redundant" = t
d5acdcf1 104then
ce859074
SP
105 # We know $existing are all redundant.
106 if [ -n "$existing" ]
62af0b53 107 then
6ed64058
JH
108 sync
109 ( cd "$PACKDIR" &&
110 for e in $existing
111 do
dca3957b
DH
112 case " $fullbases " in
113 *" $e "*) ;;
ce859074 114 *) rm -f "$e.pack" "$e.idx" "$e.keep" ;;
62af0b53 115 esac
6ed64058
JH
116 done
117 )
d5acdcf1 118 fi
5be60078 119 git prune-packed $quiet
d5acdcf1 120fi
ccf1ee32 121
ccf1ee32
JH
122case "$no_update_info" in
123t) : ;;
124*) git-update-server-info ;;
125esac