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