diff options
author | Unknown <joe2010xtmf@163.com> | 2014-04-11 20:23:34 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-04-11 20:23:34 -0400 |
commit | d6dac160dfcac068b31bda9316ddc3d4919e3288 (patch) | |
tree | 8d32752ea5c045468f2e5b3803cbf686ccc9ab2f /models | |
parent | 47aa53bd369014b0788f18a605e7347801f6c31d (diff) | |
download | gitea-d6dac160dfcac068b31bda9316ddc3d4919e3288.tar.gz gitea-d6dac160dfcac068b31bda9316ddc3d4919e3288.zip |
Pages in commits list page
Diffstat (limited to 'models')
-rw-r--r-- | models/git.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/models/git.go b/models/git.go index af7915482a..f20e663b1b 100644 --- a/models/git.go +++ b/models/git.go @@ -470,3 +470,26 @@ func SearchCommits(repoPath, branch, keyword string) (*list.List, error) { } return parsePrettyFormatLog(stdout) } + +// GetCommitsByRange returns certain number of commits with given page of repository. +func GetCommitsByRange(repoPath, branch string, page int) (*list.List, error) { + stdout, stderr, err := com.ExecCmdDirBytes(repoPath, "git", "log", branch, + "--skip="+base.ToStr((page-1)*50), "--max-count=50", prettyLogFormat) + if err != nil { + return nil, err + } else if len(stderr) > 0 { + return nil, errors.New(string(stderr)) + } + return parsePrettyFormatLog(stdout) +} + +// GetCommitsCount returns the commits count of given branch of repository. +func GetCommitsCount(repoPath, branch string) (int, error) { + stdout, stderr, err := com.ExecCmdDir(repoPath, "git", "rev-list", "--count", branch) + if err != nil { + return 0, err + } else if len(stderr) > 0 { + return 0, errors.New(stderr) + } + return base.StrTo(strings.TrimSpace(stdout)).Int() +} |