@ -73,7 +73,21 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...git.CmdArg)
return db . ErrCancelledf ( "before GC of %s" , repo . FullName ( ) )
default :
}
log . Trace ( "Running git gc on %v" , repo )
// we can ignore the error here because it will be logged in GitGCRepo
_ = GitGcRepo ( ctx , repo , timeout , args )
return nil
} ,
) ; err != nil {
return err
}
log . Trace ( "Finished: GitGcRepos" )
return nil
}
// GitGcRepo calls 'git gc' to remove unnecessary files and optimize the local repository
func GitGcRepo ( ctx context . Context , repo * repo_model . Repository , timeout time . Duration , args [ ] git . CmdArg ) error {
log . Trace ( "Running git gc on %-v" , repo )
command := git . NewCommand ( ctx , args ... ) .
SetDescription ( fmt . Sprintf ( "Repository Garbage Collection: %s" , repo . FullName ( ) ) )
var stdout string
@ -81,9 +95,9 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...git.CmdArg)
stdout , _ , err = command . RunStdString ( & git . RunOpts { Timeout : timeout , Dir : repo . RepoPath ( ) } )
if err != nil {
log . Error ( "Repository garbage collection failed for %v. Stdout: %s\nError: %v" , repo , stdout , err )
log . Error ( "Repository garbage collection failed for %- v. Stdout: %s\nError: %v" , repo , stdout , err )
desc := fmt . Sprintf ( "Repository garbage collection failed for %s. Stdout: %s\nError: %v" , repo . RepoPath ( ) , stdout , err )
if err = system_model . CreateRepositoryNotice ( desc ) ; err != nil {
if err : = system_model . CreateRepositoryNotice ( desc ) ; err != nil {
log . Error ( "CreateRepositoryNotice: %v" , err )
}
return fmt . Errorf ( "Repository garbage collection failed in repo: %s: Error: %w" , repo . FullName ( ) , err )
@ -91,21 +105,14 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...git.CmdArg)
// Now update the size of the repository
if err := repo_module . UpdateRepoSize ( ctx , repo ) ; err != nil {
log . Error ( "Updating size as part of garbage collection failed for %v. Stdout: %s\nError: %v" , repo , stdout , err )
log . Error ( "Updating size as part of garbage collection failed for %- v. Stdout: %s\nError: %v" , repo , stdout , err )
desc := fmt . Sprintf ( "Updating size as part of garbage collection failed for %s. Stdout: %s\nError: %v" , repo . RepoPath ( ) , stdout , err )
if err = system_model . CreateRepositoryNotice ( desc ) ; err != nil {
if err : = system_model . CreateRepositoryNotice ( desc ) ; err != nil {
log . Error ( "CreateRepositoryNotice: %v" , err )
}
return fmt . Errorf ( "Updating size as part of garbage collection failed in repo: %s: Error: %w" , repo . FullName ( ) , err )
}
return nil
} ,
) ; err != nil {
return err
}
log . Trace ( "Finished: GitGcRepos" )
return nil
}
@ -162,7 +169,7 @@ func DeleteMissingRepositories(ctx context.Context, doer *user_model.User) error
}
log . Trace ( "Deleting %d/%d..." , repo . OwnerID , repo . ID )
if err := models . DeleteRepository ( doer , repo . OwnerID , repo . ID ) ; err != nil {
log . Error ( "Failed to DeleteRepository %s [%d] : Error: %v" , repo . FullName ( ) , repo . ID , err )
log . Error ( "Failed to DeleteRepository %-v : Error: %v" , repo , err )
if err2 := system_model . CreateRepositoryNotice ( "Failed to DeleteRepository %s [%d]: Error: %v" , repo . FullName ( ) , repo . ID , err ) ; err2 != nil {
log . Error ( "CreateRepositoryNotice: %v" , err )
}