mirror of
https://github.com/git/git.git
synced 2024-11-30 05:23:49 +08:00
25ee9731c1
The only reason we did not call "prune" in git-gc was that it is an inherently dangerous operation: if there is a commit going on, you will prune loose objects that were just created, and are, in fact, needed by the commit object just about to be created. Since it is dangerous, we told users so. That led to many users not even daring to run it when it was actually safe. Besides, they are users, and should not have to remember such details as when to call git-gc with --prune, or to call git-prune directly. Of course, the consequence was that "git gc --auto" gets triggered much more often than we would like, since unreferenced loose objects (such as left-overs from a rebase or a reset --hard) were never pruned. Alas, git-prune recently learnt the option --expire <minimum-age>, which makes it a much safer operation. This allows us to call prune from git-gc, with a grace period of 2 weeks for the unreferenced loose objects (this value was determined in a discussion on the git list as a safe one). If you want to override this grace period, just set the config variable gc.pruneExpire to a different value; an example would be [gc] pruneExpire = 6.months.ago or even "never", if you feel really paranoid. Note that this new behaviour makes "--prune" be a no-op. While adding a test to t5304-prune.sh (since it really tests the implicit call to "prune"), also the original test for "prune --expire" was moved there from t1410-reflog.sh, where it did not belong. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
206 lines
3.7 KiB
Bash
Executable File
206 lines
3.7 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Copyright (c) 2007 Junio C Hamano
|
|
#
|
|
|
|
test_description='Test prune and reflog expiration'
|
|
. ./test-lib.sh
|
|
|
|
check_have () {
|
|
gaah= &&
|
|
for N in "$@"
|
|
do
|
|
eval "o=\$$N" && git cat-file -t $o || {
|
|
echo Gaah $N
|
|
gaah=$N
|
|
break
|
|
}
|
|
done &&
|
|
test -z "$gaah"
|
|
}
|
|
|
|
check_fsck () {
|
|
output=$(git fsck --full)
|
|
case "$1" in
|
|
'')
|
|
test -z "$output" ;;
|
|
*)
|
|
echo "$output" | grep "$1" ;;
|
|
esac
|
|
}
|
|
|
|
corrupt () {
|
|
aa=${1%??????????????????????????????????????} zz=${1#??}
|
|
mv .git/objects/$aa/$zz .git/$aa$zz
|
|
}
|
|
|
|
recover () {
|
|
aa=${1%??????????????????????????????????????} zz=${1#??}
|
|
mkdir -p .git/objects/$aa
|
|
mv .git/$aa$zz .git/objects/$aa/$zz
|
|
}
|
|
|
|
check_dont_have () {
|
|
gaah= &&
|
|
for N in "$@"
|
|
do
|
|
eval "o=\$$N"
|
|
git cat-file -t $o && {
|
|
echo Gaah $N
|
|
gaah=$N
|
|
break
|
|
}
|
|
done
|
|
test -z "$gaah"
|
|
}
|
|
|
|
test_expect_success setup '
|
|
mkdir -p A/B &&
|
|
echo rat >C &&
|
|
echo ox >A/D &&
|
|
echo tiger >A/B/E &&
|
|
git add . &&
|
|
|
|
test_tick && git commit -m rabbit &&
|
|
H=`git rev-parse --verify HEAD` &&
|
|
A=`git rev-parse --verify HEAD:A` &&
|
|
B=`git rev-parse --verify HEAD:A/B` &&
|
|
C=`git rev-parse --verify HEAD:C` &&
|
|
D=`git rev-parse --verify HEAD:A/D` &&
|
|
E=`git rev-parse --verify HEAD:A/B/E` &&
|
|
check_fsck &&
|
|
|
|
chmod +x C &&
|
|
( test "`git config --bool core.filemode`" != false ||
|
|
echo executable >>C ) &&
|
|
git add C &&
|
|
test_tick && git commit -m dragon &&
|
|
L=`git rev-parse --verify HEAD` &&
|
|
check_fsck &&
|
|
|
|
rm -f C A/B/E &&
|
|
echo snake >F &&
|
|
echo horse >A/G &&
|
|
git add F A/G &&
|
|
test_tick && git commit -a -m sheep &&
|
|
F=`git rev-parse --verify HEAD:F` &&
|
|
G=`git rev-parse --verify HEAD:A/G` &&
|
|
I=`git rev-parse --verify HEAD:A` &&
|
|
J=`git rev-parse --verify HEAD` &&
|
|
check_fsck &&
|
|
|
|
rm -f A/G &&
|
|
test_tick && git commit -a -m monkey &&
|
|
K=`git rev-parse --verify HEAD` &&
|
|
check_fsck &&
|
|
|
|
check_have A B C D E F G H I J K L &&
|
|
|
|
git prune &&
|
|
|
|
check_have A B C D E F G H I J K L &&
|
|
|
|
check_fsck &&
|
|
|
|
loglen=$(wc -l <.git/logs/refs/heads/master) &&
|
|
test $loglen = 4
|
|
'
|
|
|
|
test_expect_success rewind '
|
|
test_tick && git reset --hard HEAD~2 &&
|
|
test -f C &&
|
|
test -f A/B/E &&
|
|
! test -f F &&
|
|
! test -f A/G &&
|
|
|
|
check_have A B C D E F G H I J K L &&
|
|
|
|
git prune &&
|
|
|
|
check_have A B C D E F G H I J K L &&
|
|
|
|
loglen=$(wc -l <.git/logs/refs/heads/master) &&
|
|
test $loglen = 5
|
|
'
|
|
|
|
test_expect_success 'corrupt and check' '
|
|
|
|
corrupt $F &&
|
|
check_fsck "missing blob $F"
|
|
|
|
'
|
|
|
|
test_expect_success 'reflog expire --dry-run should not touch reflog' '
|
|
|
|
git reflog expire --dry-run \
|
|
--expire=$(($test_tick - 10000)) \
|
|
--expire-unreachable=$(($test_tick - 10000)) \
|
|
--stale-fix \
|
|
--all &&
|
|
|
|
loglen=$(wc -l <.git/logs/refs/heads/master) &&
|
|
test $loglen = 5 &&
|
|
|
|
check_fsck "missing blob $F"
|
|
'
|
|
|
|
test_expect_success 'reflog expire' '
|
|
|
|
git reflog expire --verbose \
|
|
--expire=$(($test_tick - 10000)) \
|
|
--expire-unreachable=$(($test_tick - 10000)) \
|
|
--stale-fix \
|
|
--all &&
|
|
|
|
loglen=$(wc -l <.git/logs/refs/heads/master) &&
|
|
test $loglen = 2 &&
|
|
|
|
check_fsck "dangling commit $K"
|
|
'
|
|
|
|
test_expect_success 'prune and fsck' '
|
|
|
|
git prune &&
|
|
check_fsck &&
|
|
|
|
check_have A B C D E H L &&
|
|
check_dont_have F G I J K
|
|
|
|
'
|
|
|
|
test_expect_success 'recover and check' '
|
|
|
|
recover $F &&
|
|
check_fsck "dangling blob $F"
|
|
|
|
'
|
|
|
|
test_expect_success 'delete' '
|
|
echo 1 > C &&
|
|
test_tick &&
|
|
git commit -m rat C &&
|
|
|
|
echo 2 > C &&
|
|
test_tick &&
|
|
git commit -m ox C &&
|
|
|
|
echo 3 > C &&
|
|
test_tick &&
|
|
git commit -m tiger C &&
|
|
|
|
test 5 = $(git reflog | wc -l) &&
|
|
|
|
git reflog delete master@{1} &&
|
|
git reflog show master > output &&
|
|
test 4 = $(wc -l < output) &&
|
|
! grep ox < output &&
|
|
|
|
git reflog delete master@{07.04.2005.15:15:00.-0700} &&
|
|
git reflog show master > output &&
|
|
test 3 = $(wc -l < output) &&
|
|
! grep dragon < output
|
|
|
|
'
|
|
|
|
test_done
|