Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from deztructor/vault-gc
Garbage collection support
- Loading branch information
Showing
14 changed files
with
370 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,5 @@ units/vault-* | |
*.moc | ||
tests/tests.xml | ||
tests/*_unit.cpp | ||
tests/*_vault_test | ||
tests/*_vault_test | ||
src/config.hpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef _SRC_VAULT_CONFIG_HPP_ | ||
#define _SRC_VAULT_CONFIG_HPP_ | ||
|
||
#define VAULT_LIBEXEC_PATH "@prefix@/libexec/vault" | ||
|
||
#endif // _SRC_VAULT_CONFIG_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
configure_file(vault-gc.service.in vault-gc.service @ONLY) | ||
|
||
install( | ||
PROGRAMS git-vault-gc gc-default | ||
DESTINATION libexec/vault | ||
) | ||
|
||
install( | ||
FILES git-vault-rebase-generate.awk git-vault-rebase-prepare.awk | ||
DESTINATION libexec/vault | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
/usr/bin/vault -H $HOME -V $HOME/.vault -a gc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#!/bin/bash | ||
|
||
function error { | ||
echo "`basename $0`: Error: ${@:1}" 1>&2; | ||
exit 1 | ||
} | ||
|
||
ARGS=$(getopt -o fdD -- "$@"); | ||
|
||
if [ $? -ne 0 ]; then | ||
exit 1 | ||
fi | ||
|
||
force=false | ||
dump=false | ||
dump_intention=false | ||
|
||
while true; do | ||
case "$1" in | ||
-f) | ||
force=true | ||
shift; | ||
;; | ||
-d) | ||
dump=true | ||
shift; | ||
;; | ||
-D) | ||
dump_intention=true | ||
shift; | ||
;; | ||
*) | ||
if [ $# -eq 0 ]; then | ||
break; | ||
fi | ||
error "Unknown option $1" | ||
break; | ||
esac | ||
done | ||
|
||
src=$(dirname $0) | ||
src=$(cd $src;pwd) | ||
|
||
root=$(git rev-parse --show-toplevel) | ||
rc=$? | ||
|
||
if [ $rc -ne 0 ] || [ "x$root" == "x" ]; then | ||
error "Not a git $root" | ||
fi | ||
|
||
test -d "$root" || error "Not a dir $root" | ||
test -e "$root/.vault" || error "Not a vault $root" | ||
|
||
cd $root || error "Can't enter $root" | ||
|
||
cmd_file=$(mktemp) | ||
git log --pretty=format:%H$%d$%s \ | ||
| gawk -f $src/git-vault-rebase-prepare.awk \ | ||
| tac > $cmd_file | ||
trap "rm $cmd_file" EXIT | ||
|
||
function gen_cmd { | ||
cat $cmd_file | gawk -f $src/git-vault-rebase-generate.awk | ||
} | ||
|
||
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" | ||
if ! $force; then | ||
exit 0 | ||
fi | ||
echo "Forcing 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 | ||
git clean -fd | ||
git checkout master | ||
git branch -D migrate | ||
for t in $(git tag | grep '^migrate/'); do | ||
git tag -d "$t" | ||
done | ||
git_gc | ||
error "during migration" | ||
} | ||
|
||
export -f rollback | ||
|
||
eval "$cmd" || error "$cmd" | ||
|
||
echo "REPLACE MASTER" | ||
# do it separetely to be on the safe side and keep old master until the last moment | ||
(git branch -m migrate migrated && \ | ||
git branch -m master old-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 | ||
echo "OK" |
Oops, something went wrong.