utils.go 692 B

123456789101112131415161718192021222324252627
  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. "path/filepath"
  7. "strings"
  8. )
  9. const prettyLogFormat = `--pretty=format:%H`
  10. func RefEndName(refStr string) string {
  11. index := strings.LastIndex(refStr, "/")
  12. if index != -1 {
  13. return refStr[index+1:]
  14. }
  15. return refStr
  16. }
  17. // If the object is stored in its own file (i.e not in a pack file),
  18. // this function returns the full path to the object file.
  19. // It does not test if the file exists.
  20. func filepathFromSHA1(rootdir, sha1 string) string {
  21. return filepath.Join(rootdir, "objects", sha1[:2], sha1[2:])
  22. }