2005-07-04 00:38:01 +04:00
|
|
|
#!/bin/sh
|
2005-08-24 21:40:58 +04:00
|
|
|
#
|
|
|
|
# Copyright (c) 2005 Linus Torvalds
|
|
|
|
#
|
|
|
|
|
2007-11-04 13:31:02 +03:00
|
|
|
OPTIONS_KEEPDASHDASH=
|
|
|
|
OPTIONS_SPEC="\
|
2008-07-13 17:36:15 +04:00
|
|
|
git repack [options]
|
2007-11-04 13:31:02 +03:00
|
|
|
--
|
|
|
|
a pack everything in a single pack
|
2008-05-14 09:33:53 +04:00
|
|
|
A same as -a, and turn unreachable objects loose
|
2007-11-04 13:31:02 +03:00
|
|
|
d remove redundant packs, and run git-prune-packed
|
2008-09-19 17:43:48 +04:00
|
|
|
f pass --no-reuse-object to git-pack-objects
|
2008-05-11 00:52:51 +04:00
|
|
|
n do not run git-update-server-info
|
2007-11-04 13:31:02 +03:00
|
|
|
q,quiet be quiet
|
|
|
|
l pass --local to git-pack-objects
|
|
|
|
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 06:31:11 +04:00
|
|
|
SUBDIRECTORY_OK='Yes'
|
2005-11-24 11:12:11 +03:00
|
|
|
. git-sh-setup
|
2006-04-19 21:05:12 +04:00
|
|
|
|
2008-05-14 09:33:53 +04:00
|
|
|
no_update_info= all_into_one= remove_redundant= unpack_unreachable=
|
2007-05-09 20:59:40 +04:00
|
|
|
local= quiet= no_reuse= extra=
|
2007-09-24 00:42:08 +04:00
|
|
|
while test $# != 0
|
2005-08-24 21:40:58 +04:00
|
|
|
do
|
|
|
|
case "$1" in
|
|
|
|
-n) no_update_info=t ;;
|
2005-08-29 21:29:53 +04:00
|
|
|
-a) all_into_one=t ;;
|
2007-09-17 10:24:07 +04:00
|
|
|
-A) all_into_one=t
|
2008-05-14 09:33:53 +04:00
|
|
|
unpack_unreachable=--unpack-unreachable ;;
|
2005-11-17 17:34:47 +03:00
|
|
|
-d) remove_redundant=t ;;
|
2006-02-16 22:57:18 +03:00
|
|
|
-q) quiet=-q ;;
|
2007-05-09 20:59:40 +04:00
|
|
|
-f) no_reuse=--no-reuse-object ;;
|
2006-02-16 22:57:18 +03:00
|
|
|
-l) local=--local ;;
|
2007-11-04 13:31:02 +03:00
|
|
|
--max-pack-size|--window|--window-memory|--depth)
|
|
|
|
extra="$extra $1=$2"; shift ;;
|
|
|
|
--) shift; break;;
|
2005-12-14 01:30:32 +03:00
|
|
|
*) usage ;;
|
2005-08-24 21:40:58 +04:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2008-06-25 08:24:53 +04:00
|
|
|
case "`git config --bool repack.usedeltabaseoffset || echo true`" in
|
2006-10-14 08:28:58 +04:00
|
|
|
true)
|
|
|
|
extra="$extra --delta-base-offset" ;;
|
|
|
|
esac
|
|
|
|
|
2005-08-29 21:29:53 +04:00
|
|
|
PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
|
2007-05-13 23:47:09 +04:00
|
|
|
PACKTMP="$GIT_OBJECT_DIRECTORY/.tmp-$$-pack"
|
2006-09-04 09:42:32 +04:00
|
|
|
rm -f "$PACKTMP"-*
|
|
|
|
trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
|
2005-08-29 21:29:53 +04:00
|
|
|
|
|
|
|
# There will be more repacking strategies to come...
|
|
|
|
case ",$all_into_one," in
|
|
|
|
,,)
|
2006-09-18 13:29:01 +04:00
|
|
|
args='--unpacked --incremental'
|
2005-08-29 21:29:53 +04:00
|
|
|
;;
|
|
|
|
,t,)
|
2006-10-29 12:37:54 +03: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
|
|
|
|
args="$args --unpacked=$e.pack"
|
|
|
|
existing="$existing $e"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2007-09-17 10:24:07 +04:00
|
|
|
if test -z "$args"
|
|
|
|
then
|
|
|
|
args='--unpacked --incremental'
|
2008-05-14 09:33:53 +04:00
|
|
|
elif test -n "$unpack_unreachable"
|
2007-09-17 10:24:07 +04:00
|
|
|
then
|
2008-05-14 09:33:53 +04:00
|
|
|
args="$args $unpack_unreachable"
|
2007-09-17 10:24:07 +04:00
|
|
|
fi
|
2005-08-29 21:29:53 +04:00
|
|
|
;;
|
|
|
|
esac
|
2006-09-04 09:42:32 +04:00
|
|
|
|
2007-05-09 20:59:40 +04:00
|
|
|
args="$args $local $quiet $no_reuse$extra"
|
2007-07-03 09:52:14 +04:00
|
|
|
names=$(git pack-objects --non-empty --all --reflog $args </dev/null "$PACKTMP") ||
|
2005-07-04 00:38:01 +04:00
|
|
|
exit 1
|
2007-05-13 23:47:09 +04:00
|
|
|
if [ -z "$names" ]; then
|
2007-07-03 12:47:58 +04:00
|
|
|
if test -z "$quiet"; then
|
|
|
|
echo Nothing new to pack.
|
|
|
|
fi
|
2007-05-13 23:47:09 +04:00
|
|
|
fi
|
|
|
|
for name in $names ; do
|
2007-05-25 06:06:42 +04:00
|
|
|
fullbases="$fullbases pack-$name"
|
2006-12-14 00:25:26 +03:00
|
|
|
chmod a-w "$PACKTMP-$name.pack"
|
|
|
|
chmod a-w "$PACKTMP-$name.idx"
|
2006-05-07 22:18:53 +04:00
|
|
|
mkdir -p "$PACKDIR" || exit
|
2005-08-29 21:29:53 +04:00
|
|
|
|
2006-06-25 16:28:58 +04:00
|
|
|
for sfx in pack idx
|
|
|
|
do
|
|
|
|
if test -f "$PACKDIR/pack-$name.$sfx"
|
|
|
|
then
|
|
|
|
mv -f "$PACKDIR/pack-$name.$sfx" \
|
|
|
|
"$PACKDIR/old-pack-$name.$sfx"
|
|
|
|
fi
|
|
|
|
done &&
|
2006-09-04 09:42:32 +04:00
|
|
|
mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
|
|
|
|
mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
|
2006-06-25 16:28:58 +04:00
|
|
|
test -f "$PACKDIR/pack-$name.pack" &&
|
|
|
|
test -f "$PACKDIR/pack-$name.idx" || {
|
|
|
|
echo >&2 "Couldn't replace the existing pack with updated one."
|
|
|
|
echo >&2 "The original set of packs have been saved as"
|
|
|
|
echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
|
2007-05-13 23:47:09 +04:00
|
|
|
done
|
2005-08-29 21:29:53 +04:00
|
|
|
|
2005-11-17 17:34:47 +03:00
|
|
|
if test "$remove_redundant" = t
|
2005-08-29 21:29:53 +04:00
|
|
|
then
|
2006-10-29 12:37:54 +03:00
|
|
|
# We know $existing are all redundant.
|
|
|
|
if [ -n "$existing" ]
|
2005-11-18 23:36:12 +03:00
|
|
|
then
|
2005-11-19 23:13:53 +03:00
|
|
|
( cd "$PACKDIR" &&
|
|
|
|
for e in $existing
|
|
|
|
do
|
2007-05-25 06:06:42 +04:00
|
|
|
case " $fullbases " in
|
|
|
|
*" $e "*) ;;
|
2006-10-29 12:37:54 +03:00
|
|
|
*) rm -f "$e.pack" "$e.idx" "$e.keep" ;;
|
2005-11-18 23:36:12 +03:00
|
|
|
esac
|
2005-11-19 23:13:53 +03:00
|
|
|
done
|
|
|
|
)
|
2005-08-29 21:29:53 +04:00
|
|
|
fi
|
2007-07-03 09:52:14 +04:00
|
|
|
git prune-packed $quiet
|
2005-08-29 21:29:53 +04:00
|
|
|
fi
|
2005-08-24 21:40:58 +04:00
|
|
|
|
|
|
|
case "$no_update_info" in
|
|
|
|
t) : ;;
|
|
|
|
*) git-update-server-info ;;
|
|
|
|
esac
|