Skip to content

Commit

Permalink
[gc] do gc anyway. Contributes to MER#1285
Browse files Browse the repository at this point in the history
Do gc even if there was no tree cleanup, so if backup operation was not
finished (snapshot was not created) but head was reset to the previous snapshot,
unreferenced commits from the old head will be removed.

Signed-off-by: Denis Zalevskiy <denis.zalevskiy@jolla.com>
  • Loading branch information
Denis Zalevskiy committed Sep 18, 2015
1 parent 8e11134 commit 1d44135
Showing 1 changed file with 41 additions and 27 deletions.
68 changes: 41 additions & 27 deletions tools/git-vault-gc
Expand Up @@ -63,30 +63,59 @@ function gen_cmd {
cat $cmd_file | gawk -f $src/git-vault-rebase-generate.awk
}

function git_gc {
echo "GC"
git prune
git gc --aggressive
echo "PRUNE+"
git prune
}

function git_clear_reflog {
echo "CLEAR REFLOG"
git reflog expire --expire=now --all || error "clearing reflog"
}

function git_rm_dangling_blobs {
echo "REMOVING DANGLING BLOBS"
for obj in $(git fsck --unreachable master \
| grep '^unreachable blob' \
| sed 's/unreachable blob //'); do
for blob in $(git show $obj \
| head -n 1 \
| grep '\.\./\.git/blobs' \
| sed 's:^[./]*\.git/blobs:.git/blobs:'); do
echo "Orphan $blob"
(test -f $blob && (rm $blob -f || echo "Can't remove $blob")) \
|| echo "No such blob $blob"
done
done
}

function git_prune_all_unreferenced {
git_clear_reflog
git_rm_dangling_blobs
git_gc
}

if ($dump || $dump_intention); then
$dump_intention && cat $cmd_file
$dump && gen_cmd
exit 0
fi

if ! grep '^\(old_tag\|skip\)' $cmd_file; then
echo "There is no need in gc for the $root"
echo "There is no need in tree clean-up for the $root"
if ! $force; then
echo "Just checking for dangling blobs and doing gc"
git_prune_all_unreferenced
exit 0
fi
echo "Forcing gc"
echo "Forcing tree clean-up and gc"
fi

cmd=$(gen_cmd)

function git_gc {
echo "GC"
git prune
git gc --aggressive
echo "PRUNE+"
git prune
}

function rollback {
echo "ROLLBACK"
git reset --hard
Expand All @@ -111,21 +140,6 @@ echo "REPLACE MASTER"
git branch -m migrated master && \
git branch -D old-master) || error "replacing master"

echo "CLEAR REFLOG"
git reflog expire --expire=now --all || error "clearing reflog"

echo "REMOVING DANGLING BLOBS"
for obj in $(git fsck --unreachable master \
| grep '^unreachable blob' \
| sed 's/unreachable blob //'); do
for blob in $(git show $obj \
| head -n 1 \
| grep '\.\./\.git/blobs' \
| sed 's:^[./]*\.git/blobs:.git/blobs:'); do
echo "Orphan $blob"
(test -f $blob && (rm $blob -f || echo "Can't remove $blob")) \
|| echo "No such blob $blob"
done
done
git_gc
git_prune_all_unreferenced

echo "OK"

0 comments on commit 1d44135

Please sign in to comment.