diff options
author | Unknwon <u@gogs.io> | 2015-09-02 09:26:56 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-09-02 09:26:56 -0400 |
commit | 953bb06857f59f5c6987f68a08a94cf5a885b456 (patch) | |
tree | 196a45fa4e7f8808b35790981eb0e417bbfa1a61 /modules/git | |
parent | 6ea28f2a4759c5192811b12de054e7ad62f080f6 (diff) | |
download | gitea-953bb06857f59f5c6987f68a08a94cf5a885b456.tar.gz gitea-953bb06857f59f5c6987f68a08a94cf5a885b456.zip |
basic PR feature
Diffstat (limited to 'modules/git')
-rw-r--r-- | modules/git/repo_commit.go | 59 | ||||
-rw-r--r-- | modules/git/repo_pull.go | 6 |
2 files changed, 56 insertions, 9 deletions
diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go index 66d61b9b51..cb9fa8d459 100644 --- a/modules/git/repo_commit.go +++ b/modules/git/repo_commit.go @@ -8,6 +8,7 @@ import ( "bytes" "container/list" "errors" + "fmt" "strings" "sync" @@ -138,7 +139,8 @@ func (repo *Repository) GetCommit(commitId string) (*Commit, error) { func (repo *Repository) commitsCount(id sha1) (int, error) { if gitVer.LessThan(MustParseVersion("1.8.0")) { - stdout, stderr, err := com.ExecCmdDirBytes(repo.Path, "git", "log", "--pretty=format:''", id.String()) + stdout, stderr, err := com.ExecCmdDirBytes(repo.Path, "git", "log", + "--pretty=format:''", id.String()) if err != nil { return 0, errors.New(string(stderr)) } @@ -152,6 +154,53 @@ func (repo *Repository) commitsCount(id sha1) (int, error) { return com.StrTo(strings.TrimSpace(stdout)).Int() } +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) commitsCountBetween(start, end sha1) (int, error) { + if gitVer.LessThan(MustParseVersion("1.8.0")) { + stdout, stderr, err := com.ExecCmdDirBytes(repo.Path, "git", "log", + "--pretty=format:''", start.String()+"..."+end.String()) + if err != nil { + return 0, errors.New(string(stderr)) + } + return len(bytes.Split(stdout, []byte("\n"))), nil + } + + stdout, stderr, err := com.ExecCmdDir(repo.Path, "git", "rev-list", "--count", + start.String()+"..."+end.String()) + if err != nil { + return 0, errors.New(stderr) + } + return com.StrTo(strings.TrimSpace(stdout)).Int() +} + +func (repo *Repository) CommitsCountBetween(startCommitID, endCommitID string) (int, error) { + start, err := NewIdFromString(startCommitID) + if err != nil { + return 0, err + } + end, err := NewIdFromString(endCommitID) + if err != nil { + return 0, err + } + return repo.commitsCountBetween(start, end) +} + +func (repo *Repository) FilesCountBetween(startCommitID, endCommitID string) (int, error) { + stdout, stderr, err := com.ExecCmdDir(repo.Path, "git", "diff", "--name-only", + startCommitID+"..."+endCommitID) + if err != nil { + return 0, fmt.Errorf("list changed files: %v", concatenateError(err, stderr)) + } + return len(strings.Split(stdout, "\n")) - 1, nil +} + // used only for single tree, (] func (repo *Repository) CommitsBetween(last *Commit, before *Commit) (*list.List, error) { l := list.New() @@ -231,14 +280,6 @@ 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) diff --git a/modules/git/repo_pull.go b/modules/git/repo_pull.go index a179e52802..add32df908 100644 --- a/modules/git/repo_pull.go +++ b/modules/git/repo_pull.go @@ -84,3 +84,9 @@ func (repo *Repository) GetPatch(basePath, baseBranch, headBranch string) ([]byt return stdout, nil } + +// Merge merges pull request from head repository and branch. +func (repo *Repository) Merge(headRepoPath string, baseBranch, headBranch string) error { + + return nil +} |