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