tokarchuk/v1.17
Lunny Xiao 11 years ago
parent f2b0dc18b5
commit be8baea7ad
  1. 26
      models/repo2.go

@ -37,28 +37,6 @@ type RepoFile struct {
LastCommit string LastCommit string
} }
func findTree(repo *git.Repository, tree *git.Tree, rpath string) *git.Tree {
if rpath == "" {
return tree
}
paths := strings.Split(rpath, "/")
var g = tree
for _, p := range paths {
s := g.EntryByName(p)
if s == nil {
return nil
}
g, err := repo.LookupTree(s.Id)
if err != nil {
return nil
}
if g == nil {
return nil
}
}
return g
}
func (file *RepoFile) LookupBlob() (*git.Blob, error) { func (file *RepoFile) LookupBlob() (*git.Blob, error) {
if file.Repo == nil { if file.Repo == nil {
return nil, ErrRepoFileNotLoaded return nil, ErrRepoFileNotLoaded
@ -116,7 +94,7 @@ func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile,
if cm.ParentCount() == 0 { if cm.ParentCount() == 0 {
break break
} else if cm.ParentCount() == 1 { } else if cm.ParentCount() == 1 {
pt := findTree(repo, cm.Parent(0).Tree, dirname) pt, _ := repo.SubTree(cm.Parent(0).Tree, dirname)
if pt == nil { if pt == nil {
break break
} }
@ -131,7 +109,7 @@ func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile,
var sameIdcnt = 0 var sameIdcnt = 0
for i := 0; i < cm.ParentCount(); i++ { for i := 0; i < cm.ParentCount(); i++ {
p := cm.Parent(i) p := cm.Parent(i)
pt := findTree(repo, p.Tree, dirname) pt, _ := repo.SubTree(p.Tree, dirname)
var pEntry *git.TreeEntry var pEntry *git.TreeEntry
if pt != nil { if pt != nil {
pEntry = pt.EntryByName(entry.Name) pEntry = pt.EntryByName(entry.Name)

Loading…
Cancel
Save