Add test for repo size and change default GC

--git-gc=always seems to be the right tradeoff.
This commit is contained in:
Tim Hockin 2023-02-18 16:26:18 -08:00
parent dc56d5d6bf
commit cbedbc0ca5
2 changed files with 96 additions and 6 deletions

View File

@ -136,7 +136,7 @@ var flGitCmd = pflag.String("git", envString("GIT_SYNC_GIT", "git"),
"the git command to run (subject to PATH search, mostly for testing)")
var flGitConfig = pflag.String("git-config", envString("GIT_SYNC_GIT_CONFIG", ""),
"additional git config options in 'section.var1:val1,\"section.sub.var2\":\"val2\"' format")
var flGitGC = pflag.String("git-gc", envString("GIT_SYNC_GIT_GC", "auto"),
var flGitGC = pflag.String("git-gc", envString("GIT_SYNC_GIT_GC", "always"),
"git garbage collection behavior: one of 'auto', 'always', 'aggressive', or 'off'")
var flHTTPBind = pflag.String("http-bind", envString("GIT_SYNC_HTTP_BIND", ""),
@ -1371,6 +1371,11 @@ func (git *repoSync) cleanup(ctx context.Context, oldHash string) error {
}
}
// Expire old refs.
if _, err := git.run.Run(ctx, git.root, nil, git.cmd, "reflog", "expire", "--expire-unreachable=all", "--all"); err != nil {
cleanupErrs = append(cleanupErrs, err)
}
// Run GC if needed.
if git.gc != gcOff {
args := []string{"gc"}
@ -1547,11 +1552,9 @@ func (git *repoSync) SyncRepo(ctx context.Context, refreshCreds func(context.Con
// Mark ourselves as "ready".
setRepoReady()
if oldHash != "" {
// Clean up the old worktree(s).
if err := git.cleanup(ctx, oldHash); err != nil {
git.log.Error(err, "git cleanup failed", "oldHash", oldHash)
}
// Clean up the old worktree(s) and run GC.
if err := git.cleanup(ctx, oldHash); err != nil {
git.log.Error(err, "git cleanup failed", "oldHash", oldHash)
}
return changed, remote, nil

View File

@ -2571,6 +2571,93 @@ function e2e::github_https() {
assert_file_exists "$ROOT"/link/LICENSE
}
##############################################
# Test git-gc default
##############################################
function e2e::gc_default() {
SHA1=$(git -C "$REPO" rev-parse HEAD)
dd if=/dev/urandom of="$REPO"/big1 bs=1024 count=4096 >/dev/null
git -C "$REPO" add .
git -C "$REPO" commit -qam "$FUNCNAME 1"
SHA2=$(git -C "$REPO" rev-parse HEAD)
dd if=/dev/urandom of="$REPO"/big2 bs=1024 count=4096 >/dev/null
git -C "$REPO" add .
git -C "$REPO" commit -qam "$FUNCNAME 2"
SHA3=$(git -C "$REPO" rev-parse HEAD)
GIT_SYNC \
--one-time \
--repo="file://$REPO" \
--root="$ROOT" \
--link="link" \
--ref="$SHA3" \
--depth=0
assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/big1
assert_file_exists "$ROOT"/link/big2
SIZE=$(du -s "$ROOT" | cut -f1)
if [ "$SIZE" -lt 14000 ]; then
fail "repo is impossibly small: $SIZE"
fi
if [ "$SIZE" -gt 18000 ]; then
fail "repo is too big: $SIZE"
fi
GIT_SYNC \
--one-time \
--repo="file://$REPO" \
--root="$ROOT" \
--link="link" \
--ref="$SHA3" \
--depth=1
assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/big1
assert_file_exists "$ROOT"/link/big2
SIZE=$(du -s "$ROOT" | cut -f1)
if [ "$SIZE" -lt 14000 ]; then
fail "repo is impossibly small: $SIZE"
fi
if [ "$SIZE" -gt 18000 ]; then
fail "repo is too big: $SIZE"
fi
GIT_SYNC \
--one-time \
--repo="file://$REPO" \
--root="$ROOT" \
--link="link" \
--ref="$SHA2" \
--depth=1
assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/big1
assert_file_absent "$ROOT"/link/big2
SIZE=$(du -s "$ROOT" | cut -f1)
if [ "$SIZE" -lt 7000 ]; then
fail "repo is impossibly small: $SIZE"
fi
if [ "$SIZE" -gt 9000 ]; then
fail "repo is too big: $SIZE"
fi
GIT_SYNC \
--one-time \
--repo="file://$REPO" \
--root="$ROOT" \
--link="link" \
--ref="$SHA1" \
--depth=1
assert_link_exists "$ROOT"/link
assert_file_absent "$ROOT"/link/big1
assert_file_absent "$ROOT"/link/big2
SIZE=$(du -s "$ROOT" | cut -f1)
if [ "$SIZE" -lt 100 ]; then
fail "repo is impossibly small: $SIZE"
fi
if [ "$SIZE" -gt 1000 ]; then
fail "repo is too big: $SIZE"
fi
}
##############################################
# Test git-gc=auto
##############################################