diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2014-03-15 23:38:11 +0800 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2014-03-15 23:38:11 +0800 |
commit | 6bdd6f9b18136a6066f3fc87349037027eb7a499 (patch) | |
tree | 8772e0111fd83abf6abef36796a68166e7a49b38 /models/repo2.go | |
parent | 2acf54b53b9be5cbd014f7af02e543a359e7f8f4 (diff) |
add size for file
Diffstat (limited to 'models/repo2.go')
-rw-r--r-- | models/repo2.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/models/repo2.go b/models/repo2.go index d879130a..e3fdc278 100644 --- a/models/repo2.go +++ b/models/repo2.go @@ -16,6 +16,7 @@ type RepoFile struct { Path string Message string Created time.Time + Size int64 } func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, error) { @@ -40,6 +41,10 @@ func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, var repofiles []*RepoFile lastCommit.Tree.Walk(func(dirname string, entry *git.TreeEntry) int { if dirname == rpath { + size, err := repo.ObjectSize(entry.Id) + if err != nil { + return 0 + } switch entry.Filemode { case git.FileModeBlob, git.FileModeBlobExec: repofiles = append(repofiles, &RepoFile{ @@ -47,6 +52,7 @@ func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, path.Join(dirname, entry.Name), lastCommit.Message(), lastCommit.Committer.When, + size, }) case git.FileModeTree: repodirs = append(repodirs, &RepoFile{ @@ -54,6 +60,7 @@ func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, path.Join(dirname, entry.Name), lastCommit.Message(), lastCommit.Committer.When, + size, }) } } |