Skip to content

Commit d5acdcf

Browse files
author
Junio C Hamano
committed
git-repack-script: Add option to repack all objects.
This originally came from Frank Sorenson, but with a bit of rework to allow future enhancements without changing the external interface for pack pruning part. With the '-a' option, all objects in the current repository are packed into a single pack. When the '-d' option is given at the same time, existing packs that were made redundant by this round of repacking are deleted. Since we currently have only two repacking strategies, one with '-a' (everything into one) and the other without '-a' (incrementally pack only the unpacked ones), the '-d' option is meaningful only when used with '-a'; it removes the packs existed before we did the "everything into one" repacking. At least for now. Signed-off-by: Junio C Hamano <junkio@cox.net> Acked-by: Frank Sorenson <frank@tuxrocks.com> (cherry picked from bfed505327e31221d8de796b3af880bad696b149 commit)
1 parent 8e5dd22 commit d5acdcf

File tree

1 file changed

+43
-8
lines changed

1 file changed

+43
-8
lines changed

git-repack-script

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,63 @@
55

66
. git-sh-setup-script || die "Not a git archive"
77

8-
no_update_info=
8+
no_update_info= all_into_one= remove_redundant=
99
while case "$#" in 0) break ;; esac
1010
do
1111
case "$1" in
1212
-n) no_update_info=t ;;
13+
-a) all_into_one=t ;;
14+
-d) remove_redandant=t ;;
1315
*) break ;;
1416
esac
1517
shift
1618
done
1719

1820
rm -f .tmp-pack-*
19-
packname=$(git-rev-list --unpacked --objects $(git-rev-parse --all) |
20-
git-pack-objects --non-empty --incremental .tmp-pack) ||
21+
PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
22+
23+
# There will be more repacking strategies to come...
24+
case ",$all_into_one," in
25+
,,)
26+
rev_list='--unpacked'
27+
rev_parse='--all'
28+
pack_objects='--incremental'
29+
;;
30+
,t,)
31+
rev_list=
32+
rev_parse='--all'
33+
pack_objects=
34+
# This part is a stop-gap until we have proper pack redundancy
35+
# checker.
36+
existing=`cd "$PACKDIR" && \
37+
find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
38+
;;
39+
esac
40+
name=$(git-rev-list --objects $rev_list $(git-rev-parse $rev_parse) |
41+
git-pack-objects --non-empty $pack_objects .tmp-pack) ||
2142
exit 1
22-
if [ -z "$packname" ]; then
23-
echo Nothing new to pack
43+
if [ -z "$name" ]; then
44+
echo Nothing new to pack.
2445
exit 0
2546
fi
47+
echo "Pack pack-$name created."
48+
49+
mkdir -p "$PACKDIR" || exit
50+
51+
mv .tmp-pack-$name.pack "$PACKDIR/pack-$name.pack" &&
52+
mv .tmp-pack-$name.idx "$PACKDIR/pack-$name.idx" ||
53+
exit
54+
55+
if test "$remove_redandant" = t
56+
then
57+
# We know $existing are all redandant only when
58+
# all-into-one is used.
59+
if test "$all_into_one" != '' && test "$existing" != ''
60+
then
61+
( cd "$PACKDIR" && rm -f $existing )
62+
fi
63+
fi
2664

27-
mkdir -p "$GIT_OBJECT_DIRECTORY/pack" &&
28-
mv .tmp-pack-$packname.pack "$GIT_OBJECT_DIRECTORY/pack/pack-$packname.pack" &&
29-
mv .tmp-pack-$packname.idx "$GIT_OBJECT_DIRECTORY/pack/pack-$packname.idx" &&
3065
case "$no_update_info" in
3166
t) : ;;
3267
*) git-update-server-info ;;

0 commit comments

Comments
 (0)