summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorUnknwon <joe2010xtmf@163.com>2014-07-26 02:28:04 -0400
committerUnknwon <joe2010xtmf@163.com>2014-07-26 02:28:04 -0400
commit5c4bc3c848fb4bd46ad5ceeacd82cdfa8f2b5635 (patch)
tree213666141efaf773c4411d41482387f1250068f8 /modules
parent3f38ff6c09f0497980ad13fda9803907cee6d612 (diff)
downloadgitea-5c4bc3c848fb4bd46ad5ceeacd82cdfa8f2b5635.tar.gz
gitea-5c4bc3c848fb4bd46ad5ceeacd82cdfa8f2b5635.zip
Huge updates!!!!! Be careful to merge!!!!
Diffstat (limited to 'modules')
-rw-r--r--modules/base/template.go1
-rw-r--r--modules/git/commit.go8
-rw-r--r--modules/git/repo_commit.go57
-rw-r--r--modules/git/repo_tag.go8
-rw-r--r--modules/git/tree_blob.go13
-rw-r--r--modules/git/utils.go21
6 files changed, 107 insertions, 1 deletions
diff --git a/modules/base/template.go b/modules/base/template.go
index 7589fdaafb..b9968bae65 100644
--- a/modules/base/template.go
+++ b/modules/base/template.go
@@ -106,7 +106,6 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{
"CreateCaptcha": func() string { return "" },
}
-// TODO: Legacy
type Actioner interface {
GetOpType() int
GetActUserName() string
diff --git a/modules/git/commit.go b/modules/git/commit.go
index f61f2927b9..52348fefed 100644
--- a/modules/git/commit.go
+++ b/modules/git/commit.go
@@ -73,6 +73,14 @@ func (c *Commit) CommitsCount() (int, error) {
return c.repo.commitsCount(c.Id)
}
+func (c *Commit) SearchCommits(keyword string) (*list.List, error) {
+ return c.repo.searchCommits(c.Id, keyword)
+}
+
+func (c *Commit) CommitsByRange(page int) (*list.List, error) {
+ return c.repo.commitsByRange(c.Id, page)
+}
+
func (c *Commit) GetCommitOfRelPath(relPath string) (*Commit, error) {
return c.repo.getCommitOfRelPath(c.Id, relPath)
}
diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go
index b1ea5a29a5..0e39963e68 100644
--- a/modules/git/repo_commit.go
+++ b/modules/git/repo_commit.go
@@ -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 {
diff --git a/modules/git/repo_tag.go b/modules/git/repo_tag.go
index cefbe783ab..21818f3e6b 100644
--- a/modules/git/repo_tag.go
+++ b/modules/git/repo_tag.go
@@ -30,6 +30,14 @@ func (repo *Repository) GetTags() ([]string, error) {
return tags[:len(tags)-1], nil
}
+func (repo *Repository) CreateTag(tagName, idStr string) error {
+ _, stderr, err := com.ExecCmdDir(repo.Path, "git", "tag", tagName, idStr)
+ if err != nil {
+ return errors.New(stderr)
+ }
+ return nil
+}
+
func (repo *Repository) getTag(id sha1) (*Tag, error) {
if repo.tagCache != nil {
if t, ok := repo.tagCache[id]; ok {
diff --git a/modules/git/tree_blob.go b/modules/git/tree_blob.go
index debc722bc9..f996aba376 100644
--- a/modules/git/tree_blob.go
+++ b/modules/git/tree_blob.go
@@ -44,3 +44,16 @@ func (t *Tree) GetTreeEntryByPath(relpath string) (*TreeEntry, error) {
}
return nil, fmt.Errorf("GetTreeEntryByPath: %v", ErrNotExist)
}
+
+func (t *Tree) GetBlobByPath(rpath string) (*Blob, error) {
+ entry, err := t.GetTreeEntryByPath(rpath)
+ if err != nil {
+ return nil, err
+ }
+
+ if !entry.IsDir() {
+ return entry.Blob(), nil
+ }
+
+ return nil, ErrNotExist
+}
diff --git a/modules/git/utils.go b/modules/git/utils.go
index 3c0c60f235..26eef23191 100644
--- a/modules/git/utils.go
+++ b/modules/git/utils.go
@@ -5,12 +5,33 @@
package git
import (
+ "bytes"
+ "container/list"
"path/filepath"
"strings"
)
const prettyLogFormat = `--pretty=format:%H`
+func parsePrettyFormatLog(repo *Repository, logByts []byte) (*list.List, error) {
+ l := list.New()
+ if len(logByts) == 0 {
+ return l, nil
+ }
+
+ parts := bytes.Split(logByts, []byte{'\n'})
+
+ for _, commitId := range parts {
+ commit, err := repo.GetCommit(string(commitId))
+ if err != nil {
+ return nil, err
+ }
+ l.PushBack(commit)
+ }
+
+ return l, nil
+}
+
func RefEndName(refStr string) string {
index := strings.LastIndex(refStr, "/")
if index != -1 {