2005-07-03 22:38:01 +02:00
|
|
|
#!/bin/sh
|
2005-08-24 19:40:58 +02:00
|
|
|
#
|
|
|
|
# Copyright (c) 2005 Linus Torvalds
|
|
|
|
#
|
|
|
|
|
2007-07-12 14:55:51 +02:00
|
|
|
USAGE='[-a] [-d] [-f] [-l] [-n] [-q] [--max-pack-size=N] [--window=N] [--window-memory=N] [--depth=N]'
|
2006-09-25 04:31:11 +02:00
|
|
|
SUBDIRECTORY_OK='Yes'
|
2005-11-24 09:12:11 +01:00
|
|
|
. git-sh-setup
|
2006-04-19 19:05:12 +02:00
|
|
|
|
2006-02-16 20:57:18 +01:00
|
|
|
no_update_info= all_into_one= remove_redundant=
|
2007-05-09 18:59:40 +02:00
|
|
|
local= quiet= no_reuse= extra=
|
2007-09-23 22:42:08 +02:00
|
|
|
while test $# != 0
|
2005-08-24 19:40:58 +02:00
|
|
|
do
|
|
|
|
case "$1" in
|
|
|
|
-n) no_update_info=t ;;
|
2005-08-29 19:29:53 +02:00
|
|
|
-a) all_into_one=t ;;
|
2005-11-17 15:34:47 +01:00
|
|
|
-d) remove_redundant=t ;;
|
2006-02-16 20:57:18 +01:00
|
|
|
-q) quiet=-q ;;
|
2007-05-09 18:59:40 +02:00
|
|
|
-f) no_reuse=--no-reuse-object ;;
|
2006-02-16 20:57:18 +01:00
|
|
|
-l) local=--local ;;
|
2007-05-13 21:47:09 +02:00
|
|
|
--max-pack-size=*) extra="$extra $1" ;;
|
2006-04-19 19:05:12 +02:00
|
|
|
--window=*) extra="$extra $1" ;;
|
2007-07-12 14:55:51 +02:00
|
|
|
--window-memory=*) extra="$extra $1" ;;
|
2006-04-19 19:05:12 +02:00
|
|
|
--depth=*) extra="$extra $1" ;;
|
2005-12-13 23:30:32 +01:00
|
|
|
*) usage ;;
|
2005-08-24 19:40:58 +02:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2006-10-14 06:28:58 +02:00
|
|
|
# Later we will default repack.UseDeltaBaseOffset to true
|
|
|
|
default_dbo=false
|
|
|
|
|
2007-01-29 01:16:53 +01:00
|
|
|
case "`git config --bool repack.usedeltabaseoffset ||
|
2006-10-14 06:28:58 +02:00
|
|
|
echo $default_dbo`" in
|
|
|
|
true)
|
|
|
|
extra="$extra --delta-base-offset" ;;
|
|
|
|
esac
|
|
|
|
|
2005-08-29 19:29:53 +02:00
|
|
|
PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
|
2007-05-13 21:47:09 +02:00
|
|
|
PACKTMP="$GIT_OBJECT_DIRECTORY/.tmp-$$-pack"
|
2006-09-04 07:42:32 +02:00
|
|
|
rm -f "$PACKTMP"-*
|
|
|
|
trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
|
2005-08-29 19:29:53 +02:00
|
|
|
|
|
|
|
# There will be more repacking strategies to come...
|
|
|
|
case ",$all_into_one," in
|
|
|
|
,,)
|
2006-09-18 11:29:01 +02:00
|
|
|
args='--unpacked --incremental'
|
2005-08-29 19:29:53 +02:00
|
|
|
;;
|
|
|
|
,t,)
|
2006-10-29 10:37:54 +01: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
|
|
|
|
[ -z "$args" ] && args='--unpacked --incremental'
|
2005-08-29 19:29:53 +02:00
|
|
|
;;
|
|
|
|
esac
|
2006-09-04 07:42:32 +02:00
|
|
|
|
2007-05-09 18:59:40 +02:00
|
|
|
args="$args $local $quiet $no_reuse$extra"
|
2007-07-03 07:52:14 +02:00
|
|
|
names=$(git pack-objects --non-empty --all --reflog $args </dev/null "$PACKTMP") ||
|
2005-07-03 22:38:01 +02:00
|
|
|
exit 1
|
2007-05-13 21:47:09 +02:00
|
|
|
if [ -z "$names" ]; then
|
2007-07-03 10:47:58 +02:00
|
|
|
if test -z "$quiet"; then
|
|
|
|
echo Nothing new to pack.
|
|
|
|
fi
|
2007-05-13 21:47:09 +02:00
|
|
|
fi
|
|
|
|
for name in $names ; do
|
2007-05-25 04:06:42 +02:00
|
|
|
fullbases="$fullbases pack-$name"
|
2006-12-13 22:25:26 +01:00
|
|
|
chmod a-w "$PACKTMP-$name.pack"
|
|
|
|
chmod a-w "$PACKTMP-$name.idx"
|
2006-06-24 11:41:25 +02:00
|
|
|
if test "$quiet" != '-q'; then
|
|
|
|
echo "Pack pack-$name created."
|
|
|
|
fi
|
2006-05-07 20:18:53 +02:00
|
|
|
mkdir -p "$PACKDIR" || exit
|
2005-08-29 19:29:53 +02:00
|
|
|
|
2006-06-25 14:28:58 +02: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 07:42:32 +02:00
|
|
|
mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
|
|
|
|
mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
|
2006-06-25 14:28:58 +02: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 21:47:09 +02:00
|
|
|
done
|
2005-08-29 19:29:53 +02:00
|
|
|
|
2005-11-17 15:34:47 +01:00
|
|
|
if test "$remove_redundant" = t
|
2005-08-29 19:29:53 +02:00
|
|
|
then
|
2006-10-29 10:37:54 +01:00
|
|
|
# We know $existing are all redundant.
|
|
|
|
if [ -n "$existing" ]
|
2005-11-18 21:36:12 +01:00
|
|
|
then
|
2005-11-19 21:13:53 +01:00
|
|
|
sync
|
|
|
|
( cd "$PACKDIR" &&
|
|
|
|
for e in $existing
|
|
|
|
do
|
2007-05-25 04:06:42 +02:00
|
|
|
case " $fullbases " in
|
|
|
|
*" $e "*) ;;
|
2006-10-29 10:37:54 +01:00
|
|
|
*) rm -f "$e.pack" "$e.idx" "$e.keep" ;;
|
2005-11-18 21:36:12 +01:00
|
|
|
esac
|
2005-11-19 21:13:53 +01:00
|
|
|
done
|
|
|
|
)
|
2005-08-29 19:29:53 +02:00
|
|
|
fi
|
2007-07-03 07:52:14 +02:00
|
|
|
git prune-packed $quiet
|
2005-08-29 19:29:53 +02:00
|
|
|
fi
|
2005-08-24 19:40:58 +02:00
|
|
|
|
|
|
|
case "$no_update_info" in
|
|
|
|
t) : ;;
|
|
|
|
*) git-update-server-info ;;
|
|
|
|
esac
|