1
0
Fork 0
forked from forgejo/forgejo

Huge updates!!!!! Be careful to merge!!!!

This commit is contained in:
Unknwon 2014-07-26 02:28:04 -04:00
parent 3f38ff6c09
commit 5c4bc3c848
43 changed files with 2225 additions and 2125 deletions

View file

@ -32,7 +32,18 @@ func (repo *Repository) GetCommitOfBranch(branchName string) (*Commit, error) {
if err != nil {
return nil, err
}
return repo.GetCommit(commitId)
}
func (repo *Repository) GetCommitIdOfTag(tagName string) (string, error) {
return repo.getCommitIdOfRef("refs/tags/" + tagName)
}
func (repo *Repository) GetCommitOfTag(tagName string) (*Commit, error) {
commitId, err := repo.GetCommitIdOfTag(tagName)
if err != nil {
return nil, err
}
return repo.GetCommit(commitId)
}
@ -212,6 +223,32 @@ func (repo *Repository) commitsBefore(lock *sync.Mutex, l *list.List, parent *li
return nil
}
func (repo *Repository) CommitsCount(commitId string) (int, error) {
id, err := NewIdFromString(commitId)
if err != nil {
return 0, err
}
return repo.commitsCount(id)
}
func (repo *Repository) FileCommitsCount(branch, file string) (int, error) {
stdout, stderr, err := com.ExecCmdDir(repo.Path, "git", "rev-list", "--count",
branch, "--", file)
if err != nil {
return 0, errors.New(stderr)
}
return com.StrTo(strings.TrimSpace(stdout)).Int()
}
func (repo *Repository) CommitsByFileAndRange(branch, file string, page int) (*list.List, error) {
stdout, stderr, err := com.ExecCmdDirBytes(repo.Path, "git", "log", branch,
"--skip="+com.ToStr((page-1)*50), "--max-count=50", prettyLogFormat, "--", file)
if err != nil {
return nil, errors.New(string(stderr))
}
return parsePrettyFormatLog(repo, stdout)
}
func (repo *Repository) getCommitsBefore(id sha1) (*list.List, error) {
l := list.New()
lock := new(sync.Mutex)
@ -219,6 +256,26 @@ func (repo *Repository) getCommitsBefore(id sha1) (*list.List, error) {
return l, err
}
func (repo *Repository) searchCommits(id sha1, keyword string) (*list.List, error) {
stdout, stderr, err := com.ExecCmdDirBytes(repo.Path, "git", "log", id.String(), "-100",
"-i", "--grep="+keyword, prettyLogFormat)
if err != nil {
return nil, err
} else if len(stderr) > 0 {
return nil, errors.New(string(stderr))
}
return parsePrettyFormatLog(repo, stdout)
}
func (repo *Repository) commitsByRange(id sha1, page int) (*list.List, error) {
stdout, stderr, err := com.ExecCmdDirBytes(repo.Path, "git", "log", id.String(),
"--skip="+com.ToStr((page-1)*50), "--max-count=50", prettyLogFormat)
if err != nil {
return nil, errors.New(string(stderr))
}
return parsePrettyFormatLog(repo, stdout)
}
func (repo *Repository) getCommitOfRelPath(id sha1, relPath string) (*Commit, error) {
stdout, _, err := com.ExecCmdDir(repo.Path, "git", "log", "-1", prettyLogFormat, id.String(), "--", relPath)
if err != nil {