Browse Source

bug fixed

pull/33/head
Lunny Xiao 11 years ago
parent
commit
7076f466c9
  1. 50
      models/repo.go

50
models/repo.go

@ -446,7 +446,7 @@ func GetReposFiles(userName, reposName, branchName, commitId, rpath string) ([]*
return nil, err return nil, err
} }
commit, err := GetCommit(userName, reposName, branchName, commitId) commit, err := repo.GetCommit(branchName, commitId)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -462,8 +462,10 @@ func GetReposFiles(userName, reposName, branchName, commitId, rpath string) ([]*
} }
var cm = commit var cm = commit
var i int
for { for {
i = i + 1
//fmt.Println(".....", i, cm.Id(), cm.ParentCount())
if cm.ParentCount() == 0 { if cm.ParentCount() == 0 {
break break
} else if cm.ParentCount() == 1 { } else if cm.ParentCount() == 1 {
@ -480,7 +482,10 @@ func GetReposFiles(userName, reposName, branchName, commitId, rpath string) ([]*
} else { } else {
var emptyCnt = 0 var emptyCnt = 0
var sameIdcnt = 0 var sameIdcnt = 0
var lastSameCm *git.Commit
//fmt.Println(".....", cm.ParentCount())
for i := 0; i < cm.ParentCount(); i++ { for i := 0; i < cm.ParentCount(); i++ {
//fmt.Println("parent", i, cm.Parent(i).Id())
p := cm.Parent(i) p := cm.Parent(i)
pt, _ := repo.SubTree(p.Tree, dirname) pt, _ := repo.SubTree(p.Tree, dirname)
var pEntry *git.TreeEntry var pEntry *git.TreeEntry
@ -488,23 +493,31 @@ func GetReposFiles(userName, reposName, branchName, commitId, rpath string) ([]*
pEntry = pt.EntryByName(entry.Name) pEntry = pt.EntryByName(entry.Name)
} }
//fmt.Println("pEntry", pEntry)
if pEntry == nil { if pEntry == nil {
if emptyCnt == cm.ParentCount()-1 { emptyCnt = emptyCnt + 1
goto loop if emptyCnt+sameIdcnt == cm.ParentCount() {
} else { if lastSameCm == nil {
emptyCnt = emptyCnt + 1 goto loop
continue } else {
cm = lastSameCm
break
}
} }
} else { } else {
//fmt.Println(i, "pEntry", pEntry.Id, "entry", entry.Id)
if !pEntry.Id.Equal(entry.Id) { if !pEntry.Id.Equal(entry.Id) {
goto loop goto loop
} else { } else {
if sameIdcnt == cm.ParentCount()-1 { lastSameCm = cm.Parent(i)
sameIdcnt = sameIdcnt + 1
if emptyCnt+sameIdcnt == cm.ParentCount() {
// TODO: now follow the first parent commit? // TODO: now follow the first parent commit?
cm = cm.Parent(0) cm = lastSameCm
//fmt.Println("sameId...")
break break
} }
sameIdcnt = sameIdcnt + 1
} }
} }
} }
@ -539,22 +552,7 @@ func GetCommit(userName, repoName, branchname, commitid string) (*git.Commit, er
return nil, err return nil, err
} }
if commitid != "" { return repo.GetCommit(branchname, commitid)
oid, err := git.NewOidFromString(commitid)
if err != nil {
return nil, err
}
return repo.LookupCommit(oid)
}
if branchname == "" {
return nil, errors.New("no branch name and no commit id")
}
r, err := repo.LookupReference(fmt.Sprintf("refs/heads/%s", branchname))
if err != nil {
return nil, err
}
return r.LastCommit()
} }
// GetCommits returns all commits of given branch of repository. // GetCommits returns all commits of given branch of repository.

Loading…
Cancel
Save