gitea源码

1234567891011121314151617181920212223
  1. // Copyright 2022 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package git
  4. import (
  5. "context"
  6. "fmt"
  7. "code.gitea.io/gitea/modules/git/gitcmd"
  8. )
  9. // WriteCommitGraph write commit graph to speed up repo access
  10. // this requires git v2.18 to be installed
  11. func WriteCommitGraph(ctx context.Context, repoPath string) error {
  12. if DefaultFeatures().CheckVersionAtLeast("2.18") {
  13. if _, _, err := gitcmd.NewCommand("commit-graph", "write").RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath}); err != nil {
  14. return fmt.Errorf("unable to write commit-graph for '%s' : %w", repoPath, err)
  15. }
  16. }
  17. return nil
  18. }