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_gogit.go 1019B

123456789101112131415161718192021222324252627282930313233343536373839
  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. //go:build gogit
  6. // +build gogit
  7. package git
  8. import (
  9. "os"
  10. "path"
  11. gitealog "code.gitea.io/gitea/modules/log"
  12. "github.com/go-git/go-git/v5/plumbing/format/commitgraph"
  13. cgobject "github.com/go-git/go-git/v5/plumbing/object/commitgraph"
  14. )
  15. // CommitNodeIndex returns the index for walking commit graph
  16. func (r *Repository) CommitNodeIndex() (cgobject.CommitNodeIndex, *os.File) {
  17. indexPath := path.Join(r.Path, "objects", "info", "commit-graph")
  18. file, err := os.Open(indexPath)
  19. if err == nil {
  20. var index commitgraph.Index
  21. index, err = commitgraph.OpenFileIndex(file)
  22. if err == nil {
  23. return cgobject.NewGraphCommitNodeIndex(index, r.gogitRepo.Storer), file
  24. }
  25. }
  26. if !os.IsNotExist(err) {
  27. gitealog.Warn("Unable to read commit-graph for %s: %v", r.Path, err)
  28. }
  29. return cgobject.NewObjectCommitNodeIndex(r.gogitRepo.Storer), nil
  30. }