@@ -22,8 +22,8 @@ import (
22
22
"xorm.io/builder"
23
23
)
24
24
25
- // GitFsck calls 'git fsck' to check repository health.
26
- func GitFsck (ctx context.Context , timeout time.Duration , args []git.CmdArg ) error {
25
+ // GitFsckRepos calls 'git fsck' to check repository health.
26
+ func GitFsckRepos (ctx context.Context , timeout time.Duration , args []git.CmdArg ) error {
27
27
log .Trace ("Doing: GitFsck" )
28
28
29
29
if err := db .Iterate (
@@ -35,15 +35,7 @@ func GitFsck(ctx context.Context, timeout time.Duration, args []git.CmdArg) erro
35
35
return db .ErrCancelledf ("before fsck of %s" , repo .FullName ())
36
36
default :
37
37
}
38
- log .Trace ("Running health check on repository %v" , repo )
39
- repoPath := repo .RepoPath ()
40
- if err := git .Fsck (ctx , repoPath , timeout , args ... ); err != nil {
41
- log .Warn ("Failed to health check repository (%v): %v" , repo , err )
42
- if err = system_model .CreateRepositoryNotice ("Failed to health check repository (%s): %v" , repo .FullName (), err ); err != nil {
43
- log .Error ("CreateRepositoryNotice: %v" , err )
44
- }
45
- }
46
- return nil
38
+ return GitFsckRepo (ctx , repo , timeout , args )
47
39
},
48
40
); err != nil {
49
41
log .Trace ("Error: GitFsck: %v" , err )
@@ -54,6 +46,19 @@ func GitFsck(ctx context.Context, timeout time.Duration, args []git.CmdArg) erro
54
46
return nil
55
47
}
56
48
49
+ // GitFsckRepo calls 'git fsck' to check an individual repository's health.
50
+ func GitFsckRepo (ctx context.Context , repo * repo_model.Repository , timeout time.Duration , args []git.CmdArg ) error {
51
+ log .Trace ("Running health check on repository %-v" , repo )
52
+ repoPath := repo .RepoPath ()
53
+ if err := git .Fsck (ctx , repoPath , timeout , args ... ); err != nil {
54
+ log .Warn ("Failed to health check repository (%-v): %v" , repo , err )
55
+ if err = system_model .CreateRepositoryNotice ("Failed to health check repository (%s): %v" , repo .FullName (), err ); err != nil {
56
+ log .Error ("CreateRepositoryNotice: %v" , err )
57
+ }
58
+ }
59
+ return nil
60
+ }
61
+
57
62
// GitGcRepos calls 'git gc' to remove unnecessary files and optimize the local repository
58
63
func GitGcRepos (ctx context.Context , timeout time.Duration , args ... git.CmdArg ) error {
59
64
log .Trace ("Doing: GitGcRepos" )
@@ -68,33 +73,7 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...git.CmdArg)
68
73
return db .ErrCancelledf ("before GC of %s" , repo .FullName ())
69
74
default :
70
75
}
71
- log .Trace ("Running git gc on %v" , repo )
72
- command := git .NewCommand (ctx , args ... ).
73
- SetDescription (fmt .Sprintf ("Repository Garbage Collection: %s" , repo .FullName ()))
74
- var stdout string
75
- var err error
76
- stdout , _ , err = command .RunStdString (& git.RunOpts {Timeout : timeout , Dir : repo .RepoPath ()})
77
-
78
- if err != nil {
79
- log .Error ("Repository garbage collection failed for %v. Stdout: %s\n Error: %v" , repo , stdout , err )
80
- desc := fmt .Sprintf ("Repository garbage collection failed for %s. Stdout: %s\n Error: %v" , repo .RepoPath (), stdout , err )
81
- if err = system_model .CreateRepositoryNotice (desc ); err != nil {
82
- log .Error ("CreateRepositoryNotice: %v" , err )
83
- }
84
- return fmt .Errorf ("Repository garbage collection failed in repo: %s: Error: %w" , repo .FullName (), err )
85
- }
86
-
87
- // Now update the size of the repository
88
- if err := repo_module .UpdateRepoSize (ctx , repo ); err != nil {
89
- log .Error ("Updating size as part of garbage collection failed for %v. Stdout: %s\n Error: %v" , repo , stdout , err )
90
- desc := fmt .Sprintf ("Updating size as part of garbage collection failed for %s. Stdout: %s\n Error: %v" , repo .RepoPath (), stdout , err )
91
- if err = system_model .CreateRepositoryNotice (desc ); err != nil {
92
- log .Error ("CreateRepositoryNotice: %v" , err )
93
- }
94
- return fmt .Errorf ("Updating size as part of garbage collection failed in repo: %s: Error: %w" , repo .FullName (), err )
95
- }
96
-
97
- return nil
76
+ return GitGcRepo (ctx , repo , timeout , args )
98
77
},
99
78
); err != nil {
100
79
return err
@@ -104,6 +83,37 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...git.CmdArg)
104
83
return nil
105
84
}
106
85
86
+ // GitGcRepo calls 'git gc' to remove unnecessary files and optimize the local repository
87
+ func GitGcRepo (ctx context.Context , repo * repo_model.Repository , timeout time.Duration , args []git.CmdArg ) error {
88
+ log .Trace ("Running git gc on %-v" , repo )
89
+ command := git .NewCommand (ctx , args ... ).
90
+ SetDescription (fmt .Sprintf ("Repository Garbage Collection: %s" , repo .FullName ()))
91
+ var stdout string
92
+ var err error
93
+ stdout , _ , err = command .RunStdString (& git.RunOpts {Timeout : timeout , Dir : repo .RepoPath ()})
94
+
95
+ if err != nil {
96
+ log .Error ("Repository garbage collection failed for %v. Stdout: %s\n Error: %v" , repo , stdout , err )
97
+ desc := fmt .Sprintf ("Repository garbage collection failed for %s. Stdout: %s\n Error: %v" , repo .RepoPath (), stdout , err )
98
+ if err = system_model .CreateRepositoryNotice (desc ); err != nil {
99
+ log .Error ("CreateRepositoryNotice: %v" , err )
100
+ }
101
+ return fmt .Errorf ("Repository garbage collection failed in repo: %s: Error: %w" , repo .FullName (), err )
102
+ }
103
+
104
+ // Now update the size of the repository
105
+ if err := repo_module .UpdateRepoSize (ctx , repo ); err != nil {
106
+ log .Error ("Updating size as part of garbage collection failed for %-v. Stdout: %s\n Error: %v" , repo , stdout , err )
107
+ desc := fmt .Sprintf ("Updating size as part of garbage collection failed for %s. Stdout: %s\n Error: %v" , repo .RepoPath (), stdout , err )
108
+ if err = system_model .CreateRepositoryNotice (desc ); err != nil {
109
+ log .Error ("CreateRepositoryNotice: %v" , err )
110
+ }
111
+ return fmt .Errorf ("Updating size as part of garbage collection failed in repo: %s: Error: %w" , repo .FullName (), err )
112
+ }
113
+
114
+ return nil
115
+ }
116
+
107
117
func gatherMissingRepoRecords (ctx context.Context ) ([]* repo_model.Repository , error ) {
108
118
repos := make ([]* repo_model.Repository , 0 , 10 )
109
119
if err := db .Iterate (
0 commit comments