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_blame.go 614B

1234567891011121314151617181920212223
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package git
  4. import (
  5. "fmt"
  6. )
  7. // LineBlame returns the latest commit at the given line
  8. func (repo *Repository) LineBlame(revision, path, file string, line uint) (*Commit, error) {
  9. res, _, err := NewCommand(repo.Ctx, "blame").
  10. AddOptionFormat("-L %d,%d", line, line).
  11. AddOptionValues("-p", revision).
  12. AddDashesAndList(file).RunStdString(&RunOpts{Dir: 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(res[:40])
  20. }