add: get first and last commit by path

This commit is contained in:
yystopf 2021-08-19 14:25:37 +08:00
parent 64ef5a1567
commit f13f296790
1 changed files with 13 additions and 0 deletions

View File

@ -205,6 +205,19 @@ func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) {
return commits.Front().Value.(*Commit), nil
}
// GetFirstAndLastCommitByPath returns the first commit and the last commit of relative path.
func (repo *Repository) GetFirstAndLastCommitByPath(revision, relpath string) (*Commit, *Commit, error) {
stdout, err := NewCommand("log", revision, prettyLogFormat, "--", relpath).RunInDirBytes(repo.Path)
if err != nil {
return nil, nil, err
}
commits, err := repo.parsePrettyFormatLogToList(stdout)
if err != nil {
return nil, nil, err
}
return commits.Front().Value.(*Commit), commits.Back().Value.(*Commit), nil
}
// CommitsRangeSize the default commits range size
var CommitsRangeSize = 50