0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-11-19 16:31:41 +01:00
gitea/models/repo2.go

65 lines
1.3 KiB
Go
Raw Normal View History

2014-03-15 10:53:13 +01:00
// Copyright 2014 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package models
import (
"path"
"time"
2014-03-15 15:27:24 +01:00
git "github.com/gogits/git"
)
type RepoFile struct {
2014-03-15 15:43:55 +01:00
*git.TreeEntry
Path string
Message string
Created time.Time
}
func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, error) {
f := RepoPath(userName, reposName)
repo, err := git.OpenRepository(f)
if err != nil {
return nil, err
}
ref, err := repo.LookupReference("refs/heads/" + branchName)
if err != nil {
return nil, err
}
lastCommit, err := repo.LookupCommit(ref.Oid)
if err != nil {
return nil, err
}
2014-03-15 15:27:24 +01:00
var repodirs []*RepoFile
var repofiles []*RepoFile
lastCommit.Tree.Walk(func(dirname string, entry *git.TreeEntry) int {
if dirname == rpath {
2014-03-15 15:27:24 +01:00
switch entry.Filemode {
case git.FileModeBlob, git.FileModeBlobExec:
repofiles = append(repofiles, &RepoFile{
2014-03-15 15:43:55 +01:00
entry,
2014-03-15 15:27:24 +01:00
path.Join(dirname, entry.Name),
lastCommit.Message(),
lastCommit.Committer.When,
})
case git.FileModeTree:
repodirs = append(repodirs, &RepoFile{
2014-03-15 15:43:55 +01:00
entry,
2014-03-15 15:27:24 +01:00
path.Join(dirname, entry.Name),
lastCommit.Message(),
lastCommit.Committer.When,
})
}
}
return 0
})
2014-03-15 15:27:24 +01:00
return append(repodirs, repofiles...), nil
}