refactoring for Repofile

This commit is contained in:
Lunny Xiao 2014-03-15 22:43:55 +08:00
parent ca86433402
commit aa8b38fe35
1 changed files with 3 additions and 17 deletions

View File

@ -12,22 +12,12 @@ import (
) )
type RepoFile struct { type RepoFile struct {
Id *git.Oid *git.TreeEntry
Type int
Name string
Path string Path string
Message string Message string
Created time.Time Created time.Time
} }
func (f *RepoFile) IsFile() bool {
return f.Type == git.FileModeBlob || f.Type == git.FileModeBlobExec
}
func (f *RepoFile) IsDir() bool {
return f.Type == git.FileModeTree
}
func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, error) { func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, error) {
f := RepoPath(userName, reposName) f := RepoPath(userName, reposName)
@ -53,18 +43,14 @@ func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile,
switch entry.Filemode { switch entry.Filemode {
case git.FileModeBlob, git.FileModeBlobExec: case git.FileModeBlob, git.FileModeBlobExec:
repofiles = append(repofiles, &RepoFile{ repofiles = append(repofiles, &RepoFile{
entry.Id, entry,
entry.Filemode,
entry.Name,
path.Join(dirname, entry.Name), path.Join(dirname, entry.Name),
lastCommit.Message(), lastCommit.Message(),
lastCommit.Committer.When, lastCommit.Committer.When,
}) })
case git.FileModeTree: case git.FileModeTree:
repodirs = append(repodirs, &RepoFile{ repodirs = append(repodirs, &RepoFile{
entry.Id, entry,
entry.Filemode,
entry.Name,
path.Join(dirname, entry.Name), path.Join(dirname, entry.Name),
lastCommit.Message(), lastCommit.Message(),
lastCommit.Committer.When, lastCommit.Committer.When,