Merge branch 'master' of github.com:gogits/gogs

Conflicts:
	models/repo.go
	routers/repo/single.go
	templates/repo/single.tmpl
This commit is contained in:
Unknown 2014-03-18 00:19:15 -04:00
commit d886f4df97
4 changed files with 32 additions and 25 deletions

View file

@ -408,11 +408,9 @@ var (
type RepoFile struct { type RepoFile struct {
*git.TreeEntry *git.TreeEntry
Path string Path string
Message string
Created time.Time
Size int64 Size int64
Repo *git.Repository Repo *git.Repository
LastCommit string Commit *git.Commit
} }
// LookupBlob returns the content of an object. // LookupBlob returns the content of an object.
@ -444,32 +442,28 @@ func GetBranches(userName, reposName string) ([]string, error) {
} }
// GetReposFiles returns a list of file object in given directory of repository. // GetReposFiles returns a list of file object in given directory of repository.
func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, error) { func GetReposFiles(userName, reposName, branchName, commitId, rpath string) ([]*RepoFile, error) {
repo, err := git.OpenRepository(RepoPath(userName, reposName)) repo, err := git.OpenRepository(RepoPath(userName, reposName))
if err != nil { if err != nil {
return nil, err return nil, err
} }
ref, err := repo.LookupReference("refs/heads/" + branchName) commit, err := GetCommit(userName, reposName, branchName, commitId)
if err != nil {
return nil, err
}
lastCommit, err := repo.LookupCommit(ref.Oid)
if err != nil { if err != nil {
return nil, err return nil, err
} }
var repodirs []*RepoFile var repodirs []*RepoFile
var repofiles []*RepoFile var repofiles []*RepoFile
lastCommit.Tree.Walk(func(dirname string, entry *git.TreeEntry) int { commit.Tree.Walk(func(dirname string, entry *git.TreeEntry) int {
if dirname == rpath { if dirname == rpath {
// TODO: size get method shoule be improved
size, err := repo.ObjectSize(entry.Id) size, err := repo.ObjectSize(entry.Id)
if err != nil { if err != nil {
return 0 return 0
} }
var cm = lastCommit var cm = commit
for { for {
if cm.ParentCount() == 0 { if cm.ParentCount() == 0 {
@ -524,11 +518,9 @@ func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile,
rp := &RepoFile{ rp := &RepoFile{
entry, entry,
path.Join(dirname, entry.Name), path.Join(dirname, entry.Name),
cm.Message(),
cm.Committer.When,
size, size,
repo, repo,
cm.Id().String(), cm,
} }
if entry.IsFile() { if entry.IsFile() {
@ -543,12 +535,23 @@ func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile,
return append(repodirs, repofiles...), nil return append(repodirs, repofiles...), nil
} }
// GetLastestCommit returns the latest commit of given repository. func GetCommit(userName, repoName, branchname, commitid string) (*git.Commit, error) {
func GetLastCommit(userName, repoName, branchname string) (*git.Commit, error) {
repo, err := git.OpenRepository(RepoPath(userName, repoName)) repo, err := git.OpenRepository(RepoPath(userName, repoName))
if err != nil { if err != nil {
return nil, err return nil, err
} }
if 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)) r, err := repo.LookupReference(fmt.Sprintf("refs/heads/%s", branchname))
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -69,7 +69,7 @@ func Single(ctx *middleware.Context, params martini.Params) {
// Directory and file list. // Directory and file list.
files, err := models.GetReposFiles(params["username"], params["reponame"], files, err := models.GetReposFiles(params["username"], params["reponame"],
params["branchname"], treename) params["branchname"], params["commitid"], treename)
if err != nil { if err != nil {
log.Error("repo.Single(GetReposFiles): %v", err) log.Error("repo.Single(GetReposFiles): %v", err)
ctx.Render.Error(404) ctx.Render.Error(404)
@ -90,9 +90,10 @@ func Single(ctx *middleware.Context, params martini.Params) {
} }
// Get latest commit according username and repo name // Get latest commit according username and repo name
commit, err := models.GetLastCommit(params["username"], params["reponame"], params["branchname"]) commit, err := models.GetCommit(params["username"], params["reponame"],
params["branchname"], params["commitid"])
if err != nil { if err != nil {
log.Error("repo.Single(GetLastestCommit): %v", err) log.Error("repo.Single(GetCommit): %v", err)
ctx.Render.Error(404) ctx.Render.Error(404)
return return
} }

View file

@ -73,10 +73,10 @@
</span> </span>
</td> </td>
<td class="text"> <td class="text">
<span class="wrap"><a href="/{{$username}}/{{$reponame}}/commit/{{.LastCommit}}">{{.Message}}</a></span> <span class="wrap"><a href="/{{$username}}/{{$reponame}}/commit/{{.Commit.Oid}}">{{.Commit.Message}}</a></span>
</td> </td>
<td class="date"> <td class="date">
<span class="wrap">{{TimeSince .Created}}</span> <span class="wrap">{{TimeSince .Commit.Committer.When}}</span>
</td> </td>
</tr> </tr>
{{end}} {{end}}

3
web.go
View file

@ -82,6 +82,9 @@ func runWeb(*cli.Context) {
middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Single) middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Single)
m.Get("/:username/:reponame/tree/:branchname", m.Get("/:username/:reponame/tree/:branchname",
middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Single) middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Single)
m.Get("/:username/:reponame/commit/:commitid/**", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Single)
m.Get("/:username/:reponame/commit/:commitid", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Single)
m.Get("/:username/:reponame", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Single) m.Get("/:username/:reponame", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Single)
listenAddr := fmt.Sprintf("%s:%s", listenAddr := fmt.Sprintf("%s:%s",