3 # Copyright (c) 2005 Linus Torvalds
7 ## cribbed from git v1.8.3-rc1-26-g8a45db1
14 a pack everything in a single pack
15 A same as -a, and turn unreachable objects loose
16 d remove redundant packs, and run git-prune-packed
17 f pass --no-reuse-delta to git-pack-objects
18 F pass --no-reuse-object to git-pack-objects
19 n do not run git-update-server-info
21 l pass --local to git-pack-objects
22 unpack-unreachable= with -A, do not loosen objects older than this
24 window= size of the window used for delta compression
25 window-memory= same as the above, but limit memory size instead of entries count
26 depth= limits the maximum delta depth
27 max-pack-size= maximum size of each packfile
30 GIT_EXEC_PATH
=$
(git
--exec-path)
31 .
$GIT_EXEC_PATH/git-sh-setup
33 no_update_info
= all_into_one
= remove_redundant
= unpack_unreachable
=
34 local= no_reuse
= extra
=
38 -n) no_update_info
=t
;;
41 unpack_unreachable
=--unpack-unreachable ;;
43 unpack_unreachable
="--unpack-unreachable=$2"; shift ;;
44 -d) remove_redundant
=t
;;
46 -f) no_reuse
=--no-reuse-delta ;;
47 -F) no_reuse
=--no-reuse-object ;;
49 --max-pack-size|
--window|
--window-memory|
--depth)
50 extra
="$extra $1=$2"; shift ;;
57 case "`git config --bool repack.usedeltabaseoffset || echo true`" in
59 extra
="$extra --delta-base-offset" ;;
62 PACKDIR
="$GIT_OBJECT_DIRECTORY/pack"
63 PACKTMP
="$PACKDIR/.tmp-$$-pack"
65 trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
67 # There will be more repacking strategies to come...
68 case ",$all_into_one," in
70 args
='--unpacked --incremental'
74 if [ -d "$PACKDIR" ]; then
75 for e
in `cd "$PACKDIR" && find . -type f -name '*.pack' \
76 | sed -e 's/^\.\///' -e 's/\.pack$//'`
78 if [ -e "$PACKDIR/$e.keep" ]; then
81 existing
="$existing $e"
84 if test -n "$existing" -a -n "$unpack_unreachable" -a \
85 -n "$remove_redundant"
87 # This may have arbitrary user arguments, so we
88 # have to protect it against whitespace splitting
89 # when it gets run as "pack-objects $args" later.
90 # Fortunately, we know it's an approxidate, so we
91 # can just use dots instead.
92 args
="$args $(echo "$unpack_unreachable" | tr ' ' .)"
98 mkdir
-p "$PACKDIR" ||
exit
100 args
="$args $local ${GIT_QUIET:+-q} $no_reuse$extra"
101 # we skip --keep-true-parents so history masked by a graft
103 names
=$
(git pack-objects
--honor-pack-keep --non-empty --all --reflog $args </dev
/null
"$PACKTMP") ||
105 if [ -z "$names" ]; then
106 say Nothing new to pack.
109 # Ok we have prepared all new packfiles.
111 # First see if there are packs of the same name and if so
112 # if we can move them out of the way (this can happen if we
113 # repacked immediately after packing fully.
121 test -f "$PACKDIR/$file" ||
continue
122 rm -f "$PACKDIR/old-$file" &&
123 mv "$PACKDIR/$file" "$PACKDIR/old-$file" ||
{
127 rollback
="$rollback $file"
129 test -z "$failed" ||
break
132 # If renaming failed for any of them, roll the ones we have
133 # already renamed back to their original names.
137 for file in $rollback
139 mv "$PACKDIR/old-$file" "$PACKDIR/$file" ||
140 rollback_failure
="$rollback_failure $file"
142 if test -n "$rollback_failure"
144 echo >&2 "WARNING: Some packs in use have been renamed by"
145 echo >&2 "WARNING: prefixing old- to their name, in order to"
146 echo >&2 "WARNING: replace them with the new version of the"
147 echo >&2 "WARNING: file. But the operation failed, and"
148 echo >&2 "WARNING: attempt to rename them back to their"
149 echo >&2 "WARNING: original names also failed."
150 echo >&2 "WARNING: Please rename them in $PACKDIR manually:"
151 for file in $rollback_failure
153 echo >&2 "WARNING: old-$file -> $file"
159 # Now the ones with the same name are out of the way...
163 fullbases
="$fullbases pack-$name"
164 chmod a-w
"$PACKTMP-$name.pack"
165 chmod a-w
"$PACKTMP-$name.idx"
166 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
167 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" ||
171 # Remove the "old-" files
174 rm -f "$PACKDIR/old-pack-$name.idx"
175 rm -f "$PACKDIR/old-pack-$name.pack"
178 # End of pack replacement.
180 if test "$remove_redundant" = t
182 # We know $existing are all redundant.
183 if [ -n "$existing" ]
188 case " $fullbases " in
190 *) rm -f "$e.pack" "$e.idx" "$e.keep" ;;
195 git prune-packed
${GIT_QUIET:+-q}
198 case "$no_update_info" in
200 *) git update-server-info
;;