]> source.dussan.org Git - gitea.git/commitdiff
show folder first on file list page
authorLunny Xiao <xiaolunwen@gmail.com>
Sat, 15 Mar 2014 14:27:24 +0000 (22:27 +0800)
committerLunny Xiao <xiaolunwen@gmail.com>
Sat, 15 Mar 2014 14:27:24 +0000 (22:27 +0800)
models/repo2.go

index 6aa6eda60caedc1740c70de03b85788a2a1159df..beeb8021ed521cea0009b1ec3f61890e8ce7be8d 100644 (file)
@@ -8,7 +8,7 @@ import (
        "path"
        "time"
 
-       git "github.com/speedata/gogit"
+       git "github.com/gogits/git"
 )
 
 type RepoFile struct {
@@ -46,20 +46,33 @@ func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile,
                return nil, err
        }
 
+       var repodirs []*RepoFile
        var repofiles []*RepoFile
        lastCommit.Tree.Walk(func(dirname string, entry *git.TreeEntry) int {
                if dirname == rpath {
-                       repofiles = append(repofiles, &RepoFile{
-                               entry.Id,
-                               entry.Filemode,
-                               entry.Name,
-                               path.Join(dirname, entry.Name),
-                               lastCommit.Message(),
-                               lastCommit.Committer.When,
-                       })
+                       switch entry.Filemode {
+                       case git.FileModeBlob, git.FileModeBlobExec:
+                               repofiles = append(repofiles, &RepoFile{
+                                       entry.Id,
+                                       entry.Filemode,
+                                       entry.Name,
+                                       path.Join(dirname, entry.Name),
+                                       lastCommit.Message(),
+                                       lastCommit.Committer.When,
+                               })
+                       case git.FileModeTree:
+                               repodirs = append(repodirs, &RepoFile{
+                                       entry.Id,
+                                       entry.Filemode,
+                                       entry.Name,
+                                       path.Join(dirname, entry.Name),
+                                       lastCommit.Message(),
+                                       lastCommit.Committer.When,
+                               })
+                       }
                }
                return 0
        })
 
-       return repofiles, nil
+       return append(repodirs, repofiles...), nil
 }