diff options
Diffstat (limited to 'models/repo.go')
-rw-r--r-- | models/repo.go | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/models/repo.go b/models/repo.go index b7b5ac42..c5fa899f 100644 --- a/models/repo.go +++ b/models/repo.go @@ -9,6 +9,7 @@ import ( "fmt" "io/ioutil" "os" + "path" "path/filepath" "strings" "time" @@ -267,8 +268,10 @@ const ( ) type RepoFile struct { + Id *git.Oid Type int Name string + Path string Message string Created time.Time } @@ -281,7 +284,7 @@ func (f *RepoFile) IsDir() bool { return f.Type == git.FilemodeTree } -func GetReposFiles(userName, reposName, treeName, rpath string) ([]*RepoFile, error) { +func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, error) { f := RepoPath(userName, reposName) repo, err := git.OpenRepository(f) if err != nil { @@ -298,17 +301,38 @@ func GetReposFiles(userName, reposName, treeName, rpath string) ([]*RepoFile, er if err != nil { return nil, err } - var i uint64 = 0 - for ; i < tree.EntryCount(); i++ { + //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 + }) + + /*for ; i < tree.EntryCount(); i++ { entry := tree.EntryByIndex(i) repofiles = append(repofiles, &RepoFile{ + entry.Id, entry.Filemode, entry.Name, lastCommit.Message(), lastCommit.Committer().When, }) - } + }*/ return repofiles, nil } |