@@ -189,6 +189,75 @@ func checkDaemonExport(ctx context.Context, logger log.Logger, autofix bool) err
189
189
return nil
190
190
}
191
191
192
+ func checkCommitGraph (ctx context.Context , logger log.Logger , autofix bool ) error {
193
+ if err := git .InitOnceWithSync (ctx ); err != nil {
194
+ return err
195
+ }
196
+
197
+ numRepos := 0
198
+ numNeedUpdate := 0
199
+ numWritten := 0
200
+ if err := iterateRepositories (ctx , func (repo * repo_model.Repository ) error {
201
+ numRepos ++
202
+
203
+ commitGraphExists := func () (bool , error ) {
204
+ // Check commit-graph exists
205
+ commitGraphFile := path .Join (repo .RepoPath (), `objects/info/commit-graph` )
206
+ isExist , err := util .IsExist (commitGraphFile )
207
+ if err != nil {
208
+ logger .Error ("Unable to check if %s exists. Error: %v" , commitGraphFile , err )
209
+ return false , err
210
+ }
211
+
212
+ if ! isExist {
213
+ commitGraphsDir := path .Join (repo .RepoPath (), `objects/info/commit-graphs` )
214
+ isExist , err = util .IsExist (commitGraphsDir )
215
+ if err != nil {
216
+ logger .Error ("Unable to check if %s exists. Error: %v" , commitGraphsDir , err )
217
+ return false , err
218
+ }
219
+ }
220
+ return isExist , nil
221
+ }
222
+
223
+ isExist , err := commitGraphExists ()
224
+ if err != nil {
225
+ return err
226
+ }
227
+ if ! isExist {
228
+ numNeedUpdate ++
229
+ if autofix {
230
+ if err := git .WriteCommitGraph (ctx , repo .RepoPath ()); err != nil {
231
+ logger .Error ("Unable to write commit-graph in %s. Error: %v" , repo .FullName (), err )
232
+ return err
233
+ }
234
+ isExist , err := commitGraphExists ()
235
+ if err != nil {
236
+ return err
237
+ }
238
+ if isExist {
239
+ numWritten ++
240
+ logger .Info ("Commit-graph written: %s" , repo .FullName ())
241
+ } else {
242
+ logger .Warn ("No commit-graph written: %s" , repo .FullName ())
243
+ }
244
+ }
245
+ }
246
+ return nil
247
+ }); err != nil {
248
+ logger .Critical ("Unable to checkCommitGraph: %v" , err )
249
+ return err
250
+ }
251
+
252
+ if autofix {
253
+ logger .Info ("Wrote commit-graph files for %d of %d repositories." , numWritten , numRepos )
254
+ } else {
255
+ logger .Info ("Checked %d repositories, %d without commit-graphs." , numRepos , numNeedUpdate )
256
+ }
257
+
258
+ return nil
259
+ }
260
+
192
261
func init () {
193
262
Register (& Check {
194
263
Title : "Check if SCRIPT_TYPE is available" ,
@@ -225,4 +294,11 @@ func init() {
225
294
Run : checkDaemonExport ,
226
295
Priority : 8 ,
227
296
})
297
+ Register (& Check {
298
+ Title : "Check commit-graphs" ,
299
+ Name : "check-commit-graphs" ,
300
+ IsDefault : false ,
301
+ Run : checkCommitGraph ,
302
+ Priority : 9 ,
303
+ })
228
304
}
0 commit comments