2005-07-04 04:38:01 +08:00
|
|
|
#!/bin/sh
|
2005-08-25 01:40:58 +08:00
|
|
|
#
|
|
|
|
# Copyright (c) 2005 Linus Torvalds
|
|
|
|
#
|
|
|
|
|
2007-11-04 18:31:02 +08:00
|
|
|
OPTIONS_KEEPDASHDASH=
|
|
|
|
OPTIONS_SPEC="\
|
2008-07-13 21:36:15 +08:00
|
|
|
git repack [options]
|
2007-11-04 18:31:02 +08:00
|
|
|
--
|
|
|
|
a pack everything in a single pack
|
2008-05-14 13:33:53 +08:00
|
|
|
A same as -a, and turn unreachable objects loose
|
2007-11-04 18:31:02 +08:00
|
|
|
d remove redundant packs, and run git-prune-packed
|
2010-09-27 20:19:36 +08:00
|
|
|
f pass --no-reuse-delta to git-pack-objects
|
|
|
|
F pass --no-reuse-object to git-pack-objects
|
2008-05-11 04:52:51 +08:00
|
|
|
n do not run git-update-server-info
|
2007-11-04 18:31:02 +08:00
|
|
|
q,quiet be quiet
|
|
|
|
l pass --local to git-pack-objects
|
2012-04-07 18:30:09 +08:00
|
|
|
unpack-unreachable= with -A, do not loosen objects older than this
|
2007-11-04 18:31:02 +08:00
|
|
|
Packing constraints
|
|
|
|
window= size of the window used for delta compression
|
|
|
|
window-memory= same as the above, but limit memory size instead of entries count
|
|
|
|
depth= limits the maximum delta depth
|
|
|
|
max-pack-size= maximum size of each packfile
|
|
|
|
"
|
2006-09-25 10:31:11 +08:00
|
|
|
SUBDIRECTORY_OK='Yes'
|
2005-11-24 16:12:11 +08:00
|
|
|
. git-sh-setup
|
2006-04-20 01:05:12 +08:00
|
|
|
|
2008-05-14 13:33:53 +08:00
|
|
|
no_update_info= all_into_one= remove_redundant= unpack_unreachable=
|
2009-06-17 06:33:00 +08:00
|
|
|
local= no_reuse= extra=
|
2007-09-24 04:42:08 +08:00
|
|
|
while test $# != 0
|
2005-08-25 01:40:58 +08:00
|
|
|
do
|
|
|
|
case "$1" in
|
|
|
|
-n) no_update_info=t ;;
|
2005-08-30 01:29:53 +08:00
|
|
|
-a) all_into_one=t ;;
|
2007-09-17 14:24:07 +08:00
|
|
|
-A) all_into_one=t
|
2008-05-14 13:33:53 +08:00
|
|
|
unpack_unreachable=--unpack-unreachable ;;
|
2012-04-07 18:30:09 +08:00
|
|
|
--unpack-unreachable)
|
|
|
|
unpack_unreachable="--unpack-unreachable=$2"; shift ;;
|
2005-11-17 22:34:47 +08:00
|
|
|
-d) remove_redundant=t ;;
|
2009-06-17 06:33:00 +08:00
|
|
|
-q) GIT_QUIET=t ;;
|
2010-09-27 20:19:36 +08:00
|
|
|
-f) no_reuse=--no-reuse-delta ;;
|
|
|
|
-F) no_reuse=--no-reuse-object ;;
|
2006-02-17 03:57:18 +08:00
|
|
|
-l) local=--local ;;
|
2007-11-04 18:31:02 +08:00
|
|
|
--max-pack-size|--window|--window-memory|--depth)
|
|
|
|
extra="$extra $1=$2"; shift ;;
|
|
|
|
--) shift; break;;
|
2005-12-14 06:30:32 +08:00
|
|
|
*) usage ;;
|
2005-08-25 01:40:58 +08:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2008-06-25 12:24:53 +08:00
|
|
|
case "`git config --bool repack.usedeltabaseoffset || echo true`" in
|
2006-10-14 12:28:58 +08:00
|
|
|
true)
|
|
|
|
extra="$extra --delta-base-offset" ;;
|
|
|
|
esac
|
|
|
|
|
2005-08-30 01:29:53 +08:00
|
|
|
PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
|
2010-10-19 17:50:43 +08:00
|
|
|
PACKTMP="$PACKDIR/.tmp-$$-pack"
|
2006-09-04 13:42:32 +08:00
|
|
|
rm -f "$PACKTMP"-*
|
|
|
|
trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
|
2005-08-30 01:29:53 +08:00
|
|
|
|
|
|
|
# There will be more repacking strategies to come...
|
|
|
|
case ",$all_into_one," in
|
|
|
|
,,)
|
2006-09-18 17:29:01 +08:00
|
|
|
args='--unpacked --incremental'
|
2005-08-30 01:29:53 +08:00
|
|
|
;;
|
|
|
|
,t,)
|
2009-02-28 15:58:50 +08:00
|
|
|
args= existing=
|
2006-10-29 17:37:54 +08:00
|
|
|
if [ -d "$PACKDIR" ]; then
|
|
|
|
for e in `cd "$PACKDIR" && find . -type f -name '*.pack' \
|
|
|
|
| sed -e 's/^\.\///' -e 's/\.pack$//'`
|
|
|
|
do
|
|
|
|
if [ -e "$PACKDIR/$e.keep" ]; then
|
|
|
|
: keep
|
|
|
|
else
|
|
|
|
existing="$existing $e"
|
|
|
|
fi
|
|
|
|
done
|
2009-03-20 11:47:51 +08:00
|
|
|
if test -n "$existing" -a -n "$unpack_unreachable" -a \
|
2008-11-14 04:11:46 +08:00
|
|
|
-n "$remove_redundant"
|
2008-11-13 01:59:06 +08:00
|
|
|
then
|
2012-04-07 18:30:09 +08:00
|
|
|
# This may have arbitrary user arguments, so we
|
|
|
|
# have to protect it against whitespace splitting
|
|
|
|
# when it gets run as "pack-objects $args" later.
|
|
|
|
# Fortunately, we know it's an approxidate, so we
|
|
|
|
# can just use dots instead.
|
|
|
|
args="$args $(echo "$unpack_unreachable" | tr ' ' .)"
|
2008-11-13 01:59:06 +08:00
|
|
|
fi
|
2007-09-17 14:24:07 +08:00
|
|
|
fi
|
2005-08-30 01:29:53 +08:00
|
|
|
;;
|
|
|
|
esac
|
2006-09-04 13:42:32 +08:00
|
|
|
|
2010-10-19 17:50:43 +08:00
|
|
|
mkdir -p "$PACKDIR" || exit
|
|
|
|
|
2009-06-17 06:33:00 +08:00
|
|
|
args="$args $local ${GIT_QUIET:+-q} $no_reuse$extra"
|
2009-07-23 23:33:49 +08:00
|
|
|
names=$(git pack-objects --keep-true-parents --honor-pack-keep --non-empty --all --reflog $args </dev/null "$PACKTMP") ||
|
2005-07-04 04:38:01 +08:00
|
|
|
exit 1
|
2007-05-14 03:47:09 +08:00
|
|
|
if [ -z "$names" ]; then
|
2009-06-17 06:33:00 +08:00
|
|
|
say Nothing new to pack.
|
2007-05-14 03:47:09 +08:00
|
|
|
fi
|
2005-08-30 01:29:53 +08:00
|
|
|
|
2009-02-11 04:16:31 +08:00
|
|
|
# Ok we have prepared all new packfiles.
|
|
|
|
|
|
|
|
# First see if there are packs of the same name and if so
|
|
|
|
# if we can move them out of the way (this can happen if we
|
|
|
|
# repacked immediately after packing fully.
|
|
|
|
rollback=
|
|
|
|
failed=
|
|
|
|
for name in $names
|
|
|
|
do
|
2006-06-25 20:28:58 +08:00
|
|
|
for sfx in pack idx
|
|
|
|
do
|
2009-02-11 04:16:31 +08:00
|
|
|
file=pack-$name.$sfx
|
|
|
|
test -f "$PACKDIR/$file" || continue
|
|
|
|
rm -f "$PACKDIR/old-$file" &&
|
|
|
|
mv "$PACKDIR/$file" "$PACKDIR/old-$file" || {
|
|
|
|
failed=t
|
|
|
|
break
|
|
|
|
}
|
|
|
|
rollback="$rollback $file"
|
|
|
|
done
|
|
|
|
test -z "$failed" || break
|
|
|
|
done
|
|
|
|
|
|
|
|
# If renaming failed for any of them, roll the ones we have
|
|
|
|
# already renamed back to their original names.
|
|
|
|
if test -n "$failed"
|
|
|
|
then
|
|
|
|
rollback_failure=
|
|
|
|
for file in $rollback
|
|
|
|
do
|
|
|
|
mv "$PACKDIR/old-$file" "$PACKDIR/$file" ||
|
|
|
|
rollback_failure="$rollback_failure $file"
|
|
|
|
done
|
|
|
|
if test -n "$rollback_failure"
|
|
|
|
then
|
|
|
|
echo >&2 "WARNING: Some packs in use have been renamed by"
|
|
|
|
echo >&2 "WARNING: prefixing old- to their name, in order to"
|
|
|
|
echo >&2 "WARNING: replace them with the new version of the"
|
|
|
|
echo >&2 "WARNING: file. But the operation failed, and"
|
|
|
|
echo >&2 "WARNING: attempt to rename them back to their"
|
|
|
|
echo >&2 "WARNING: original names also failed."
|
|
|
|
echo >&2 "WARNING: Please rename them in $PACKDIR manually:"
|
|
|
|
for file in $rollback_failure
|
|
|
|
do
|
|
|
|
echo >&2 "WARNING: old-$file -> $file"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Now the ones with the same name are out of the way...
|
|
|
|
fullbases=
|
|
|
|
for name in $names
|
|
|
|
do
|
|
|
|
fullbases="$fullbases pack-$name"
|
|
|
|
chmod a-w "$PACKTMP-$name.pack"
|
|
|
|
chmod a-w "$PACKTMP-$name.idx"
|
2006-09-04 13:42:32 +08:00
|
|
|
mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
|
2009-02-11 04:16:31 +08:00
|
|
|
mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" ||
|
|
|
|
exit
|
|
|
|
done
|
|
|
|
|
|
|
|
# Remove the "old-" files
|
|
|
|
for name in $names
|
|
|
|
do
|
|
|
|
rm -f "$PACKDIR/old-pack-$name.idx"
|
|
|
|
rm -f "$PACKDIR/old-pack-$name.pack"
|
2007-05-14 03:47:09 +08:00
|
|
|
done
|
2005-08-30 01:29:53 +08:00
|
|
|
|
2009-02-11 04:16:31 +08:00
|
|
|
# End of pack replacement.
|
|
|
|
|
2005-11-17 22:34:47 +08:00
|
|
|
if test "$remove_redundant" = t
|
2005-08-30 01:29:53 +08:00
|
|
|
then
|
2006-10-29 17:37:54 +08:00
|
|
|
# We know $existing are all redundant.
|
|
|
|
if [ -n "$existing" ]
|
2005-11-19 04:36:12 +08:00
|
|
|
then
|
2005-11-20 04:13:53 +08:00
|
|
|
( cd "$PACKDIR" &&
|
|
|
|
for e in $existing
|
|
|
|
do
|
2007-05-25 10:06:42 +08:00
|
|
|
case " $fullbases " in
|
|
|
|
*" $e "*) ;;
|
2006-10-29 17:37:54 +08:00
|
|
|
*) rm -f "$e.pack" "$e.idx" "$e.keep" ;;
|
2005-11-19 04:36:12 +08:00
|
|
|
esac
|
2005-11-20 04:13:53 +08:00
|
|
|
done
|
|
|
|
)
|
2005-08-30 01:29:53 +08:00
|
|
|
fi
|
2009-06-17 06:33:00 +08:00
|
|
|
git prune-packed ${GIT_QUIET:+-q}
|
2005-08-30 01:29:53 +08:00
|
|
|
fi
|
2005-08-25 01:40:58 +08:00
|
|
|
|
|
|
|
case "$no_update_info" in
|
|
|
|
t) : ;;
|
2009-04-05 00:59:55 +08:00
|
|
|
*) git update-server-info ;;
|
2005-08-25 01:40:58 +08:00
|
|
|
esac
|