2005-07-04 00:38:01 +04:00
|
|
|
#!/bin/sh
|
2005-08-24 21:40:58 +04:00
|
|
|
#
|
|
|
|
# Copyright (c) 2005 Linus Torvalds
|
|
|
|
#
|
|
|
|
|
2006-10-14 08:28:58 +04:00
|
|
|
USAGE='[-a] [-d] [-f] [-l] [-n] [-q] [--window=N] [--depth=N]'
|
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
|
|
|
|
2006-02-16 22:57:18 +03:00
|
|
|
no_update_info= all_into_one= remove_redundant=
|
2006-04-19 21:05:12 +04:00
|
|
|
local= quiet= no_reuse_delta= extra=
|
2005-08-24 21:40:58 +04:00
|
|
|
while case "$#" in 0) break ;; esac
|
|
|
|
do
|
|
|
|
case "$1" in
|
|
|
|
-n) no_update_info=t ;;
|
2005-08-29 21:29:53 +04:00
|
|
|
-a) all_into_one=t ;;
|
2005-11-17 17:34:47 +03:00
|
|
|
-d) remove_redundant=t ;;
|
2006-02-16 22:57:18 +03:00
|
|
|
-q) quiet=-q ;;
|
|
|
|
-f) no_reuse_delta=--no-reuse-delta ;;
|
|
|
|
-l) local=--local ;;
|
2006-04-19 21:05:12 +04:00
|
|
|
--window=*) extra="$extra $1" ;;
|
|
|
|
--depth=*) extra="$extra $1" ;;
|
2005-12-14 01:30:32 +03:00
|
|
|
*) usage ;;
|
2005-08-24 21:40:58 +04:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2006-10-14 08:28:58 +04:00
|
|
|
# Later we will default repack.UseDeltaBaseOffset to true
|
|
|
|
default_dbo=false
|
|
|
|
|
2007-01-29 03:16:53 +03:00
|
|
|
case "`git config --bool repack.usedeltabaseoffset ||
|
2006-10-14 08:28:58 +04:00
|
|
|
echo $default_dbo`" in
|
|
|
|
true)
|
|
|
|
extra="$extra --delta-base-offset" ;;
|
|
|
|
esac
|
|
|
|
|
2005-08-29 21:29:53 +04:00
|
|
|
PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
|
2006-09-04 09:42:32 +04:00
|
|
|
PACKTMP="$GIT_DIR/.tmp-$$-pack"
|
|
|
|
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
|
|
|
|
[ -z "$args" ] && args='--unpacked --incremental'
|
2005-08-29 21:29:53 +04:00
|
|
|
;;
|
|
|
|
esac
|
2006-09-04 09:42:32 +04:00
|
|
|
|
2006-09-18 13:29:01 +04:00
|
|
|
args="$args $local $quiet $no_reuse_delta$extra"
|
2006-12-19 04:25:28 +03:00
|
|
|
name=$(git-pack-objects --non-empty --all --reflog $args </dev/null "$PACKTMP") ||
|
2005-07-04 00:38:01 +04:00
|
|
|
exit 1
|
2005-08-29 21:29:53 +04:00
|
|
|
if [ -z "$name" ]; then
|
|
|
|
echo Nothing new to pack.
|
2006-05-07 22:18:53 +04:00
|
|
|
else
|
2006-12-14 00:25:26 +03:00
|
|
|
chmod a-w "$PACKTMP-$name.pack"
|
|
|
|
chmod a-w "$PACKTMP-$name.idx"
|
2006-06-24 13:41:25 +04:00
|
|
|
if test "$quiet" != '-q'; then
|
|
|
|
echo "Pack pack-$name created."
|
|
|
|
fi
|
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"
|
2006-05-07 22:18:53 +04:00
|
|
|
fi
|
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
|
|
|
sync
|
|
|
|
( cd "$PACKDIR" &&
|
|
|
|
for e in $existing
|
|
|
|
do
|
2005-11-18 23:36:12 +03:00
|
|
|
case "$e" in
|
2006-10-29 12:37:54 +03:00
|
|
|
pack-$name) ;;
|
|
|
|
*) 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-01-13 02:00:13 +03: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
|