From 3a1fa012f7069c5d6b606a3330ec68abdcc125ed Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 13 Mar 2014 14:50:09 +0800 Subject: [PATCH] update repo page --- models/repo.go | 24 +++++++++++++++++------- routers/repo/single.go | 1 - templates/repo/single.tmpl | 2 +- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/models/repo.go b/models/repo.go index 6387090ed00..fa8f7c760db 100644 --- a/models/repo.go +++ b/models/repo.go @@ -268,13 +268,21 @@ const ( ) type RepoFile struct { - Type int - Name string - + Type int + Name string + Message string Created time.Time } -func GetReposFiles(userName, reposName, treeName, rpath string) ([]RepoFile, error) { +func (f *RepoFile) IsFile() bool { + return f.Type == git.FilemodeBlob || f.Type == git.FilemodeBlobExecutable +} + +func (f *RepoFile) IsDir() bool { + return f.Type == git.FilemodeTree +} + +func GetReposFiles(userName, reposName, treeName, rpath string) ([]*RepoFile, error) { f := RepoPath(userName, reposName) repo, err := git.OpenRepository(f) if err != nil { @@ -286,7 +294,7 @@ func GetReposFiles(userName, reposName, treeName, rpath string) ([]RepoFile, err return nil, err } lastCommit := obj.(*git.Commit) - var repofiles []RepoFile + var repofiles []*RepoFile tree, err := lastCommit.Tree() if err != nil { return nil, err @@ -294,10 +302,12 @@ func GetReposFiles(userName, reposName, treeName, rpath string) ([]RepoFile, err var i uint64 = 0 for ; i < tree.EntryCount(); i++ { entry := tree.EntryByIndex(i) - repofiles = append(repofiles, RepoFile{ + + repofiles = append(repofiles, &RepoFile{ entry.Filemode, entry.Name, - time.Now(), + lastCommit.Message(), + lastCommit.Committer().When, }) } diff --git a/routers/repo/single.go b/routers/repo/single.go index 4870adbd0a5..1d5e601aa30 100644 --- a/routers/repo/single.go +++ b/routers/repo/single.go @@ -23,7 +23,6 @@ func Single(params martini.Params, r render.Render, data base.TmplData) { } data["IsRepoToolbarSource"] = true - data["Files"] = files r.HTML(200, "repo/single", data) diff --git a/templates/repo/single.tmpl b/templates/repo/single.tmpl index 96ca95bd8ef..42e09b9a2f7 100644 --- a/templates/repo/single.tmpl +++ b/templates/repo/single.tmpl @@ -6,7 +6,7 @@

Source Files: