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.

24 lines
817 B

  1. // Copyright 2017 The Gitea 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 "fmt"
  6. // FileBlame return the Blame object of file
  7. func (repo *Repository) FileBlame(revision, path, file string) ([]byte, error) {
  8. return NewCommand("blame", "--root", "--", file).RunInDirBytes(path)
  9. }
  10. // LineBlame returns the latest commit at the given line
  11. func (repo *Repository) LineBlame(revision, path, file string, line uint) (*Commit, error) {
  12. res, err := NewCommand("blame", fmt.Sprintf("-L %d,%d", line, line), "-p", revision, "--", file).RunInDir(path)
  13. if err != nil {
  14. return nil, err
  15. }
  16. if len(res) < 40 {
  17. return nil, fmt.Errorf("invalid result of blame: %s", res)
  18. }
  19. return repo.GetCommit(string(res[:40]))
  20. }