bug fixed

This commit is contained in:
Lunny Xiao 2014-03-17 18:56:22 +08:00
parent 015174484a
commit 914ce405af
1 changed files with 94 additions and 21 deletions

View File

@ -6,6 +6,7 @@ package models
import ( import (
"path" "path"
"strings"
"time" "time"
git "github.com/gogits/git" git "github.com/gogits/git"
@ -13,10 +14,33 @@ import (
type RepoFile struct { type RepoFile struct {
*git.TreeEntry *git.TreeEntry
Path string Path string
Message string Message string
Created time.Time Created time.Time
Size int64 Size int64
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 GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, error) { func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, error) {
@ -45,23 +69,72 @@ func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile,
if err != nil { if err != nil {
return 0 return 0
} }
switch entry.Filemode {
case git.FileModeBlob, git.FileModeBlobExec: var cm = lastCommit
repofiles = append(repofiles, &RepoFile{
entry, for {
path.Join(dirname, entry.Name), if cm.ParentCount() == 0 {
lastCommit.Message(), break
lastCommit.Committer.When, } else if cm.ParentCount() == 1 {
size, pt := findTree(repo, cm.Parent(0).Tree, dirname)
}) if pt == nil {
case git.FileModeTree: break
repodirs = append(repodirs, &RepoFile{ }
entry, pEntry := pt.EntryByName(entry.Name)
path.Join(dirname, entry.Name), if pEntry == nil || !pEntry.Id.Equal(entry.Id) {
lastCommit.Message(), break
lastCommit.Committer.When, } else {
size, cm = cm.Parent(0)
}) }
} else {
var emptyCnt = 0
var sameIdcnt = 0
for i := 0; i < cm.ParentCount(); i++ {
p := cm.Parent(i)
pt := findTree(repo, p.Tree, dirname)
var pEntry *git.TreeEntry
if pt != nil {
pEntry = pt.EntryByName(entry.Name)
}
if pEntry == nil {
if emptyCnt == cm.ParentCount()-1 {
goto loop
} else {
emptyCnt = emptyCnt + 1
continue
}
} else {
if !pEntry.Id.Equal(entry.Id) {
goto loop
} else {
if sameIdcnt == cm.ParentCount()-1 {
// TODO: now follow the first parent commit?
cm = cm.Parent(0)
break
}
sameIdcnt = sameIdcnt + 1
}
}
}
}
}
loop:
rp := &RepoFile{
entry,
path.Join(dirname, entry.Name),
cm.Message(),
cm.Committer.When,
size,
cm.Id().String(),
}
if entry.IsFile() {
repofiles = append(repofiles, rp)
} else if entry.IsDir() {
repodirs = append(repodirs, rp)
} }
} }
return 0 return 0