Browse Source

bug fixed

pull/31/head
Lunny Xiao 11 years ago
parent
commit
914ce405af
  1. 115
      models/repo2.go

115
models/repo2.go

@ -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

Loading…
Cancel
Save