From 677643b812cdc3bce3b7ef7839239b3059376684 Mon Sep 17 00:00:00 2001 From: slene Date: Fri, 28 Mar 2014 00:07:22 +0800 Subject: fix read commit source --- models/git.go | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'models/git.go') diff --git a/models/git.go b/models/git.go index 8e1bc4e3..6bae7248 100644 --- a/models/git.go +++ b/models/git.go @@ -38,8 +38,8 @@ func (file *RepoFile) LookupBlob() (*git.Blob, error) { } // GetBranches returns all branches of given repository. -func GetBranches(userName, reposName string) ([]string, error) { - repo, err := git.OpenRepository(RepoPath(userName, reposName)) +func GetBranches(userName, repoName string) ([]string, error) { + repo, err := git.OpenRepository(RepoPath(userName, repoName)) if err != nil { return nil, err } @@ -56,8 +56,16 @@ func GetBranches(userName, reposName string) ([]string, error) { return brs, nil } -func GetTargetFile(userName, reposName, branchName, commitId, rpath string) (*RepoFile, error) { - repo, err := git.OpenRepository(RepoPath(userName, reposName)) +func IsBranchExist(userName, repoName, branchName string) bool { + repo, err := git.OpenRepository(RepoPath(userName, repoName)) + if err != nil { + return false + } + return repo.IsBranchExist(branchName) +} + +func GetTargetFile(userName, repoName, branchName, commitId, rpath string) (*RepoFile, error) { + repo, err := git.OpenRepository(RepoPath(userName, repoName)) if err != nil { return nil, err } @@ -102,8 +110,8 @@ func GetTargetFile(userName, reposName, branchName, commitId, rpath string) (*Re } // GetReposFiles returns a list of file object in given directory of repository. -func GetReposFiles(userName, reposName, branchName, commitId, rpath string) ([]*RepoFile, error) { - repo, err := git.OpenRepository(RepoPath(userName, reposName)) +func GetReposFiles(userName, repoName, branchName, commitId, rpath string) ([]*RepoFile, error) { + repo, err := git.OpenRepository(RepoPath(userName, repoName)) if err != nil { return nil, err } @@ -217,13 +225,27 @@ func GetCommit(userName, repoName, branchname, commitid string) (*git.Commit, er return repo.GetCommit(branchname, commitid) } -// GetCommits returns all commits of given branch of repository. -func GetCommits(userName, reposName, branchname string) (*list.List, error) { - repo, err := git.OpenRepository(RepoPath(userName, reposName)) +// GetCommitsByBranch returns all commits of given branch of repository. +func GetCommitsByBranch(userName, repoName, branchName string) (*list.List, error) { + repo, err := git.OpenRepository(RepoPath(userName, repoName)) + if err != nil { + return nil, err + } + r, err := repo.LookupReference(fmt.Sprintf("refs/heads/%s", branchName)) + if err != nil { + return nil, err + } + return r.AllCommits() +} + +// GetCommitsByCommitId returns all commits of given commitId of repository. +func GetCommitsByCommitId(userName, repoName, commitId string) (*list.List, error) { + repo, err := git.OpenRepository(RepoPath(userName, repoName)) if err != nil { return nil, err } - r, err := repo.LookupReference(fmt.Sprintf("refs/heads/%s", branchname)) + fmt.Println(userName, repoName, commitId) + r, err := repo.LookupReference(commitId) if err != nil { return nil, err } -- cgit v1.2.3 From 16cb1e974ca2e34384cd7882886f46f860ea5640 Mon Sep 17 00:00:00 2001 From: slene Date: Fri, 28 Mar 2014 00:13:05 +0800 Subject: print err --- models/git.go | 1 - routers/repo/commit.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'models/git.go') diff --git a/models/git.go b/models/git.go index 6bae7248..e2ee5208 100644 --- a/models/git.go +++ b/models/git.go @@ -244,7 +244,6 @@ func GetCommitsByCommitId(userName, repoName, commitId string) (*list.List, erro if err != nil { return nil, err } - fmt.Println(userName, repoName, commitId) r, err := repo.LookupReference(commitId) if err != nil { return nil, err diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 11aab67c..4a126d23 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -37,7 +37,7 @@ func Commits(ctx *middleware.Context, params martini.Params) { } if err != nil { - ctx.Handle(404, "repo.Commits", nil) + ctx.Handle(404, "repo.Commits", err) return } -- cgit v1.2.3