summaryrefslogtreecommitdiffstats
path: root/services/repository
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-07-06 18:52:41 +0200
committerGitHub <noreply@github.com>2023-07-06 18:52:41 +0200
commitf0bde0e4f902970d447e3aae628f2dcf6f79e539 (patch)
tree8eae0d35b153b0bf0aa0a21a64cb3a70b3cfbd2b /services/repository
parentAllow/fix review (approve/reject) of empty PRs (#25690) (diff)
downloadforgejo-f0bde0e4f902970d447e3aae628f2dcf6f79e539.tar.xz
forgejo-f0bde0e4f902970d447e3aae628f2dcf6f79e539.zip
Simplify the LFS GC logger usage (#25717)
Remove unnecessary `if opts.Logger != nil` checks. * For "CLI doctor" mode, output to the console's "logger.Info". * For "Web Task" mode, output to the default "logger.Debug", to avoid flooding the server's log in a busy production instance. Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'services/repository')
-rw-r--r--services/repository/lfs.go38
1 files changed, 17 insertions, 21 deletions
diff --git a/services/repository/lfs.go b/services/repository/lfs.go
index aeb808a72f..0bd4d53a5c 100644
--- a/services/repository/lfs.go
+++ b/services/repository/lfs.go
@@ -19,7 +19,7 @@ import (
// GarbageCollectLFSMetaObjectsOptions provides options for GarbageCollectLFSMetaObjects function
type GarbageCollectLFSMetaObjectsOptions struct {
- Logger log.Logger
+ LogDetail func(format string, v ...any)
AutoFix bool
OlderThan time.Time
UpdatedLessRecentlyThan time.Time
@@ -32,10 +32,12 @@ func GarbageCollectLFSMetaObjects(ctx context.Context, opts GarbageCollectLFSMet
log.Trace("Doing: GarbageCollectLFSMetaObjects")
defer log.Trace("Finished: GarbageCollectLFSMetaObjects")
+ if opts.LogDetail == nil {
+ opts.LogDetail = log.Debug
+ }
+
if !setting.LFS.StartServer {
- if opts.Logger != nil {
- opts.Logger.Info("LFS support is disabled")
- }
+ opts.LogDetail("LFS support is disabled")
return nil
}
@@ -54,21 +56,17 @@ func GarbageCollectLFSMetaObjects(ctx context.Context, opts GarbageCollectLFSMet
// GarbageCollectLFSMetaObjectsForRepo garbage collects LFS objects for a specific repository
func GarbageCollectLFSMetaObjectsForRepo(ctx context.Context, repo *repo_model.Repository, opts GarbageCollectLFSMetaObjectsOptions) error {
- if opts.Logger != nil {
- opts.Logger.Info("Checking %-v", repo)
- }
+ opts.LogDetail("Checking %-v", repo)
total, orphaned, collected, deleted := int64(0), 0, 0, 0
- if opts.Logger != nil {
- defer func() {
- if orphaned == 0 {
- opts.Logger.Info("Found %d total LFSMetaObjects in %-v", total, repo)
- } else if !opts.AutoFix {
- opts.Logger.Info("Found %d/%d orphaned LFSMetaObjects in %-v", orphaned, total, repo)
- } else {
- opts.Logger.Info("Collected %d/%d orphaned/%d total LFSMetaObjects in %-v. %d removed from storage.", collected, orphaned, total, repo, deleted)
- }
- }()
- }
+ defer func() {
+ if orphaned == 0 {
+ opts.LogDetail("Found %d total LFSMetaObjects in %-v", total, repo)
+ } else if !opts.AutoFix {
+ opts.LogDetail("Found %d/%d orphaned LFSMetaObjects in %-v", orphaned, total, repo)
+ } else {
+ opts.LogDetail("Collected %d/%d orphaned/%d total LFSMetaObjects in %-v. %d removed from storage.", collected, orphaned, total, repo, deleted)
+ }
+ }()
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
if err != nil {
@@ -129,9 +127,7 @@ func GarbageCollectLFSMetaObjectsForRepo(ctx context.Context, repo *repo_model.R
})
if err == errStop {
- if opts.Logger != nil {
- opts.Logger.Info("Processing stopped at %d total LFSMetaObjects in %-v", total, repo)
- }
+ opts.LogDetail("Processing stopped at %d total LFSMetaObjects in %-v", total, repo)
return nil
} else if err != nil {
return err