From 5bc2a1a6f98ae42ab5c30299d26082ffae54b859 Mon Sep 17 00:00:00 2001 From: slene Date: Mon, 17 Mar 2014 18:46:54 +0800 Subject: show readme.md --- models/repo2.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'models/repo2.go') diff --git a/models/repo2.go b/models/repo2.go index 0c17a583..b31244b4 100644 --- a/models/repo2.go +++ b/models/repo2.go @@ -5,6 +5,7 @@ package models import ( + "fmt" "path" "strings" "time" @@ -22,12 +23,25 @@ type Commit struct { Message string } +var ( + ErrRepoFileNotLoaded = fmt.Errorf("repo file not loaded") +) + type RepoFile struct { *git.TreeEntry Path string Message string Created time.Time Size int64 + Repo *git.Repository +} + +func (file *RepoFile) LookupBlob() (*git.Blob, error) { + if file.Repo == nil { + return nil, ErrRepoFileNotLoaded + } + + return file.Repo.LookupBlob(file.Id) } func GetBranches(userName, reposName string) ([]string, error) { @@ -80,6 +94,7 @@ func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, lastCommit.Message(), lastCommit.Committer.When, size, + repo, }) case git.FileModeTree: repodirs = append(repodirs, &RepoFile{ @@ -88,6 +103,7 @@ func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, lastCommit.Message(), lastCommit.Committer.When, size, + repo, }) } } -- cgit v1.2.3