func (repo *Repository) fileCommitsCount(commit *Commit, file string) (int64, error) { pathCb := history.MakePathChecker(commit.repo.repo, file) cmp := history.MakePathComparator(commit.repo.repo, file) counter, result := history.MakeCounter(pathCb) hist := history.New(commit.repo.repo) _, err := hist.WalkFilteredHistory(sha2oidp(commit.ID), counter, cmp) if err != nil { return 0, err } return int64(result()), nil }
func (repo *Repository) commitsByFileAndRange(commit *Commit, file string, page int) (*list.List, error) { pathCb := history.MakePathChecker(commit.repo.repo, file) cmp := history.MakePathComparator(commit.repo.repo, file) pager := history.MakePager(commit.repo.repo, pathCb, (page-1)*CommitsRangeSize, CommitsRangeSize) hist := history.New(commit.repo.repo) result, err := hist.WalkFilteredHistory(sha2oidp(commit.ID), pager, cmp) if err != nil { return nil, err } return repo.raw2commitList(result) }
// GetCommitByPath return the commit of relative path object. func (c *Commit) GetCommitByPath(relpath string) (*Commit, error) { pathCb := history.MakePathChecker(c.repo.repo, relpath) pager := history.MakePager(c.repo.repo, pathCb, 0, 1) cmp := history.MakePathComparator(c.repo.repo, relpath) hist := history.New(c.repo.repo) result, err := hist.WalkFilteredHistory(sha2oidp(c.ID), pager, cmp) if err != nil { return nil, err } if result.Len() == 0 { // no entries return nil, nil } return raw2commit(c.repo, result.Front().Value.(*rawgit.Commit)) }