You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo_commitgraph.go 985B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2019 The Gitea Authors.
  2. // All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package git
  6. import (
  7. "os"
  8. "path"
  9. gitealog "code.gitea.io/gitea/modules/log"
  10. "github.com/go-git/go-git/v5/plumbing/format/commitgraph"
  11. cgobject "github.com/go-git/go-git/v5/plumbing/object/commitgraph"
  12. )
  13. // CommitNodeIndex returns the index for walking commit graph
  14. func (r *Repository) CommitNodeIndex() (cgobject.CommitNodeIndex, *os.File) {
  15. indexPath := path.Join(r.Path, "objects", "info", "commit-graph")
  16. file, err := os.Open(indexPath)
  17. if err == nil {
  18. var index commitgraph.Index
  19. index, err = commitgraph.OpenFileIndex(file)
  20. if err == nil {
  21. return cgobject.NewGraphCommitNodeIndex(index, r.gogitRepo.Storer), file
  22. }
  23. }
  24. if !os.IsNotExist(err) {
  25. gitealog.Warn("Unable to read commit-graph for %s: %v", r.Path, err)
  26. }
  27. return cgobject.NewObjectCommitNodeIndex(r.gogitRepo.Storer), nil
  28. }