add: get first and last commit by path
This commit is contained in:
parent
64ef5a1567
commit
f13f296790
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue