]> source.dussan.org Git - gitea.git/commitdiff
add size for file
authorLunny Xiao <xiaolunwen@gmail.com>
Sat, 15 Mar 2014 15:38:11 +0000 (23:38 +0800)
committerLunny Xiao <xiaolunwen@gmail.com>
Sat, 15 Mar 2014 15:38:11 +0000 (23:38 +0800)
models/repo.go
models/repo2.go
templates/repo/single.tmpl

index c52d0a1f24e91698ff01cabe6e2f422724ed0bdf..125abfc3423b6da43334bcef995bc3ed93194fbd 100644 (file)
@@ -261,69 +261,6 @@ func GetRepositoryCount(user *User) (int64, error) {
        return orm.Count(&Repository{OwnerId: user.Id})
 }
 
-/*
-type RepoFile struct {
-       Id      *git.Oid
-       Type    int
-       Name    string
-       Path    string
-       Message string
-       Created time.Time
-}
-
-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, branchName, rpath string) ([]*RepoFile, error) {
-       f := RepoPath(userName, reposName)
-
-       repo, err := git.OpenRepository(f)
-       if err != nil {
-               return nil, err
-       }
-
-       repo.LookupReference("refs/heads/" + branchName)
-
-       obj, err := repo.RevparseSingle("HEAD")
-       if err != nil {
-               return nil, err
-       }
-       lastCommit := obj.(*git.Commit)
-       var repofiles []*RepoFile
-       tree, err := lastCommit.Tree()
-       if err != nil {
-               return nil, err
-       }
-       //var i uint64 = 0
-       if rpath != "" {
-               rpath = rpath + "/"
-       }
-       //fmt.Println("...", rpath, "...")
-
-       tree.Walk(func(dirname string, entry *git.TreeEntry) int {
-               if dirname == rpath {
-                       //fmt.Println("====", dirname, "==", entry.Name)
-                       repofiles = append(repofiles, &RepoFile{
-                               entry.Id,
-                               entry.Filemode,
-                               entry.Name,
-                               path.Join(dirname, entry.Name),
-                               lastCommit.Message(),
-                               lastCommit.Committer().When,
-                       })
-               }
-               return 0
-       })
-
-       return repofiles, nil
-}*/
-
 func StarReposiory(user *User, repoName string) error {
        return nil
 }
index d879130acef0664421eacf364665f74b7786e2cd..e3fdc2784b802c20811beb9c3a7b86de6db859df 100644 (file)
@@ -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,
                                })
                        }
                }
index f71e87f0fb334d36fd4cbfde3953ae473e4ad4c6..b99950ef51f4281b698b2a57242ae4856784e1cf 100644 (file)
@@ -47,7 +47,7 @@
                     {{if .IsDir}}
                     <a href="/{{$username}}/{{$reponame}}/tree/{{$branchname}}/{{.Path}}">{{.Name}}</a>
                     {{else}}
-                    <a href="#">{{.Name}}</a>
+                    <a href="#">{{.Name}} - {{.Size}}</a>
                     {{end}}</td>
                        <td class="date"><time datetime="{{.Created}}" data-title="true" title="{{.Created}}">{{TimeSince .Created}}</time></td>
                        <td class="text">{{.Message}}</td>