]> git.ipfire.org Git - thirdparty/git.git/blame - git-repack.sh
Add test for git rebase --abort
[thirdparty/git.git] / git-repack.sh
CommitLineData
b2d46199 1#!/bin/sh
ccf1ee32
JH
2#
3# Copyright (c) 2005 Linus Torvalds
4#
5
5715d0bb
PH
6OPTIONS_KEEPDASHDASH=
7OPTIONS_SPEC="\
8git-repack [options]
9--
10a pack everything in a single pack
11A same as -a, and keep unreachable objects too
12d remove redundant packs, and run git-prune-packed
13f pass --no-reuse-delta to git-pack-objects
14q,quiet be quiet
15l pass --local to git-pack-objects
16 Packing constraints
17window= size of the window used for delta compression
18window-memory= same as the above, but limit memory size instead of entries count
19depth= limits the maximum delta depth
20max-pack-size= maximum size of each packfile
21"
d0b353b1 22SUBDIRECTORY_OK='Yes'
ae2b0f15 23. git-sh-setup
ccb36504 24
65aa5302 25no_update_info= all_into_one= remove_redundant= keep_unreachable=
479b56ba 26local= quiet= no_reuse= extra=
822f7c73 27while test $# != 0
ccf1ee32
JH
28do
29 case "$1" in
30 -n) no_update_info=t ;;
d5acdcf1 31 -a) all_into_one=t ;;
65aa5302
JH
32 -A) all_into_one=t
33 keep_unreachable=--keep-unreachable ;;
0adb3358 34 -d) remove_redundant=t ;;
cec2be76 35 -q) quiet=-q ;;
479b56ba 36 -f) no_reuse=--no-reuse-object ;;
cec2be76 37 -l) local=--local ;;
5715d0bb
PH
38 --max-pack-size|--window|--window-memory|--depth)
39 extra="$extra $1=$2"; shift ;;
40 --) shift; break;;
9678faaa 41 *) usage ;;
ccf1ee32
JH
42 esac
43 shift
44done
45
b6945f57
JH
46# Later we will default repack.UseDeltaBaseOffset to true
47default_dbo=false
48
e0d10e1c 49case "`git config --bool repack.usedeltabaseoffset ||
b6945f57
JH
50 echo $default_dbo`" in
51true)
52 extra="$extra --delta-base-offset" ;;
53esac
54
d5acdcf1 55PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
6b94b1a0 56PACKTMP="$GIT_OBJECT_DIRECTORY/.tmp-$$-pack"
0ea2582d
ML
57rm -f "$PACKTMP"-*
58trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
d5acdcf1
JH
59
60# There will be more repacking strategies to come...
61case ",$all_into_one," in
62,,)
cd0d74d2 63 args='--unpacked --incremental'
d5acdcf1
JH
64 ;;
65,t,)
ce859074
SP
66 if [ -d "$PACKDIR" ]; then
67 for e in `cd "$PACKDIR" && find . -type f -name '*.pack' \
68 | sed -e 's/^\.\///' -e 's/\.pack$//'`
69 do
70 if [ -e "$PACKDIR/$e.keep" ]; then
71 : keep
72 else
73 args="$args --unpacked=$e.pack"
74 existing="$existing $e"
75 fi
76 done
77 fi
65aa5302
JH
78 if test -z "$args"
79 then
80 args='--unpacked --incremental'
81 elif test -n "$keep_unreachable"
82 then
83 args="$args $keep_unreachable"
84 fi
d5acdcf1
JH
85 ;;
86esac
0ea2582d 87
479b56ba 88args="$args $local $quiet $no_reuse$extra"
5be60078 89names=$(git pack-objects --non-empty --all --reflog $args </dev/null "$PACKTMP") ||
b2d46199 90 exit 1
6b94b1a0 91if [ -z "$names" ]; then
d9fb395a
UKK
92 if test -z "$quiet"; then
93 echo Nothing new to pack.
94 fi
6b94b1a0
DH
95fi
96for name in $names ; do
dca3957b 97 fullbases="$fullbases pack-$name"
ad2c82c0
NP
98 chmod a-w "$PACKTMP-$name.pack"
99 chmod a-w "$PACKTMP-$name.idx"
178613c7 100 mkdir -p "$PACKDIR" || exit
d5acdcf1 101
2ad47d61
JH
102 for sfx in pack idx
103 do
104 if test -f "$PACKDIR/pack-$name.$sfx"
105 then
106 mv -f "$PACKDIR/pack-$name.$sfx" \
107 "$PACKDIR/old-pack-$name.$sfx"
108 fi
109 done &&
0ea2582d
ML
110 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
111 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
2ad47d61
JH
112 test -f "$PACKDIR/pack-$name.pack" &&
113 test -f "$PACKDIR/pack-$name.idx" || {
114 echo >&2 "Couldn't replace the existing pack with updated one."
115 echo >&2 "The original set of packs have been saved as"
116 echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
117 exit 1
118 }
119 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
6b94b1a0 120done
d5acdcf1 121
0adb3358 122if test "$remove_redundant" = t
d5acdcf1 123then
ce859074
SP
124 # We know $existing are all redundant.
125 if [ -n "$existing" ]
62af0b53 126 then
6ed64058
JH
127 sync
128 ( cd "$PACKDIR" &&
129 for e in $existing
130 do
dca3957b
DH
131 case " $fullbases " in
132 *" $e "*) ;;
ce859074 133 *) rm -f "$e.pack" "$e.idx" "$e.keep" ;;
62af0b53 134 esac
6ed64058
JH
135 done
136 )
d5acdcf1 137 fi
5be60078 138 git prune-packed $quiet
d5acdcf1 139fi
ccf1ee32 140
ccf1ee32
JH
141case "$no_update_info" in
142t) : ;;
143*) git-update-server-info ;;
144esac