@@ -19,7 +19,7 @@ import (
19
19
20
20
// GarbageCollectLFSMetaObjectsOptions provides options for GarbageCollectLFSMetaObjects function
21
21
type GarbageCollectLFSMetaObjectsOptions struct {
22
- Logger log. Logger
22
+ LogDetail func ( format string , v ... any )
23
23
AutoFix bool
24
24
OlderThan time.Time
25
25
UpdatedLessRecentlyThan time.Time
@@ -32,10 +32,12 @@ func GarbageCollectLFSMetaObjects(ctx context.Context, opts GarbageCollectLFSMet
32
32
log .Trace ("Doing: GarbageCollectLFSMetaObjects" )
33
33
defer log .Trace ("Finished: GarbageCollectLFSMetaObjects" )
34
34
35
+ if opts .LogDetail == nil {
36
+ opts .LogDetail = log .Debug
37
+ }
38
+
35
39
if ! setting .LFS .StartServer {
36
- if opts .Logger != nil {
37
- opts .Logger .Info ("LFS support is disabled" )
38
- }
40
+ opts .LogDetail ("LFS support is disabled" )
39
41
return nil
40
42
}
41
43
@@ -54,21 +56,17 @@ func GarbageCollectLFSMetaObjects(ctx context.Context, opts GarbageCollectLFSMet
54
56
55
57
// GarbageCollectLFSMetaObjectsForRepo garbage collects LFS objects for a specific repository
56
58
func GarbageCollectLFSMetaObjectsForRepo (ctx context.Context , repo * repo_model.Repository , opts GarbageCollectLFSMetaObjectsOptions ) error {
57
- if opts .Logger != nil {
58
- opts .Logger .Info ("Checking %-v" , repo )
59
- }
59
+ opts .LogDetail ("Checking %-v" , repo )
60
60
total , orphaned , collected , deleted := int64 (0 ), 0 , 0 , 0
61
- if opts .Logger != nil {
62
- defer func () {
63
- if orphaned == 0 {
64
- opts .Logger .Info ("Found %d total LFSMetaObjects in %-v" , total , repo )
65
- } else if ! opts .AutoFix {
66
- opts .Logger .Info ("Found %d/%d orphaned LFSMetaObjects in %-v" , orphaned , total , repo )
67
- } else {
68
- opts .Logger .Info ("Collected %d/%d orphaned/%d total LFSMetaObjects in %-v. %d removed from storage." , collected , orphaned , total , repo , deleted )
69
- }
70
- }()
71
- }
61
+ defer func () {
62
+ if orphaned == 0 {
63
+ opts .LogDetail ("Found %d total LFSMetaObjects in %-v" , total , repo )
64
+ } else if ! opts .AutoFix {
65
+ opts .LogDetail ("Found %d/%d orphaned LFSMetaObjects in %-v" , orphaned , total , repo )
66
+ } else {
67
+ opts .LogDetail ("Collected %d/%d orphaned/%d total LFSMetaObjects in %-v. %d removed from storage." , collected , orphaned , total , repo , deleted )
68
+ }
69
+ }()
72
70
73
71
gitRepo , err := git .OpenRepository (ctx , repo .RepoPath ())
74
72
if err != nil {
@@ -129,9 +127,7 @@ func GarbageCollectLFSMetaObjectsForRepo(ctx context.Context, repo *repo_model.R
129
127
})
130
128
131
129
if err == errStop {
132
- if opts .Logger != nil {
133
- opts .Logger .Info ("Processing stopped at %d total LFSMetaObjects in %-v" , total , repo )
134
- }
130
+ opts .LogDetail ("Processing stopped at %d total LFSMetaObjects in %-v" , total , repo )
135
131
return nil
136
132
} else if err != nil {
137
133
return err
0 commit comments