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.

48 lines
1.1 KiB

  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package git
  5. import (
  6. "bytes"
  7. "container/list"
  8. "path/filepath"
  9. "strings"
  10. )
  11. const prettyLogFormat = `--pretty=format:%H`
  12. func parsePrettyFormatLog(repo *Repository, logByts []byte) (*list.List, error) {
  13. l := list.New()
  14. if len(logByts) == 0 {
  15. return l, nil
  16. }
  17. parts := bytes.Split(logByts, []byte{'\n'})
  18. for _, commitId := range parts {
  19. commit, err := repo.GetCommit(string(commitId))
  20. if err != nil {
  21. return nil, err
  22. }
  23. l.PushBack(commit)
  24. }
  25. return l, nil
  26. }
  27. func RefEndName(refStr string) string {
  28. index := strings.LastIndex(refStr, "/")
  29. if index != -1 {
  30. return refStr[index+1:]
  31. }
  32. return refStr
  33. }
  34. // If the object is stored in its own file (i.e not in a pack file),
  35. // this function returns the full path to the object file.
  36. // It does not test if the file exists.
  37. func filepathFromSHA1(rootdir, sha1 string) string {
  38. return filepath.Join(rootdir, "objects", sha1[:2], sha1[2:])
  39. }